summaryrefslogtreecommitdiff
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-01-30 09:02:07 +0000
commit9e6207f37ac1b87a751434c9ba39056983b12522 (patch)
tree3026107d96ab6447f45d6b02ae05eb1cc7e2151d
parent15d78757aa3fc4ca069500fa0e95cb4a718edf2c (diff)
downloadgnu-guix-9e6207f37ac1b87a751434c9ba39056983b12522.tar
gnu-guix-9e6207f37ac1b87a751434c9ba39056983b12522.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."