Skip to content

Commit 671c105

Browse files
committed
Fixup from Franco's feedback
1 parent d18ad85 commit 671c105

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

.github/workflows/docker.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ jobs:
5959
6060
# Compute tags. We want the following behaviour:
6161
#
62-
# 1. Building on tag: image tagged `tag`
63-
# 2. Building on release: image tagged `latest`
62+
# 1. Building on tag:
63+
#
64+
# a. Image tagged `<tag>`
65+
#
66+
# b. If the tag is the "latest" one for the present major release,
67+
# then also tag it as "latest"
68+
#
6469
# 3. Building on master: image tagged `unstable`.
6570
6671
# Let's default to 'unstable'.
@@ -75,13 +80,8 @@ jobs:
7580
IMAGE_LABEL=${{github.ref_name}} && \
7681
VERSION=${{github.ref_name}}
7782
78-
# If we're running on the release branch, tag it as `latest`,
79-
# and leave the version as the git commit.
80-
[[ ${GITHUB_REF_NAME} = "release" ]] && \
81-
IMAGE_LABEL=latest
82-
8383
# If we're running on master, tag it as "unstable" and
84-
# and again leave the version as the git commit.
84+
# and leave the version as the git commit.
8585
[[ ${GITHUB_REF_NAME} = "master" ]] && \
8686
IMAGE_LABEL=unstable
8787
@@ -95,6 +95,27 @@ jobs:
9595
--label org.opencontainers.image.version=${VERSION} \
9696
--tag ${IMAGE_NAME}:${IMAGE_LABEL} -
9797
98+
# Tag the build as 'latest' if it's the latest tag.
99+
if [[ ${BUILDING_TAG} = true ]]; then
100+
# Build a sorted list of tags . We have to grep-exclude some tags
101+
# that we don't want to include; i.e. ones that don't point to our
102+
# actual releases.
103+
git tag -l | grep -P '^\d+.\d+.\d+$' >tags.txt
104+
105+
# Get the largest one (sort -V sorts as versions).
106+
sort -V tags.txt | tail -n1 >latest.txt
107+
108+
# Compare it to mine; and if it's the same, then I am the latest, so
109+
# we can tag it as such.
110+
echo ${{ github.ref_name }}>mine.txt
111+
112+
# Note: This will also print the diff if it fails, which is useful
113+
# for debugging.
114+
if (diff mine.txt latest.txt); then
115+
docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:latest
116+
fi
117+
fi
118+
98119
# Also tag with ref name when manually dispatched
99120
[[ ${{github.event_name == 'workflow_dispatch'}} = true ]] && \
100121
docker tag ${IMAGE_NAME}:${IMAGE_LABEL} ${IMAGE_NAME}:workflow_dispatch-${{github.event.inputs.ref_name}}

0 commit comments

Comments
 (0)