diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2025-11-04 14:22:08 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-11-18 13:05:49 +0100 |
| commit | 1ce270fb85be517c32c0369df6293ca73b26ebac (patch) | |
| tree | 82be943bc300834618df458519d7e114c75335c9 | |
| parent | 830562e5cdb6c244f39c3168b4649c1144099450 (diff) | |
gnu-maintenance: ‘generic-html’ recognizes ‘release-file-regexp’ property.
* guix/gnu-maintenance.scm (package-release-file?): New procedure.
(tarball->version): Add optional parameter and honor it.
(import-html-release): Use ‘package-release-file?’ and pass second argument to
‘tarball->version’.
* tests/gnu-maintenance.scm ("latest-html-release, 'release-file-regexp' property")
("latest-html-release, invalid 'release-file-regexp' property"): New tests.
* doc/guix.texi (Invoking guix refresh): Document it.
Change-Id: Ia9328418fdd2faf118e4ec9d5fbde4a279e100ed
Reviewed-by: Maxim Cournoyer <maxim@guixotic.coop>
| -rw-r--r-- | doc/guix.texi | 30 | ||||
| -rw-r--r-- | guix/gnu-maintenance.scm | 45 | ||||
| -rw-r--r-- | tests/gnu-maintenance.scm | 58 |
3 files changed, 121 insertions, 12 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 8b569c7fbc2..7bba256b838 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -15530,10 +15530,34 @@ the updater for @uref{https://www.stackage.org, Stackage} packages. | |||
| 15530 | the updater for @uref{https://crates.io, Crates} packages. | 15530 | the updater for @uref{https://crates.io, Crates} packages. |
| 15531 | @item launchpad | 15531 | @item launchpad |
| 15532 | the updater for @uref{https://launchpad.net, Launchpad} packages. | 15532 | the updater for @uref{https://launchpad.net, Launchpad} packages. |
| 15533 | |||
| 15533 | @item generic-html | 15534 | @item generic-html |
| 15534 | a generic updater that crawls the HTML page where the source tarball of | 15535 | a generic updater that crawls, by default, the HTML page where the |
| 15535 | the package is hosted, when applicable, or the HTML page specified by | 15536 | source tarball of the package is hosted, when applicable. Behavior can |
| 15536 | the @code{release-monitoring-url} property of the package. | 15537 | be customized with the following package properties: |
| 15538 | |||
| 15539 | @table @code | ||
| 15540 | @item release-monitoring-url | ||
| 15541 | an alternate URL to crawl; | ||
| 15542 | |||
| 15543 | @item release-file-regexp | ||
| 15544 | an regular expression matching release file names, whose first | ||
| 15545 | subexpression must correspond to the version string. | ||
| 15546 | @end table | ||
| 15547 | |||
| 15548 | Here is an example package with a custom release monitoring URL and a | ||
| 15549 | regexp matching an unconventional release file name (it's unconventional | ||
| 15550 | due to the use of upper case letter and the lack of a hyphen before the | ||
| 15551 | version string): | ||
| 15552 | |||
| 15553 | @lisp | ||
| 15554 | (package | ||
| 15555 | ;; @dots{} | ||
| 15556 | (home-page "http://example.org/software/the-package.html") | ||
| 15557 | (properties | ||
| 15558 | `((release-monitoring-url . ,home-page) | ||
| 15559 | (release-file-regexp . "ThePackage([0-9\\.]+)\\.tgz")))) | ||
| 15560 | @end lisp | ||
| 15537 | 15561 | ||
| 15538 | @item generic-git | 15562 | @item generic-git |
| 15539 | a generic updater for packages hosted on Git repositories. It tries to | 15563 | a generic updater for packages hosted on Git repositories. It tries to |
diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm index 08332425083..a33f941cb80 100644 --- a/guix/gnu-maintenance.scm +++ b/guix/gnu-maintenance.scm | |||
| @@ -288,13 +288,41 @@ network to check in GNU's database." | |||
| 288 | (let ((s (tarball-sans-extension file))) | 288 | (let ((s (tarball-sans-extension file))) |
| 289 | (regexp-exec %package-name-rx s)))) | 289 | (regexp-exec %package-name-rx s)))) |
| 290 | 290 | ||
| 291 | (define (tarball->version tarball) | 291 | (define (package-release-file? package file) |
| 292 | "Return true if FILE, a string like \"NPB2.3.tar.gz\", denotes a release | ||
| 293 | file for PACKAGE." | ||
| 294 | (match (assoc-ref (package-properties package) 'release-file-regexp) | ||
| 295 | (#f | ||
| 296 | (release-file? (package-upstream-name package) file)) | ||
| 297 | (str | ||
| 298 | (catch #t | ||
| 299 | (lambda () | ||
| 300 | (string-match str file)) | ||
| 301 | (lambda _ | ||
| 302 | (warning (package-field-location package 'properties) | ||
| 303 | (G_ "~a: invalid 'release-file-regexp' property~%") | ||
| 304 | (package-full-name package)) | ||
| 305 | #f))))) | ||
| 306 | |||
| 307 | (define* (tarball->version tarball #:optional regexp) | ||
| 292 | "Return the version TARBALL corresponds to. TARBALL is a file name like | 308 | "Return the version TARBALL corresponds to. TARBALL is a file name like |
| 293 | \"coreutils-8.23.tar.xz\"." | 309 | \"coreutils-8.23.tar.xz\"." |
| 294 | (let-values (((name version) | 310 | (if regexp |
| 295 | (gnu-package-name->name+version | 311 | (let ((match (string-match regexp tarball))) |
| 296 | (tarball-sans-extension tarball)))) | 312 | (if (= 2 (match:count match)) |
| 297 | version)) | 313 | (match:substring match 1) |
| 314 | (begin | ||
| 315 | (warning (N_ "release file regexp ~s has ~a subexpression\ | ||
| 316 | (expected one for the version string)~%" | ||
| 317 | "release file regexp ~s has ~a subexpressions\ | ||
| 318 | (expected one for the version string)~%" | ||
| 319 | (- (match:count match) 1)) | ||
| 320 | regexp (- (match:count match) 1)) | ||
| 321 | #f))) | ||
| 322 | (let-values (((name version) | ||
| 323 | (gnu-package-name->name+version | ||
| 324 | (tarball-sans-extension tarball)))) | ||
| 325 | version))) | ||
| 298 | 326 | ||
| 299 | (define* (releases project | 327 | (define* (releases project |
| 300 | #:key | 328 | #:key |
| @@ -705,8 +733,11 @@ also updated to the latest version, as explained in the doc of the | |||
| 705 | "Return an <upstream-source> object if a release file was found at URL, | 733 | "Return an <upstream-source> object if a release file was found at URL, |
| 706 | else #f. URL is assumed to fully specified." | 734 | else #f. URL is assumed to fully specified." |
| 707 | (let ((base (basename url))) | 735 | (let ((base (basename url))) |
| 708 | (and (release-file? name base) | 736 | (and (package-release-file? package base) |
| 709 | (let ((version (tarball->version base))) | 737 | (let ((version (tarball->version |
| 738 | base | ||
| 739 | (assoc-ref (package-properties package) | ||
| 740 | 'release-file-regexp)))) | ||
| 710 | (upstream-source | 741 | (upstream-source |
| 711 | (package name) | 742 | (package name) |
| 712 | (version version) | 743 | (version version) |
diff --git a/tests/gnu-maintenance.scm b/tests/gnu-maintenance.scm index 644cd1f2a90..01bcea04aab 100644 --- a/tests/gnu-maintenance.scm +++ b/tests/gnu-maintenance.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2015, 2021 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2015, 2021, 2025 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be> | 3 | ;;; Copyright © 2022 Maxime Devos <maximedevos@telenet.be> |
| 4 | ;;; Copyright © 2023-2024 Maxim Cournoyer <maxim@guixotic.coop> | 4 | ;;; Copyright © 2023-2024 Maxim Cournoyer <maxim@guixotic.coop> |
| 5 | ;;; | 5 | ;;; |
| @@ -27,7 +27,7 @@ | |||
| 27 | #:use-module (srfi srfi-1) | 27 | #:use-module (srfi srfi-1) |
| 28 | #:use-module (srfi srfi-64) | 28 | #:use-module (srfi srfi-64) |
| 29 | #:use-module ((web client) #:select (current-http-proxy)) | 29 | #:use-module ((web client) #:select (current-http-proxy)) |
| 30 | #:use-module ((web uri) #:select (uri? uri->string)) | 30 | #:use-module ((web uri) #:select (uri? uri->string string->uri uri-path)) |
| 31 | #:use-module (ice-9 match)) | 31 | #:use-module (ice-9 match)) |
| 32 | 32 | ||
| 33 | (test-begin "gnu-maintenance") | 33 | (test-begin "gnu-maintenance") |
| @@ -91,6 +91,60 @@ | |||
| 91 | (equal? (upstream-source-version update) "2") | 91 | (equal? (upstream-source-version update) "2") |
| 92 | (equal? (list expected-new-url) (upstream-source-urls update)))))) | 92 | (equal? (list expected-new-url) (upstream-source-urls update)))))) |
| 93 | 93 | ||
| 94 | (test-equal "latest-html-release, 'release-file-regexp' property" | ||
| 95 | '("foo" | ||
| 96 | "1.2.3" | ||
| 97 | ("/dl/FOO1.2.3.tgz")) | ||
| 98 | (with-http-server | ||
| 99 | `((200 "<html xmlns=\"http://www.w3.org/1999/xhtml\"> | ||
| 100 | <head> | ||
| 101 | <title>Releases with unusual file names</title> | ||
| 102 | </head> | ||
| 103 | <body | ||
| 104 | <a href=\"FOO1.2.3.tgz\">version 1.2</a> | ||
| 105 | </body> | ||
| 106 | </html>")) | ||
| 107 | (let () | ||
| 108 | (define package | ||
| 109 | (dummy-package "foo" | ||
| 110 | (source | ||
| 111 | (dummy-origin | ||
| 112 | (uri (string-append (%local-url #:path "/dl") | ||
| 113 | "/FOO1.0.0.tar.gz")))) | ||
| 114 | (properties | ||
| 115 | `((release-monitoring-url . ,(%local-url #:path "/dl/")) | ||
| 116 | (release-file-regexp . "FOO([0-9\\.]+)\\.tgz"))))) | ||
| 117 | (define update | ||
| 118 | ((upstream-updater-import %generic-html-updater) package)) | ||
| 119 | |||
| 120 | (list (upstream-source-package update) | ||
| 121 | (upstream-source-version update) | ||
| 122 | (map (compose uri-path string->uri) | ||
| 123 | (upstream-source-urls update)))))) | ||
| 124 | |||
| 125 | (test-assert "latest-html-release, invalid 'release-file-regexp' property" | ||
| 126 | (with-http-server | ||
| 127 | `((200 "<html xmlns=\"http://www.w3.org/1999/xhtml\"> | ||
| 128 | <head> | ||
| 129 | <title>Releases with unusual file names</title> | ||
| 130 | </head> | ||
| 131 | <body | ||
| 132 | <a href=\"FOO1.2.3.tgz\">version 1.2</a> | ||
| 133 | </body> | ||
| 134 | </html>")) | ||
| 135 | (let () | ||
| 136 | (define package | ||
| 137 | (dummy-package "foo" | ||
| 138 | (source | ||
| 139 | (dummy-origin | ||
| 140 | (uri (string-append (%local-url #:path "/dl") | ||
| 141 | "/FOO1.0.0.tar.gz")))) | ||
| 142 | (properties | ||
| 143 | `((release-monitoring-url . ,(%local-url #:path "/dl/")) | ||
| 144 | (release-file-regexp . "FOO[0-9\\.]+\\.tgz"))))) | ||
| 145 | (not ((upstream-updater-import %generic-html-updater) package))))) | ||
| 146 | |||
| 147 | |||
| 94 | (test-assert "latest-html-release, no signature" | 148 | (test-assert "latest-html-release, no signature" |
| 95 | (with-http-server | 149 | (with-http-server |
| 96 | `((200 "<html xmlns=\"http://www.w3.org/1999/xhtml\"> | 150 | `((200 "<html xmlns=\"http://www.w3.org/1999/xhtml\"> |
