Skip to content

Commit f027808

Browse files
authored
Merge pull request #707 from crazy-max/git-ref
Use GITHUB_REF when tag pushed for versioning
2 parents 231efb5 + e278959 commit f027808

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ RUN apk add --no-cache file git
1313
WORKDIR /src
1414

1515
FROM base AS version
16-
RUN --mount=target=. \
17-
echo $(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) | tee /tmp/.version
16+
ARG GIT_REF
17+
RUN --mount=target=. <<EOT
18+
set -e
19+
case "$GIT_REF" in
20+
refs/tags/v*) version="${GIT_REF#refs/tags/}" ;;
21+
*) version=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) ;;
22+
esac
23+
echo "$version" | tee /tmp/.version
24+
EOT
1825

1926
FROM base AS vendored
2027
COPY go.mod go.sum ./

docker-bake.hcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ variable "DESTDIR" {
66
default = "./bin"
77
}
88

9+
# GITHUB_REF is the actual ref that triggers the workflow and used as version
10+
# when tag is pushed: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
11+
variable "GITHUB_REF" {
12+
default = ""
13+
}
14+
915
target "_common" {
1016
args = {
1117
GO_VERSION = GO_VERSION
18+
GIT_REF = GITHUB_REF
1219
}
1320
}
1421

0 commit comments

Comments
 (0)