Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GITHUB_REF when tag pushed for versioning #707

Merged
merged 1 commit into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ RUN apk add --no-cache file git
WORKDIR /src

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

FROM base AS vendored
COPY go.mod go.sum ./
Expand Down
7 changes: 7 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ variable "DESTDIR" {
default = "./bin"
}

# GITHUB_REF is the actual ref that triggers the workflow and used as version
# when tag is pushed: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
variable "GITHUB_REF" {
default = ""
}

target "_common" {
args = {
GO_VERSION = GO_VERSION
GIT_REF = GITHUB_REF
}
}

Expand Down