From patchwork Tue Jan 19 22:20:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Spooren X-Patchwork-Id: 1428905 X-Patchwork-Delegate: mail@aparcar.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=e0I8Xlzt; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DL39d2rBLz9sW8 for ; Wed, 20 Jan 2021 09:24:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=z1AO/aU9wg3FFd/xwqnlDbyceVOczPOhWkIaL9ycUxM=; b=e0I8Xlzteul8TjEp99Q6m+DZsd /HVJ09Wu6JdsZFSliIatnjEuNWE/vj/Uxax3qXEzW8Cba3C6rX83gbK3BpAOXVyITG8o7Yh75qguq TArKkNqyQ7I6gWKPOYgryzkURebi5TLAfTqc3pKqixYp0p+t0xCwKF3FvDU7utlRypMMukLD3mavU dpwZz7iHa/K5qbuz6IJ0+Muph4e6ktNeCbgnaqLh4EkvSxmLIdgZXNj4SmxxFGCvYGKh6zgjT2Vb7 omQZPk38r5WDvrOMst9HWtUANiUQhffbYD8eNraJtfnrVXdlqWBCxc5vcWlE3OvJG8gR/VCy8zdxN 12nORmsg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1zOG-0000tI-Fh; Tue, 19 Jan 2021 22:22:20 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l1zOD-0000sq-WE for openwrt-devel@lists.openwrt.org; Tue, 19 Jan 2021 22:22:19 +0000 X-Originating-IP: 72.235.129.18 Received: from dawn.lan (udp100268uds.hawaiiantel.net [72.235.129.18]) (Authenticated sender: mail@aparcar.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPA id AB60220005; Tue, 19 Jan 2021 22:22:13 +0000 (UTC) From: Paul Spooren To: openwrt-devel@lists.openwrt.org Subject: [PATCH v2 1/4] rules: add AUTORELEASE and COMMITCOUNT variables Date: Tue, 19 Jan 2021 12:20:32 -1000 Message-Id: <20210119222034.4018694-1-mail@aparcar.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210119_172218_150765_26416C34 X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.200 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [217.70.183.200 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ~aparcar/openwrt-devel-test@lists.sr.ht, Paul Spooren , Daniel Golle , freifunk@adrianschmutzler.de Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The lack of bumped PKG_RELEASE variables is a recurring theme on the mailing list and in GitHub comments. This costs precious review time, a rare good within the OpenWrt project. Instead of relying on a manually set PKG_RELEASE this commit adds a `commitcount` function that uses the number of Git commits to determine the release. The function is called via the variables `$(AUTORELEASE)` or `$(COMMITCOUNT)`. The `PKG_RELEASE` variable can be set to either of the two. - $(AUTORELEASE): Release is automagically set to the number of commits since the last commit containing either ": update to " or ": bump to ". Example below: $ git log packages/foobar/ foobar: fixup file location foobar: disable docs foobar: bump to 5.3.2 foobar: fixup copyright Resulting package name: foobar_5.3.2-3_all.ipk, two package changes since the last upstream version change, using a 1 based counter. - $(COMMITCOUNT): For non-traditional versioning (x.y.z), most prominent `base-files`, it is possible to pass an argument to get the total number of commits. The new functionality can also be used by other feeds like packages.git. Suggested-by: Daniel Golle Signed-off-by: Paul Spooren --- v2: The initial version would use `git log --grep` which also scans through the commit message, not only the commit subject. That can cause problems in cases where other commit are referenced in commit messages and overall slows the down the execution. Instead pipe output to grep. rules.mk | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rules.mk b/rules.mk index f79340b124..6d3c98b8f6 100644 --- a/rules.mk +++ b/rules.mk @@ -408,6 +408,32 @@ endef # file extension ext=$(word $(words $(subst ., ,$(1))),$(subst ., ,$(1))) +# Count Git commits of a package +# $(1) => if non-empty count commits since "update" or "bump" to determine package release +define commitcount +$(shell \ + if git log -1 >/dev/null 2>/dev/null; then \ + if [ -n "$(1)" ]; then \ + last_bump="$$(git log --pretty=format:'%h %s' . | \ + grep --max-count=1 -e ': [uU]pdate to ' -e ': [bB]ump to ' | \ + cut -f 1 -d ' ')"; \ + fi; \ + if [ -n "$$last_bump" ]; then \ + echo -n $$(($$(git rev-list --count "$$last_bump..HEAD" .) + 1)); \ + else \ + echo -n $$(($$(git rev-list --count HEAD .) + 1)); \ + fi; \ + else \ + secs="$$(($(SOURCE_DATE_EPOCH) % 86400))"; \ + date="$$(date --utc --date="@$(SOURCE_DATE_EPOCH)" "+%y%m%d")"; \ + printf '%s.%05d' "$$date" "$$secs"; \ + fi; \ +) +endef + +COMMITCOUNT = $(if $(DUMP),,$(call commitcount)) +AUTORELEASE = $(if $(DUMP),,$(call commitcount,1)) + all: FORCE: ; .PHONY: FORCE