From 650fd4680f8ed3d181faf1664bc9297fc4b415ee Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Tue, 9 Jan 2024 13:46:05 -0700 Subject: [PATCH 1/5] Use number of commits since last release in build number Previously, the number of commits ever was used, to ensure that a build from a later child commit will always be considered a higher version number. Because the version number increases each time the release version increases, counting only the commits since the last release tag is sufficient. --- CHANGELOG.md | 1 + build/functions.sh | 11 ++++++++++- docs/source/api/v3/about.rst | 2 +- docs/source/api/v4/about.rst | 2 +- docs/source/api/v5/about.rst | 2 +- experimental/traffic-portal/server.config.ts | 2 +- infrastructure/cdn-in-a-box/Makefile | 2 +- 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4cb04d569..a6cabe555f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - [#7812](https://github.com/apache/trafficcontrol/pull/7812) *Traffic Portal*: Expose the `configUpdateFailed` and `revalUpdateFailed` fields on the server table. - [#7870](https://github.com/apache/trafficcontrol/pull/7870) *Traffic Portal*: Adds a hyperlink to the DSR page to the DS itself for ease of navigation. +- [#7896](https://github.com/apache/trafficcontrol/pull/7896) *ATC Build system*: Count commits since the last release, not commits ### Changed - [#7614](https://github.com/apache/trafficcontrol/pull/7614) *Traffic Ops* The database upgrade process no longer overwrites changes users may have made to the initially seeded data. diff --git a/build/functions.sh b/build/functions.sh index 97355df8ec..2904cbc53f 100755 --- a/build/functions.sh +++ b/build/functions.sh @@ -93,7 +93,16 @@ getBuildNumber() { local in_git='' if isInGitTree; then local commits sha - commits="$(git rev-list HEAD 2>/dev/null | wc -l | awk '{print $1}')" # awk is for BSD compatibility + # The number of commits since the last tag + if ! commits="$(git describe --tags \ + --match='RELEASE-[0-9].[0-9].[0-9]' \ + --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' \ + --match='v[0-9].[0-9].[0-9]' \ + --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | + awk -F- '{print $(NF-1)}')"; + then + commits=0 + fi sha="$(git rev-parse --short=8 HEAD)" echo "$commits.$sha" else diff --git a/docs/source/api/v3/about.rst b/docs/source/api/v3/about.rst index 259956146c..ff9a7c3c97 100644 --- a/docs/source/api/v3/about.rst +++ b/docs/source/api/v3/about.rst @@ -45,7 +45,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by running ``git rev-list HEAD | wc -l``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/docs/source/api/v4/about.rst b/docs/source/api/v4/about.rst index f0e56831c3..74321ffec9 100644 --- a/docs/source/api/v4/about.rst +++ b/docs/source/api/v4/about.rst @@ -46,7 +46,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by running ``git rev-list HEAD | wc -l``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/docs/source/api/v5/about.rst b/docs/source/api/v5/about.rst index 7841e66921..8411a6707a 100644 --- a/docs/source/api/v5/about.rst +++ b/docs/source/api/v5/about.rst @@ -46,7 +46,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by running ``git rev-list HEAD | wc -l``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/experimental/traffic-portal/server.config.ts b/experimental/traffic-portal/server.config.ts index 83657b7f2a..7df8a30543 100644 --- a/experimental/traffic-portal/server.config.ts +++ b/experimental/traffic-portal/server.config.ts @@ -340,7 +340,7 @@ export async function getVersion(path?: string): Promise { }; try { - ver.commits = String(execSync("git rev-list HEAD", {encoding: "utf8"}).split("\n").length); + ver.commits = String(execSync("git describe --tags --match=RELEASE-[0-9].[0-9].[0-9] --match=RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9] --match=v[0-9].[0-9].[0-9] --match=v[0-9][0-9].[0-9][0-9].[0-9][0-9]", {encoding: "utf8"}).split("-").slice(-2)[0]); ver.hash = execSync("git rev-parse --short=8 HEAD", {encoding: "utf8"}).trimEnd(); } catch (e) { console.warn("getting git parts of version:", e); diff --git a/infrastructure/cdn-in-a-box/Makefile b/infrastructure/cdn-in-a-box/Makefile index 6d9ca65a80..2c29ef25fd 100644 --- a/infrastructure/cdn-in-a-box/Makefile +++ b/infrastructure/cdn-in-a-box/Makefile @@ -40,7 +40,7 @@ TC_DIR := $(CIAB_DIR_RELATIVE)../.. PKG_COMMAND := $(TC_DIR)/pkg PKG_FLAGS := -v -$(RHEL_VERSION) BUILD_SUFFIX := _build -BUILD_NUMBER := $(shell git rev-list HEAD 2>/dev/null | wc -l | tr -d '[[:space:]]').$(shell git rev-parse --short=8 HEAD) +BUILD_NUMBER := $(shell git describe --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) BUILD_ARCH := $(shell docker run --name=ciab-get-$(BASE_IMAGE)-$(RHEL_VERSION)-arch --rm $(BASE_IMAGE):$(RHEL_VERSION) rpm --eval %_arch ) TC_VERSION := $(shell cat "$(TC_DIR)/VERSION") TOMCAT_VERSION := $(shell grep '^\s*TOMCAT_VERSION=' "$(TC_DIR)/traffic_router/build/build_rpm.sh" | cut -d= -f2) From f49cf088060f85075912c357edefd5134b448c28 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 10 Jan 2024 13:43:44 -0700 Subject: [PATCH 2/5] Set pipefail and escape $() in Makefile --- infrastructure/cdn-in-a-box/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/cdn-in-a-box/Makefile b/infrastructure/cdn-in-a-box/Makefile index 2c29ef25fd..ade37fd799 100644 --- a/infrastructure/cdn-in-a-box/Makefile +++ b/infrastructure/cdn-in-a-box/Makefile @@ -40,7 +40,7 @@ TC_DIR := $(CIAB_DIR_RELATIVE)../.. PKG_COMMAND := $(TC_DIR)/pkg PKG_FLAGS := -v -$(RHEL_VERSION) BUILD_SUFFIX := _build -BUILD_NUMBER := $(shell git describe --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) +BUILD_NUMBER := $(shell set -o pipefail; git describe --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $$(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) BUILD_ARCH := $(shell docker run --name=ciab-get-$(BASE_IMAGE)-$(RHEL_VERSION)-arch --rm $(BASE_IMAGE):$(RHEL_VERSION) rpm --eval %_arch ) TC_VERSION := $(shell cat "$(TC_DIR)/VERSION") TOMCAT_VERSION := $(shell grep '^\s*TOMCAT_VERSION=' "$(TC_DIR)/traffic_router/build/build_rpm.sh" | cut -d= -f2) From 36f28ce72e59d643887fc43b99d0034a6f67e4c9 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 10 Jan 2024 13:44:25 -0700 Subject: [PATCH 3/5] Include --long to always get relative commit count --- build/functions.sh | 2 +- docs/source/api/v3/about.rst | 2 +- docs/source/api/v4/about.rst | 2 +- docs/source/api/v5/about.rst | 2 +- experimental/traffic-portal/server.config.ts | 2 +- infrastructure/cdn-in-a-box/Makefile | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/functions.sh b/build/functions.sh index 2904cbc53f..718516d833 100755 --- a/build/functions.sh +++ b/build/functions.sh @@ -94,7 +94,7 @@ getBuildNumber() { if isInGitTree; then local commits sha # The number of commits since the last tag - if ! commits="$(git describe --tags \ + if ! commits="$(git describe --long --tags \ --match='RELEASE-[0-9].[0-9].[0-9]' \ --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' \ --match='v[0-9].[0-9].[0-9]' \ diff --git a/docs/source/api/v3/about.rst b/docs/source/api/v3/about.rst index ff9a7c3c97..39fa050c08 100644 --- a/docs/source/api/v3/about.rst +++ b/docs/source/api/v3/about.rst @@ -45,7 +45,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags --long``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/docs/source/api/v4/about.rst b/docs/source/api/v4/about.rst index 74321ffec9..78b7e38258 100644 --- a/docs/source/api/v4/about.rst +++ b/docs/source/api/v4/about.rst @@ -46,7 +46,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags --long``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/docs/source/api/v5/about.rst b/docs/source/api/v5/about.rst index 8411a6707a..62af25b199 100644 --- a/docs/source/api/v5/about.rst +++ b/docs/source/api/v5/about.rst @@ -46,7 +46,7 @@ No parameters available. Response Structure ------------------ :commitHash: The `Git `_ commit hash that Traffic Ops was built at. -:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags``. +:commits: The number of commits in the branch of the commit that Traffic Ops was built at, including that commit. Calculated by extracting the commit count from running ``git describe --tags --long``. :goVersion: The version of `Go `_ that was used to build Traffic Ops. :release: The major version of CentOS or Red Hat Enterprise Linux that the build environment was running. :name: The human-readable name of the `RPM `_ file. diff --git a/experimental/traffic-portal/server.config.ts b/experimental/traffic-portal/server.config.ts index 7df8a30543..9a172debbf 100644 --- a/experimental/traffic-portal/server.config.ts +++ b/experimental/traffic-portal/server.config.ts @@ -340,7 +340,7 @@ export async function getVersion(path?: string): Promise { }; try { - ver.commits = String(execSync("git describe --tags --match=RELEASE-[0-9].[0-9].[0-9] --match=RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9] --match=v[0-9].[0-9].[0-9] --match=v[0-9][0-9].[0-9][0-9].[0-9][0-9]", {encoding: "utf8"}).split("-").slice(-2)[0]); + ver.commits = String(execSync("git describe --long --tags --match=RELEASE-[0-9].[0-9].[0-9] --match=RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9] --match=v[0-9].[0-9].[0-9] --match=v[0-9][0-9].[0-9][0-9].[0-9][0-9]", {encoding: "utf8"}).split("-").slice(-2)[0]); ver.hash = execSync("git rev-parse --short=8 HEAD", {encoding: "utf8"}).trimEnd(); } catch (e) { console.warn("getting git parts of version:", e); diff --git a/infrastructure/cdn-in-a-box/Makefile b/infrastructure/cdn-in-a-box/Makefile index ade37fd799..35b1512e47 100644 --- a/infrastructure/cdn-in-a-box/Makefile +++ b/infrastructure/cdn-in-a-box/Makefile @@ -40,7 +40,7 @@ TC_DIR := $(CIAB_DIR_RELATIVE)../.. PKG_COMMAND := $(TC_DIR)/pkg PKG_FLAGS := -v -$(RHEL_VERSION) BUILD_SUFFIX := _build -BUILD_NUMBER := $(shell set -o pipefail; git describe --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $$(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) +BUILD_NUMBER := $(shell set -o pipefail; git describe --long --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $$(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) BUILD_ARCH := $(shell docker run --name=ciab-get-$(BASE_IMAGE)-$(RHEL_VERSION)-arch --rm $(BASE_IMAGE):$(RHEL_VERSION) rpm --eval %_arch ) TC_VERSION := $(shell cat "$(TC_DIR)/VERSION") TOMCAT_VERSION := $(shell grep '^\s*TOMCAT_VERSION=' "$(TC_DIR)/traffic_router/build/build_rpm.sh" | cut -d= -f2) From 2262faf933fb712f65143ba626009b064d77fde4 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 10 Jan 2024 14:50:45 -0700 Subject: [PATCH 4/5] Use pipefail shell option within bash --- infrastructure/cdn-in-a-box/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/cdn-in-a-box/Makefile b/infrastructure/cdn-in-a-box/Makefile index 35b1512e47..f0890f989c 100644 --- a/infrastructure/cdn-in-a-box/Makefile +++ b/infrastructure/cdn-in-a-box/Makefile @@ -40,7 +40,7 @@ TC_DIR := $(CIAB_DIR_RELATIVE)../.. PKG_COMMAND := $(TC_DIR)/pkg PKG_FLAGS := -v -$(RHEL_VERSION) BUILD_SUFFIX := _build -BUILD_NUMBER := $(shell set -o pipefail; git describe --long --tags --match='RELEASE-[0-9].[0-9].[0-9]' --match='RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]' --match='v[0-9].[0-9].[0-9]' --match='v[0-9][0-9].[0-9][0-9].[0-9][0-9]' | awk -F- '{print $$(NF-1)}' || echo 0).$(shell git rev-parse --short=8 HEAD) +BUILD_NUMBER := $(shell bash -c 'set -o pipefail -o xtrace; git describe --long --tags --match="RELEASE-[0-9].[0-9].[0-9]" --match="RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9]" --match="v[0-9].[0-9].[0-9]" --match="v[0-9][0-9].[0-9][0-9].[0-9][0-9]" | awk -F- "{print \$$(NF-1)}"' || echo 0).$(shell git rev-parse --short=8 HEAD) BUILD_ARCH := $(shell docker run --name=ciab-get-$(BASE_IMAGE)-$(RHEL_VERSION)-arch --rm $(BASE_IMAGE):$(RHEL_VERSION) rpm --eval %_arch ) TC_VERSION := $(shell cat "$(TC_DIR)/VERSION") TOMCAT_VERSION := $(shell grep '^\s*TOMCAT_VERSION=' "$(TC_DIR)/traffic_router/build/build_rpm.sh" | cut -d= -f2) From 14122bb9139c03f5a02636ee50b6bade35df9f55 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Wed, 10 Jan 2024 15:14:40 -0700 Subject: [PATCH 5/5] Fall back to commit count of 0 in TPv2 --- experimental/traffic-portal/server.config.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/experimental/traffic-portal/server.config.ts b/experimental/traffic-portal/server.config.ts index 9a172debbf..26485be520 100644 --- a/experimental/traffic-portal/server.config.ts +++ b/experimental/traffic-portal/server.config.ts @@ -340,9 +340,12 @@ export async function getVersion(path?: string): Promise { }; try { - ver.commits = String(execSync("git describe --long --tags --match=RELEASE-[0-9].[0-9].[0-9] --match=RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9] --match=v[0-9].[0-9].[0-9] --match=v[0-9][0-9].[0-9][0-9].[0-9][0-9]", {encoding: "utf8"}).split("-").slice(-2)[0]); ver.hash = execSync("git rev-parse --short=8 HEAD", {encoding: "utf8"}).trimEnd(); + ver.commits = String(execSync("git describe --long --tags " + + "--match=RELEASE-[0-9].[0-9].[0-9] --match=RELEASE-[0-9][0-9].[0-9][0-9].[0-9][0-9] " + + "--match=v[0-9].[0-9].[0-9] --match=v[0-9][0-9].[0-9][0-9].[0-9][0-9]", {encoding: "utf8"}).split("-").slice(-2)[0]); } catch (e) { + ver.commits = "0"; console.warn("getting git parts of version:", e); }