From patchwork Fri Apr 9 09:05:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 28421 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6D2AE27BC6F; Fri, 9 Apr 2021 10:06:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7166827BC6E for ; Fri, 9 Apr 2021 10:06:28 +0100 (BST) Received: from localhost ([::1]:41840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUn5v-0001ix-H9 for patchwork@mira.cbaines.net; Fri, 09 Apr 2021 05:06:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUn5X-0001hu-3d for guix-patches@gnu.org; Fri, 09 Apr 2021 05:06:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lUn5W-0000DW-RC for guix-patches@gnu.org; Fri, 09 Apr 2021 05:06:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lUn5W-0003oT-Mg for guix-patches@gnu.org; Fri, 09 Apr 2021 05:06:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47670] [PATCH 2/2] gnu-maintenance: Add 'sourcehut-git' updater. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 09 Apr 2021 09:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47670 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47670@debbugs.gnu.org Cc: =?utf-8?q?L=C3=A9o?= Le Bouter Received: via spool by 47670-submit@debbugs.gnu.org id=B47670.161795912314595 (code B ref 47670); Fri, 09 Apr 2021 09:06:02 +0000 Received: (at 47670) by debbugs.gnu.org; 9 Apr 2021 09:05:23 +0000 Received: from localhost ([127.0.0.1]:49073 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lUn4n-0003nE-Ri for submit@debbugs.gnu.org; Fri, 09 Apr 2021 05:05:23 -0400 Received: from h87-96-130-155.cust.a3fiber.se ([87.96.130.155]:37390 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lUn4j-0003mg-US for 47670@debbugs.gnu.org; Fri, 09 Apr 2021 05:05:15 -0400 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yoctocell.xyz; s=mail; t=1617959106; bh=80RNeqJRCHquwTRjJk8gsxkPXLIe0+kVd9iWWStc+mU=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=Czsx5qgUHxUq33PPh6gjIQBJjMfQU/fGRgc5dKXQioIrWqKNrcxOJW+KQcII2PHtD 5aA54qUo5lyNCiof77DMoH2HM47WWj5qVFsQq9qBWwzXm7WjX1ZTnPtMdQqWCS0d/L duUaerTcSjXN3Pv6YQ/ehuUJQFxhypwARXNPWLNQ= In-Reply-To: References: Message-Id: <8ea188fa0521e9ea5f07dcc9973e1fa916dc4494.1617958554.git.public@yoctocell.xyz> Date: Fri, 09 Apr 2021 11:05:05 +0200 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/gnu-maintenance.scm (latest-git-tag-version, sourcehut-git-package?, latest-sourcehut-git-release): New procedures. (%sourcehut-git-updater): New variable. * doc/guix.texi (Invoking guix refresh): Document it. --- doc/guix.texi | 3 ++ guix/gnu-maintenance.scm | 90 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index d1a15cb28b..6b6e3401f0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -11745,6 +11745,9 @@ the updater for @uref{https://www.stackage.org, Stackage} packages. the updater for @uref{https://crates.io, Crates} packages. @item launchpad the updater for @uref{https://launchpad.net, Launchpad} packages. +@item sourcehut-git +the updater for packages hosted as @uref{https://sourcehut.org, +SourceHut} Git repositories. @item generic-html a generic updater that crawls the HTML page where the source tarball of the package is hosted, when applicable. diff --git a/guix/gnu-maintenance.scm b/guix/gnu-maintenance.scm index fece84b341..6a2a4ccf34 100644 --- a/guix/gnu-maintenance.scm +++ b/guix/gnu-maintenance.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2012, 2013 Nikita Karetnikov ;;; Copyright © 2021 Simon Tournier +;;; Copyright © 2021 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,6 +26,9 @@ #:use-module (sxml simple) #:use-module (ice-9 regex) #:use-module (ice-9 match) + #:use-module (ice-9 popen) + #:use-module (ice-9 rdelim) + #:use-module (ice-9 receive) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) @@ -38,6 +42,7 @@ #:use-module (guix records) #:use-module (guix upstream) #:use-module (guix packages) + #:use-module (guix git-download) #:autoload (zlib) (call-with-gzip-input-port) #:autoload (htmlprag) (html->sxml) ;from Guile-Lib #:export (gnu-package-name @@ -69,6 +74,7 @@ %sourceforge-updater %xorg-updater %kernel.org-updater + %sourcehut-git-updater %generic-html-updater)) ;;; Commentary: @@ -802,6 +808,83 @@ the directory containing its source tarball." (apply throw key args)) #f)))) +(define (latest-git-tag-version package) + "Return the latest version of PACKAGE based on Git tags. This relies on the +Git tag having the version of the package in the name." + (let* ((url (git-reference-url (origin-uri (package-source package)))) + (port (open-pipe* OPEN_READ + "git" + "ls-remote" + "--tags" + url))) + + (define read-tags + (let loop ((lines '())) + (let ((line (read-line port))) + (cond + ((eof-object? line) lines) + ;; The hash on the lines without "^{}" dont't correspond to a + ;; commit. + ;; + ;; 0545ff5df25ea019fcb6fc1dcb40da06b35320e9 refs/tags/0.8.1 + ;; 13042ec03837b72f8d14c04e9abe3ddae88449fa refs/tags/0.8.1^{} + ((not (string-suffix? "^{}" line)) (loop lines)) + ;; Drop the "^{}" + (else (loop (cons (string-drop-right line 3) lines))))))) + + (close-pipe port) + + (define (tag->version tag) + (if (string-prefix? "v"tag) + (substring tag 1) + tag)) + + (define (valid-version? tag) + (if (string-match "^[0-9._-]*$" (tag->version tag)) #t #f)) + + ;; Some projects will publish release candidates which we usually don't + ;; want to package. + (if (not (null? read-tags)) + (receive (valid invalid) + (partition valid-version? + (map (lambda (line) + (last (string-split line #\/))) + read-tags)) + (tag->version (first valid))) + (package-version package)))) + +;; Not guaranteed to always work correctly since you can self-host it. +(define sourcehut-git-package? + (let ((hosting-site "git.sr.ht")) + (git-url-predicate (lambda (url) + (match (string->uri url) + (#f #f) + (uri + (let ((scheme (uri-scheme uri)) + (host (uri-host uri))) + (and (memq scheme '(http https)) + (if (string-match hosting-site host) + #t #f))))))))) + +(define (latest-sourcehut-git-release package) + "Return the latest release of PACKAGE." + (let ((name (package-name package)) + (old-version (package-version package)) + (new-version (latest-git-tag-version package)) + (url (git-reference-url (origin-uri (package-source package))))) + (define (ensure-trailing-slash str) + (if (string-suffix? "/" str) str (string-append str "/"))) + + (if (not (string= old-version new-version)) + (upstream-source + (package name) + (version new-version) + (urls (list (string-append (ensure-trailing-slash url) + "archive/" + new-version + ".tar.gz")))) + #f))) ; no tags + (define %gnu-updater ;; This is for everything at ftp.gnu.org. (upstream-updater @@ -849,6 +932,13 @@ the directory containing its source tarball." (pred (url-prefix-predicate "mirror://kernel.org/")) (latest latest-kernel.org-release))) +(define %sourcehut-git-updater + (upstream-updater + (name 'sourcehut-git) + (description "Updater for packages hosted as SourceHut Git repositories") + (pred sourcehut-git-package?) + (latest latest-sourcehut-git-release))) + (define %generic-html-updater (upstream-updater (name 'generic-html)