Text of issues.guix.gnu.org › issue › 35684 as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

import: github: Sort releases before picking the latest one.

Arun 8 years ago Ludovic 8 years ago Arun 8 years ago Ludovic 8 years ago Arun 8 years ago Ludovic 8 years ago Arun 8 years ago import: github: Sort releases before picking the latest one. Done Details 2 participants Arun Isaac Ludovic Courtès Owner unassigned Submitted by Arun Isaac Severity normal Debbugs page Prior to this, for some packages (e.g., osc in (gnu packages build-tools)), `guix refresh' could not find the latest version correctly.

From 33f42ea8a33c6e502062708336a5ab8be871c92b Mon Sep 17 00:00:00 2001 From: Arun Isaac <arunisaac@systemreboot.net> Date: Sat, 11 May 2019 16:40:38 +0530 Subject: [PATCH] import: github: Sort releases before picking the latest one. * guix/import/github.scm (latest-released-version): Sort releases before picking the first one as the latest. --- guix/import/github.scm | 55 ++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) Toggle diff (68 lines) diff --git a/guix/import/github.scm b/guix/import/github.scm index 4d12339204..a8af318bc8 100644 --- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -183,32 +183,35 @@ 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)))))) + (first + (sort + (filter-map + (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))) + version>?))))) (define (latest-release pkg) "Return an <upstream-source> for the latest release of PKG." -- 2.21.0 -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAlzWsKoACgkQLiXui2GA K7NdjwgAqQ/YarcqTl9yArKcCvLRCXq0Ta/Y3ZDRf2qz2mTRs/3bPivIQEG+5oJf BPnlrSA6NQIrku7tM/ryRtNQGag/O8yUEdi496vU7mxa1X6jJlxXYaLOKGat7wp6 ZN6QrjKhx5oUlYUXEtuhRHgLUUlQvTQ95oFhVvP8jf8lC0E3va115Mt3KXMLTm3p easLET250+FnP5P3Q6+L4XtJ0Wwro7Y6UKnpCeUgI9DcZ0FvVYrbMSbx4wTtf1OT 872RXgiB5JCLxXaqUP+G+96U1+sfZWfnu4tX+QYljQ1wNSMUwd9DZ5QlytvHiOQj NtkRv8W24JRwrPVphqCEPcrJ7WkqNg== =vJPD -----END PGP SIGNATURE----- Arun Isaac <arunisaac@systemreboot.net> skribis: Toggle quote (4 lines) > Prior to this, for some packages (e.g., osc in (gnu packages > build-tools)), `guix refresh' could not find the latest version > correctly.

Good catch. Toggle quote (8 lines) > From 33f42ea8a33c6e502062708336a5ab8be871c92b Mon Sep 17 00:00:00 2001 > From: Arun Isaac <arunisaac@systemreboot.net> > Date: Sat, 11 May 2019 16:40:38 +0530 > Subject: [PATCH] import: github: Sort releases before picking the latest one. > > * guix/import/github.scm (latest-released-version): Sort releases before > picking the first one as the latest. [...] Toggle quote (30 lines) > + (first > + (sort > + (filter-map > + (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))) > + version>?))))) LGTM, but… … while you’re at it, would you mind cleaning this up a bit? :-) Namely, I think this big ‘lambda’ could be given a name and moved out of the way to make ‘latest-released-version’ easier to read.

Also, it would probably be reasonable to avoid ‘first’ and instead write: (match (sort …) ((first . _) first) (() (leave (G_ "no releases found etc.~%")))) WDYT? :-) If you’d rather leave that for later, you can also just go ahead and commit your patch. Thanks, Ludo’. Toggle quote (14 lines) > Namely, I think this big ‘lambda’ could be given a name and moved out of > the way to make ‘latest-released-version’ easier to read.

Also, it > would probably be reasonable to avoid ‘first’ and instead write: > > (match (sort …) > ((first . _) first) > (() > (leave (G_ "no releases found etc.~%")))) > > WDYT? :-) > > If you’d rather leave that for later, you can also just go ahead and > commit your patch. No problem! :-) Here is the updated patch. From d3f28de8fedc41732a07edf2ea91222208ccc73f Mon Sep 17 00:00:00 2001 From: Arun Isaac <arunisaac@systemreboot.net> Date: Sat, 11 May 2019 16:40:38 +0530 Subject: [PATCH] import: github: Sort releases before picking the latest one. * guix/import/github.scm (latest-released-version): Sort releases before picking the first one as the latest. --- guix/import/github.scm | 56 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 26 deletions(-) Toggle diff (76 lines) diff --git a/guix/import/github.scm b/guix/import/github.scm index 4d12339204..cdac70420a 100644 --- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -174,6 +174,29 @@ the package e.g. 'bedtools2'.

Return #f if there is no releases" (define (pre-release? x) (hash-ref x "prerelease")) + (define (release->version 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)))) + (let* ((json (fetch-releases-or-tags url))) (if (eq? json #f) (if (%github-token) @@ -183,32 +206,13 @@ API when using a G

The rest of this page is on the live site.