diff options
Diffstat (limited to 'etc')
| -rwxr-xr-x | etc/tag-release | 165 | ||||
| -rw-r--r-- | etc/tag-release.sh | 49 |
2 files changed, 165 insertions, 49 deletions
diff --git a/etc/tag-release b/etc/tag-release new file mode 100755 index 0000000..d5f4a45 --- /dev/null +++ b/etc/tag-release | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | #-*-Scheme-*- | ||
| 3 | |||
| 4 | GUIX="${GUIX:-$(command -v guix)}" | ||
| 5 | |||
| 6 | if [ -z "$GUIX" ]; then | ||
| 7 | echo "Missing guix executable." | ||
| 8 | exit 1 | ||
| 9 | fi | ||
| 10 | |||
| 11 | exec env GUILE_AUTO_COMPILE=0 $GUIX repl -- "$0" "$@" | ||
| 12 | !# | ||
| 13 | |||
| 14 | ;;; SPDX-License-Identifier: LGPL-3.0-or-later | ||
| 15 | ;;; SPDX-FileCopyrightText: 2026 Sergio Pastor Pérez <sergio.pastor-perez@inria.fr> | ||
| 16 | ;;; SPDX-FileCopyrightText: 2026 Romain Garbage <romain.garbage@inria.fr> | ||
| 17 | ;;; | ||
| 18 | ;;; tag-release.scm --- Tag commits for Guix Science releases. | ||
| 19 | ;;; | ||
| 20 | ;;; Commentary: | ||
| 21 | ;;; | ||
| 22 | ;;; This utility aims to ease the tagging of commits intended for making | ||
| 23 | ;;; releases following the Guix Science requirements. | ||
| 24 | ;;; | ||
| 25 | ;;; Code: | ||
| 26 | |||
| 27 | (use-modules (guix channels) | ||
| 28 | (guix describe) | ||
| 29 | (guix diagnostics) | ||
| 30 | (guix i18n) | ||
| 31 | (ice-9 popen) | ||
| 32 | (ice-9 pretty-print) | ||
| 33 | (ice-9 rdelim) | ||
| 34 | (ice-9 regex) | ||
| 35 | (srfi srfi-1) | ||
| 36 | (srfi srfi-37)) | ||
| 37 | |||
| 38 | (define %version "0.0.1") | ||
| 39 | |||
| 40 | (define %this-channel | ||
| 41 | (channel | ||
| 42 | (name 'guix-science) | ||
| 43 | (url "https://codeberg.org/guix-science/guix-science.git") | ||
| 44 | (branch "master") | ||
| 45 | (introduction | ||
| 46 | (make-channel-introduction | ||
| 47 | "b1fe5aaff3ab48e798a4cce02f0212bc91f423dc" | ||
| 48 | (openpgp-fingerprint | ||
| 49 | "CA4F 8CF4 37D7 478F DA05 5FD4 4213 7701 1A37 8446"))))) | ||
| 50 | |||
| 51 | (define help-message | ||
| 52 | "Usage: ~a [OPTIONS]... TAG | ||
| 53 | |||
| 54 | Where TAG has the following format `vYYYYMMDD'. | ||
| 55 | |||
| 56 | OPTIONS: | ||
| 57 | |||
| 58 | --commit=COMMIT the commit where to place the TAG | ||
| 59 | --guix=COMMIT the Guix commit to associate with the release | ||
| 60 | |||
| 61 | Report bugs to: <https://codeberg.org/guix-science/guix-science/issues> | ||
| 62 | ") | ||
| 63 | |||
| 64 | (define %options | ||
| 65 | (let ((display-and-exit-proc | ||
| 66 | (lambda (msg . rest) | ||
| 67 | (lambda _ | ||
| 68 | (apply format (cons* #t msg rest)) (quit))))) | ||
| 69 | (list (option '("commit") #t #f | ||
| 70 | (lambda (opt name arg result) | ||
| 71 | (alist-cons 'commit arg result))) | ||
| 72 | (option '("guix") #t #f | ||
| 73 | (lambda (opt name arg result) | ||
| 74 | (alist-cons 'guix arg result))) | ||
| 75 | (option '(#\v "version") #f #f | ||
| 76 | (display-and-exit-proc "tag-release version v~a\n" %version)) | ||
| 77 | (option '(#\h "help") #f #f | ||
| 78 | (display-and-exit-proc help-message #f))))) | ||
| 79 | |||
| 80 | |||
| 81 | ;;; Helpers | ||
| 82 | |||
| 83 | (define (current-guix-channel) | ||
| 84 | "Retrieve the current Guix channel as seen by `guix describe'." | ||
| 85 | (find (lambda (channel) | ||
| 86 | (equal? (channel-name channel) 'guix)) | ||
| 87 | (current-channels))) | ||
| 88 | |||
| 89 | (define (current-commit) | ||
| 90 | "Return commit as seen by the current working directory." | ||
| 91 | (string-trim-both (run-command "git" "rev-parse" "HEAD"))) | ||
| 92 | |||
| 93 | (define (make-channels-message tag commit guix-commit) | ||
| 94 | "Generate channels file using COMMIT and GUIX-COMMIT." | ||
| 95 | (let* ((this-pinned (channel | ||
| 96 | (inherit %this-channel) | ||
| 97 | (commit commit))) | ||
| 98 | (guix-pinned (channel | ||
| 99 | (inherit (current-guix-channel)) | ||
| 100 | (commit guix-commit))) | ||
| 101 | (pinned-channels (call-with-output-string | ||
| 102 | (lambda (port) | ||
| 103 | (pretty-print | ||
| 104 | `(list ,@(map channel->code (list this-pinned guix-pinned))) | ||
| 105 | port))))) | ||
| 106 | (format #f "\ | ||
| 107 | ;; Guix-Science release ~a | ||
| 108 | ;; | ||
| 109 | ;; Guix revision: ~a | ||
| 110 | ~a" tag guix-commit pinned-channels))) | ||
| 111 | |||
| 112 | (define (check-tag-format tag) | ||
| 113 | "Check that TAG follows the `vYYYYMMDD' pattern." | ||
| 114 | (unless (string-match "^v[0-9]{8}$" tag) | ||
| 115 | (leave (G_ "TAG must follow the `vYYYYMMDD' pattern, got `~a'~%") tag)) | ||
| 116 | tag) | ||
| 117 | |||
| 118 | (define (check-commit-format commit) | ||
| 119 | "Check that COMMIT looks like a valid Git commit hash." | ||
| 120 | (unless (string-match "^[0-9a-fA-F]{40}$" commit) | ||
| 121 | (leave (G_ "COMMIT must be a valid Git commit hash, got `~a'~%") commit)) | ||
| 122 | commit) | ||
| 123 | |||
| 124 | (define (run-command prog . args) | ||
| 125 | "Invoke PROGRAM with the given ARGS." | ||
| 126 | (let* ((port (apply open-pipe* OPEN_READ prog args)) | ||
| 127 | (output (read-string port)) | ||
| 128 | (status (close-pipe port)) | ||
| 129 | (exit-code (status:exit-val status))) | ||
| 130 | (values output exit-code))) | ||
| 131 | |||
| 132 | |||
| 133 | ;;; Main | ||
| 134 | |||
| 135 | (define (main args) | ||
| 136 | (define (parse-args args) | ||
| 137 | (args-fold (cdr args) | ||
| 138 | %options | ||
| 139 | (lambda (opt name arg loads) | ||
| 140 | (error "Unrecognized option `~A'" name)) | ||
| 141 | (lambda (arg result) | ||
| 142 | (when (assoc-ref result 'argument) | ||
| 143 | (error "Only 1 argument for TAG accepted")) | ||
| 144 | (alist-cons 'argument arg result)) | ||
| 145 | '())) | ||
| 146 | (let* ((arguments (parse-args args)) | ||
| 147 | (tag (and=> (or (assoc-ref arguments 'argument) | ||
| 148 | (begin | ||
| 149 | (display help-message) | ||
| 150 | (leave (G_ "missing tag argument~%")))) | ||
| 151 | check-tag-format)) | ||
| 152 | (commit (and=> (or (assoc-ref arguments 'commit) | ||
| 153 | (current-commit)) | ||
| 154 | check-commit-format)) | ||
| 155 | (guix-commit (and=> (or (assoc-ref arguments 'guix) | ||
| 156 | (channel-commit (current-guix-channel))) | ||
| 157 | check-commit-format)) | ||
| 158 | (message (make-channels-message tag commit guix-commit))) | ||
| 159 | (call-with-values | ||
| 160 | (lambda () | ||
| 161 | (run-command "git" "tag" "--annotate" "--sign" "-m" message tag commit)) | ||
| 162 | (lambda (_ exit-code) | ||
| 163 | (exit exit-code))))) | ||
| 164 | |||
| 165 | (main (command-line)) | ||
diff --git a/etc/tag-release.sh b/etc/tag-release.sh deleted file mode 100644 index d9b4a21..0000000 --- a/etc/tag-release.sh +++ /dev/null | |||
| @@ -1,49 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | set -e | ||
| 4 | set -o pipefail | ||
| 5 | |||
| 6 | TAG="$1" | ||
| 7 | GUIX_SCIENCE_COMMIT="$2" | ||
| 8 | GUIX_REVISION="$3" | ||
| 9 | |||
| 10 | usage () { | ||
| 11 | echo "usage: $0 <release-tag> <guix-science-commit> <guix-revision>" | ||
| 12 | echo | ||
| 13 | echo "where <release-tag> is in the format vYYYYMMDD, <guix-science-commit>" | ||
| 14 | echo "is the Guix-Science commit to tag and <guix-revision> is the Guix" | ||
| 15 | echo "revision to associate with the release." | ||
| 16 | } | ||
| 17 | |||
| 18 | # TODO: check arguments. | ||
| 19 | if [ $# -ne 3 ] ; then | ||
| 20 | usage | ||
| 21 | exit 1 | ||
| 22 | fi | ||
| 23 | |||
| 24 | echo ";; Guix-Science release $TAG | ||
| 25 | ;; | ||
| 26 | ;; Guix revision: $GUIX_REVISION | ||
| 27 | (list (channel | ||
| 28 | (name 'guix-science) | ||
| 29 | (url \"https://codeberg.org/guix-science/guix-science.git\") | ||
| 30 | (branch \"master\") | ||
| 31 | (commit | ||
| 32 | \"$GUIX_SCIENCE_COMMIT\") | ||
| 33 | (introduction | ||
| 34 | (make-channel-introduction | ||
| 35 | \"b1fe5aaff3ab48e798a4cce02f0212bc91f423dc\" | ||
| 36 | (openpgp-fingerprint | ||
| 37 | \"CA4F 8CF4 37D7 478F DA05 5FD4 4213 7701 1A37 8446\")))) | ||
| 38 | (channel | ||
| 39 | (name 'guix) | ||
| 40 | (url \"https://git.guix.gnu.org/guix.git\") | ||
| 41 | (branch \"master\") | ||
| 42 | (commit | ||
| 43 | \"$GUIX_REVISION\") | ||
| 44 | (introduction | ||
| 45 | (make-channel-introduction | ||
| 46 | \"9edb3f66fd807b096b48283debdcddccfea34bad\" | ||
| 47 | (openpgp-fingerprint | ||
| 48 | \"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA\"))))) | ||
| 49 | " | git tag --annotate --sign -F - $TAG $GUIX_SCIENCE_COMMIT | ||
