aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <christopher.baines@digital.cabinet-office.gov.uk>2017-04-24 06:36:04 +0100
committerChristopher Baines <christopher.baines@digital.cabinet-office.gov.uk>2019-02-24 20:34:02 +0000
commit6a32bf95665c8fde42c844ea183394a6dc437808 (patch)
tree88c5434cbb9951909b6497d45efb72a617eab4b1
parenta4dc7e2e22d28d2add96960a223f199dfc2ef8e3 (diff)
downloadgnu-guix-6a32bf95665c8fde42c844ea183394a6dc437808.tar
gnu-guix-6a32bf95665c8fde42c844ea183394a6dc437808.tar.gz
Alter the GitHub updater to use git tags
Just using tags is the most consistent way of getting releases for GOV.UK related software.
-rw-r--r--guix/import/github.scm73
1 files changed, 43 insertions, 30 deletions
diff --git a/guix/import/github.scm b/guix/import/github.scm
index 4d12339204..78f32a4fef 100644
--- a/guix/import/github.scm
+++ b/guix/import/github.scm
@@ -171,10 +171,19 @@ empty list."
"Return a string of the newest released version name given a string URL like
'https://github.com/arq5x/bedtools2/archive/v2.24.0.tar.gz' and the name of
the package e.g. 'bedtools2'. Return #f if there is no releases"
- (define (pre-release? x)
- (hash-ref x "prerelease"))
-
- (let* ((json (fetch-releases-or-tags url)))
+ (let* ((token (%github-token))
+ (releases-api-url (string-append
+ "https://api.github.com/repos/"
+ (github-user-slash-repository url)
+ "/releases"))
+ (tags-api-url (string-append
+ "https://api.github.com/repos/"
+ (github-user-slash-repository url)
+ "/tags"))
+ (json (json-fetch
+ (if token
+ (string-append tags-api-url "?access_token=" token)
+ tags-api-url))))
(if (eq? json #f)
(if (%github-token)
(error "Error downloading release information through the GitHub
@@ -183,32 +192,36 @@ API when using a GitHub token")
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens"))
- (any
- (lambda (release)
- (let ((tag (or (hash-ref release "tag_name") ;a "release"
- (hash-ref release "name"))) ;a tag
- (name-length (string-length package-name)))
- (cond
- ;; some tags include the name of the package e.g. "fdupes-1.51"
- ;; so remove these
- ((and (< name-length (string-length tag))
- (string=? (string-append package-name "-")
- (substring tag 0 (+ name-length 1))))
- (substring tag (+ name-length 1)))
- ;; some tags start with a "v" e.g. "v0.25.0"
- ;; where some are just the version number
- ((string-prefix? "v" tag)
- (substring tag 1))
- ;; Finally, reject tags that don't start with a digit:
- ;; they may not represent a release.
- ((and (not (string-null? tag))
- (char-set-contains? char-set:digit
- (string-ref tag 0)))
- tag)
- (else #f))))
- (match (remove pre-release? json)
- (() json) ; keep everything
- (releases releases))))))
+ (let ((proper-releases
+ (filter
+ (lambda (x)
+ ;; example pre-release:
+ ;; https://github.com/wwood/OrfM/releases/tag/v0.5.1
+ ;; or an all-prerelease set
+ ;; https://github.com/powertab/powertabeditor/releases
+ (and (not (hash-ref x "prerelease"))
+ (string-prefix? "release_"
+ (or (hash-ref x "tag_name")
+ (hash-ref x "name")))))
+ json)))
+ (match proper-releases
+ (() ;empty release list
+ #f)
+
+ ((release . rest) ;one or more releases
+ (let ((tag (or (hash-ref release "tag_name")
+ (hash-ref release "name")))
+ (name-length (string-length package-name)))
+ ;; some tags include the name of the package e.g. "fdupes-1.51"
+ ;; so remove these
+ (if (and (< name-length (string-length tag))
+ (string=? (string-append package-name "-")
+ (substring tag 0 (+ name-length 1))))
+ (substring tag (+ name-length 1))
+ ;; some tags start with a "v" e.g. "v0.25.0"
+ ;; where some are just the version number
+ (if (string-prefix? "v" tag)
+ (substring tag 1) tag)))))))))
(define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG."