treewide: fix nostamp
Previously, --nostamp did not disable all stamping with commit info,
which meant that metropolis e2e tests ran on CI even if no change was
made to metropolis code. Now, --config:nostamp does this properly.
The Bazel --nostamp flag is supposed to disable stamping. Ideally, this
means that the workspace status script is not executed. But we can't do
that because the metropolis version is required (e.g. for compatibility
checks), and we currently obtain the version from git tags. Another
option is to check whether the --nostamp flag is set in the status
script, and omit any git commit info in this case. But I didn't find a
way to access the --nostamp flag from the status script, so instead, the
--config:nostamp flag is introduced and replaces --nostamp.
Versions without git info are marked with a "-nostamp" suffix.
I adjusted //version to handle this case.
Change-Id: I34e1b59b908074e8d4234013358b6be41899570a
Reviewed-on: https://review.monogon.dev/c/monogon/+/4169
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/version/stampgo/main.go b/version/stampgo/main.go
index 7aaa91d..3f8502c 100644
--- a/version/stampgo/main.go
+++ b/version/stampgo/main.go
@@ -30,7 +30,6 @@
var (
rePrereleaseCommitOffset = regexp.MustCompile(`^dev([0-9]+)$`)
- rePrereleaseDirty = regexp.MustCompile(`^dirty$`)
rePrereleaseGitHash = regexp.MustCompile(`^g[0-9a-f]+$`)
)
@@ -83,28 +82,26 @@
log.Fatalf("Failed to read workspace status file: %v", err)
}
- commitHash := values["STABLE_MONOGON_gitCommit"]
- if commitHash == "" {
- log.Fatalf("No git commit in workspace status")
- }
- if len(commitHash) < 8 {
- log.Fatalf("Git commit hash too short")
- }
- buildTreeState := spec.Version_GitInformation_BUILD_TREE_STATE_INVALID
- switch values["STABLE_MONOGON_gitTreeState"] {
- case "clean":
- buildTreeState = spec.Version_GitInformation_BUILD_TREE_STATE_CLEAN
- case "dirty":
- buildTreeState = spec.Version_GitInformation_BUILD_TREE_STATE_DIRTY
- default:
- log.Fatalf("Invalid git tree state %q", values["STABLE_MONOGON_gitTreeState"])
- }
+ version := &spec.Version{}
- version := &spec.Version{
- GitInformation: &spec.Version_GitInformation{
+ commitHash := values["STABLE_MONOGON_gitCommit"]
+ if commitHash != "" {
+ if len(commitHash) < 8 {
+ log.Fatalf("Git commit hash too short")
+ }
+ buildTreeState := spec.Version_GitInformation_BUILD_TREE_STATE_INVALID
+ switch values["STABLE_MONOGON_gitTreeState"] {
+ case "clean":
+ buildTreeState = spec.Version_GitInformation_BUILD_TREE_STATE_CLEAN
+ case "dirty":
+ buildTreeState = spec.Version_GitInformation_BUILD_TREE_STATE_DIRTY
+ default:
+ log.Fatalf("Invalid git tree state %q", values["STABLE_MONOGON_gitTreeState"])
+ }
+ version.GitInformation = &spec.Version_GitInformation{
CommitHash: commitHash[:8],
BuildTreeState: buildTreeState,
- },
+ }
}
productVersion := values["STABLE_MONOGON_"+flagProduct+"_version"]
@@ -119,22 +116,24 @@
}
// Parse prerelease strings (v1.2.3-foo-bar -> [foo, bar])
for _, el := range v.PreRelease.Slice() {
- // Skip empty slices which happens when there's a semver string with no
- // prerelease data.
- if el == "" {
- continue
- }
preCommitOffset := rePrereleaseCommitOffset.FindStringSubmatch(el)
- preDirty := rePrereleaseDirty.FindStringSubmatch(el)
preGitHash := rePrereleaseGitHash.FindStringSubmatch(el)
switch {
+ case el == "":
+ // Skip empty slices which happens when there's a semver string with no
+ // prerelease data.
+ case el == "nostamp":
+ // Ignore field, we have it from the global monorepo state.
case preCommitOffset != nil:
offset, err := strconv.ParseUint(preCommitOffset[1], 10, 64)
if err != nil {
log.Fatalf("Invalid commit offset value: %v", err)
}
+ if version.GitInformation == nil {
+ log.Fatalf("Have git offset but no git commit")
+ }
version.GitInformation.CommitsSinceRelease = offset
- case preDirty != nil:
+ case el == "dirty":
// Ignore field, we have it from the global monorepo state.
case preGitHash != nil:
// Ignore field, we have it from the global monorepo state.
diff --git a/version/version.go b/version/version.go
index 999854e..2929684 100644
--- a/version/version.go
+++ b/version/version.go
@@ -33,6 +33,8 @@
if git.BuildTreeState != spec.Version_GitInformation_BUILD_TREE_STATE_CLEAN {
prerelease = append(prerelease, "dirty")
}
+ } else {
+ prerelease = append(prerelease, "nostamp")
}
if len(prerelease) > 0 {