Skip to content

Commit ee4dd2a

Browse files
committed
Fix: Set conformance commit in GitHub Action
It is not possible to inject the commit hash into the main package (though it works with "go test"). Instead, this exposes the default value from yaml and the env, but overrides it from git when possible. This fixes the reports in the GitHub Actions that run without the .git directory. Signed-off-by: Brandon Mitchell <git@bmitch.net>
1 parent 2292ca1 commit ee4dd2a

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,12 @@ clean-ci:
139139

140140
$(OUTPUT_DIRNAME)/conformance: conformance/*.go conformance/go.mod
141141
cd conformance && \
142-
CGO_ENABLED=0 go build -o $(shell pwd)/$(OUTPUT_DIRNAME)/conformance \
143-
--ldflags="-X github.com/opencontainers/distribution-spec/conformance.Version=$(CONFORMANCE_VERSION)"
142+
CGO_ENABLED=0 go build -o $(shell pwd)/$(OUTPUT_DIRNAME)/conformance .
144143

145144
$(OUTPUT_DIRNAME)/conformance.test: conformance/*.go conformance/go.mod
146145
cd conformance && \
147146
CGO_ENABLED=0 go test -c -o $(shell pwd)/$(OUTPUT_DIRNAME)/conformance.test \
148-
--ldflags="-X github.com/opencontainers/distribution-spec/conformance.Version=$(CONFORMANCE_VERSION)"
147+
-ldflags "-X github.com/opencontainers/distribution-spec/conformance.Version=$(CONFORMANCE_VERSION)" .
149148

150149
clean: clean-ci
151150
rm -rf header.html junit.xml report.html results.yaml output conformance/results

action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ runs:
5454
run: |
5555
set -x
5656
57-
# Enter the directory containing the checkout of this action which is surpisingly hard to do (but we did it... #OCI)
57+
# Enter the directory containing the checkout of this action which is surprisingly hard to do (but we did it... #OCI)
5858
cd "$(dirname $(find $(find ~/work/_actions -name distribution-spec -print -quit) -name Makefile -print -quit))"
5959
6060
# The .git folder is not present, but the dirname is the requested action ref, so use this as the commit version
@@ -65,6 +65,7 @@ runs:
6565
6666
# The spec version is independent of the conformance git commit
6767
echo "oci-spec-version=${OCI_VERSION:-stable}" >> $GITHUB_OUTPUT
68+
echo "oci-commit=${commit_version}" >> $GITHUB_OUTPUT
6869
6970
# Add bin to the PATH so we can just run "conformance"
7071
echo "${PWD}/bin" >> $GITHUB_PATH
@@ -75,7 +76,8 @@ runs:
7576
run: |
7677
set -x
7778
set +e
78-
export OCI_RESULTS_DIR=${OCI_RESULTS_DIR:-.}
79+
export OCI_RESULTS_DIR="${OCI_RESULTS_DIR:-.}"
80+
export OCI_COMMIT="${{ steps.build-conformance.outputs.oci-commit }}"
7981
conformance
8082
conformance_rc="$?"
8183
set -e

conformance/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export OCI_CONFIGURATION="oci-conformance.yaml" # see Yaml Configuration File be
2121
export OCI_RESULTS_DIR="./results" # output of the conformance test will be written here, see Results below
2222
export OCI_VERSION="1.1" # distribution-spec version to test against, this adjusts default values for the API tests, also accepts "stable" and "dev"
2323
export OCI_LOG="warn" # adjust logging threshold: debug, info, warn, error (this does not affect the generated reports)
24+
export OCI_COMMIT="unknown" # commit hash of the distribution-spec, this is auto detected from git when available
2425

2526
# the registry settings typically need to be configured
2627
export OCI_REGISTRY="localhost:5000"
@@ -95,6 +96,7 @@ password: ""
9596
cacheAuth: true
9697
logging: warn
9798
filterTest: ""
99+
commit: "unknown"
98100
apis:
99101
pull: true
100102
push: true

conformance/config.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type config struct {
4242
ResultsDir string `conformance:"RESULTS_DIR" yaml:"resultsDir"` // directory to write results
4343
Version string `conformance:"VERSION" yaml:"version"` // spec version used to set test defaults
4444
schemeReg string `yaml:"-"` // base for url to access the registry
45-
Commit string `yaml:"commit"` // injected git commit hash from runtime
45+
Commit string `conformance:"COMMIT" yaml:"commit"` // injected git commit hash from runtime
4646
Legacy bool `yaml:"legacy,omitempty"` // injected to indicate that conformance was run with "go test"
4747
}
4848

@@ -155,6 +155,7 @@ func configLoad() (config, error) {
155155
LogLevel: "warn",
156156
LogWriter: os.Stderr,
157157
ResultsDir: "./results",
158+
Commit: Version,
158159
APIs: configAPI{
159160
Ping: true,
160161
Pull: true,
@@ -236,19 +237,15 @@ func configLoad() (config, error) {
236237
scheme = "http"
237238
}
238239
c.schemeReg = fmt.Sprintf("%s://%s", scheme, c.Registry)
239-
// load the commit from the build info
240+
// load the commit from the build info when available, overriding any user provided value
240241
if bi, ok := debug.ReadBuildInfo(); ok && bi != nil {
241242
for _, setting := range bi.Settings {
242-
if setting.Key == biVCSCommit {
243+
if setting.Key == biVCSCommit && setting.Value != "" {
243244
c.Commit = setting.Value
244245
break
245246
}
246247
}
247248
}
248-
// fall back to version injected from the makefile ldflags parameter
249-
if c.Commit == "" {
250-
c.Commit = Version
251-
}
252249
return c, nil
253250
}
254251

0 commit comments

Comments
 (0)