Skip to content

Commit 613d321

Browse files
committed
ci: tag docker images of releases
- rework tag pattern match to match X.Y and X.Y.Z - bring back latest tags for releases and protect them in cleanup
1 parent 7fd4843 commit 613d321

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

.github/workflows/cleanup.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ jobs:
4747
package-name: ${{ env.PACKAGE_NAME }}
4848
package-type: container
4949
min-versions-to-keep: 30
50-
ignore-versions: '^(main|latest|\d+\.\d+)$'
50+
ignore-versions: '^(main|latest|\d+\.\d+|\d+\.\d+\.\d+)$'
5151

5252
cleanup-branch:
5353
name: Clean up branch images
5454
runs-on: ubuntu-latest
55-
if: github.event_name == 'delete'
55+
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
5656
permissions:
5757
packages: write
5858
steps:

.github/workflows/docker-ci.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
RELAY_REF_INPUT: ${{ steps.relay.outputs.ref }}
9999
EVENT_NAME: ${{ github.event_name }}
100100
REF_NAME: ${{ github.ref_name }}
101+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101102
run: |
102103
IMAGE="${REGISTRY}/${IMAGE_NAME}"
103104
RELAY_REF="${RELAY_REF_INPUT}"
@@ -127,11 +128,24 @@ jobs:
127128
BRANCH_TAG=$(echo "${RELAY_REF}" | sed 's|/|-|g')
128129
TAGS="${TAGS}"$'\n'"${IMAGE}:${BRANCH_TAG}"
129130
if [[ "${RELAY_REF}" =~ ^v?([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
130-
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
131-
MINOR="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
132-
TAGS="${TAGS}"$'\n'"${IMAGE}:${VERSION}"
133-
TAGS="${TAGS}"$'\n'"${IMAGE}:${MINOR}"
134-
TAGS="${TAGS}"$'\n'"${IMAGE}:latest"
131+
MAJOR="${BASH_REMATCH[1]}"
132+
MINOR="${BASH_REMATCH[2]}"
133+
PATCH="${BASH_REMATCH[3]}"
134+
VERSION="${MAJOR}.${MINOR}.${PATCH}"
135+
TAGS="${TAGS}"$'\n'"${IMAGE}:${VERSION}"$'\n'"${IMAGE}:${MAJOR}.${MINOR}"
136+
# `latest` only if this is the highest semver published so far,
137+
# so a back-ported patch on an old minor line cannot clobber it.
138+
HIGHEST=$(gh api \
139+
"orgs/chatmail/packages/container/docker/versions?per_page=100" \
140+
--jq '[.[].metadata.container.tags[]
141+
| select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))]
142+
| sort_by(split(".") | map(tonumber)) | last // empty' \
143+
2>/dev/null) || true
144+
if [ -z "$HIGHEST" ] || \
145+
[ "$(printf '%s\n%s\n' "$HIGHEST" "$VERSION" \
146+
| sort -V | tail -1)" = "$VERSION" ]; then
147+
TAGS="${TAGS}"$'\n'"${IMAGE}:latest"
148+
fi
135149
fi
136150
fi
137151
echo "tags<<EOF" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)