Skip to content

Commit d83c7b1

Browse files
authored
fix: Fix tags in official Docker images and binaries (#1370)
The release workflows did not run checkout with `fetch-tags: true`, so the builds were unable to compute the correct release version number. I audited all instances of `actions/checkout` to add `fetch-tags` where needed and clean up unneeded options. I also had to fix options to `docker/build-push-action`, which by default ignores `actions/checkout` and tries to pull from git itself. This led to the Docker build running in a context without the new tag. Finally, to make verification easier and provide version info in the build logs, this adds debugging info to the version-generation script via stderr. Closes #1366
1 parent 5ee2b7f commit d83c7b1

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
with:
9797
ref: ${{ inputs.ref }}
9898
submodules: recursive
99+
fetch-tags: true
99100

100101
- name: Install Linux deps
101102
if: runner.os == 'Linux'

.github/workflows/publish-docker.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
with:
4848
ref: ${{ inputs.tag }}
4949
submodules: recursive
50+
fetch-tags: true
5051

5152
- name: Log in to Docker Hub
5253
uses: docker/login-action@v3
@@ -57,12 +58,22 @@ jobs:
5758
- name: Push to Docker Hub
5859
uses: docker/build-push-action@v5
5960
with:
61+
# Important: use actions/checkout source, which has the right tags!
62+
# Without context: ., this action will try to fetch git source
63+
# itself, and it will be unable to determine the correct version
64+
# number.
65+
context: .
6066
push: true
6167
tags: ${{ secrets.DOCKERHUB_PACKAGE_NAME }}:${{ inputs.tag }}
6268

6369
- name: Push to Docker Hub as "latest"
6470
if: ${{ inputs.latest }}
6571
uses: docker/build-push-action@v5
6672
with:
73+
# Important: use actions/checkout source, which has the right tags!
74+
# Without context: ., this action will try to fetch git source
75+
# itself, and it will be unable to determine the correct version
76+
# number.
77+
context: .
6778
push: true
6879
tags: ${{ secrets.DOCKERHUB_PACKAGE_NAME }}:latest

.github/workflows/release-please.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555
- uses: actions/checkout@v4
5656
with:
5757
fetch-tags: true
58-
persist-credentials: false
5958

6059
- name: Compute latest
6160
id: compute

packager/version/generate_version_string.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,37 @@
88
"""This script is used to generate version string for packager."""
99

1010
import subprocess
11+
import sys
1112

1213
if __name__ == '__main__':
1314
try:
1415
version_tag = subprocess.check_output('git tag --points-at HEAD',
1516
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
17+
if version_tag:
18+
print('Found version tag: {}'.format(version_tag), file=sys.stderr)
19+
else:
20+
print('Cannot find version tag!', file=sys.stderr)
1621
except subprocess.CalledProcessError as e:
1722
# git tag --points-at is not supported in old versions of git. Just ignore
1823
# version_tag in this case.
1924
version_tag = None
25+
print('Old version of git, cannot determine version tag!', file=sys.stderr)
2026

2127
try:
2228
version_hash = subprocess.check_output('git rev-parse --short HEAD',
2329
stderr=subprocess.STDOUT, shell=True).decode().rstrip()
30+
print('Version hash: {}'.format(version_hash), file=sys.stderr)
2431
except subprocess.CalledProcessError as e:
2532
version_hash = 'unknown-version'
33+
print('Cannot find version hasah!', file=sys.stderr)
2634

2735
if version_tag:
28-
print('{0}-{1}'.format(version_tag, version_hash))
36+
output = '{0}-{1}'.format(version_tag, version_hash)
2937
else:
30-
print(version_hash)
38+
output = version_hash
39+
40+
# Final debug message, mirroring what is used to generate the source file:
41+
print('Final output: {}'.format(output), file=sys.stderr)
42+
43+
# Actually used to generate the source file:
44+
print(output)

0 commit comments

Comments
 (0)