Skip to content

Commit

Permalink
cmd: version for old gits
Browse files Browse the repository at this point in the history
This also adds a workaround for actions/checkout#882 where the new tag
get blasted away with a new, lightweight tag for the duration of the
run.

Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Jul 27, 2023
1 parent 1bfbfa1 commit 8231b43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cut-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ jobs:
go: ${{ needs.config.outputs.build_go_version }}
- name: Create Release Archive
run: |
go mod vendor
# Fix the checkout action overwriting the tag: (see https://github.com/actions/checkout/issues/882)
git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
git archive --prefix '${{ needs.config.outputs.tar_prefix }}' -o clair.tar "${GITHUB_REF}"
go mod vendor
tar -rf clair.tar --transform 's,^,${{ needs.config.outputs.tar_prefix }},' vendor
gzip clair.tar
mv clair.tar.gz clair-${{ needs.config.outputs.version }}.tar.gz
Expand Down
6 changes: 4 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func init() {
"claircore_version": "",
"goversion": runtime.Version(),
"modified": "",
"revision": "",
"revision": revision,
"version": "",
}
info, infoOK := debug.ReadBuildInfo()
Expand Down Expand Up @@ -76,7 +76,9 @@ func init() {
switch {
case Version != "":
// Had our version injected at build: do nothing.
case len(describe) > 0 && describe[0] != '$':
case len(describe) > 0 && describe[0] != '$' && !strings.HasPrefix(describe, "%(describe:"):
// Some git versions apparently don't know about the describe format
// verb, so need to check that it's not just "%(describe..."
Version = describe
case revision[0] == '$':
Version = `(random source build)`
Expand Down

0 comments on commit 8231b43

Please sign in to comment.