Skip to content

Commit a254167

Browse files
committed
ci(docker): build from the release tag instead of the pre-release SHA
The previous workflow_run trigger checked out github.event.workflow_run.head_sha, which is the commit before release-it bumps the version, tags, and creates the GitHub Release. The image was then labeled with the new version tag and :latest, so every published Docker image was one release behind its label. Switch to release: types: [published] so the build runs after release-it creates the GitHub Release, and check out the release tag in both jobs. release events are unaffected by the [skip ci] marker on the release commit, which is why on: push: tags: would not work here. Add workflow_dispatch with a tag input to allow re-publishing past releases. Closes #38
1 parent 75f9fc4 commit a254167

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
name: Docker Publish
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- "CI build"
7-
types:
8-
- "completed"
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: "Release tag to build and publish (e.g. v0.19.57)"
10+
required: true
911

1012
jobs:
1113
docker-test:
1214
name: Build and test Docker image
13-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1415
runs-on: ubuntu-latest
1516
permissions:
1617
contents: read
1718

1819
steps:
20+
- name: Resolve release tag
21+
id: ref
22+
run: |
23+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
24+
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
25+
else
26+
echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
27+
fi
28+
1929
- name: Checkout
2030
uses: actions/checkout@v6
2131
with:
2232
fetch-depth: 0
23-
ref: ${{ github.event.workflow_run.head_sha }}
33+
ref: ${{ steps.ref.outputs.tag }}
2434

2535
- name: Set up Docker Buildx
2636
uses: docker/setup-buildx-action@v4
@@ -114,32 +124,36 @@ jobs:
114124
name: Push Docker image
115125
needs:
116126
- docker-test
117-
if: ${{ github.event.workflow_run.conclusion == 'success' && needs.docker-test.result == 'success' }}
118127
runs-on: ubuntu-latest
119128
permissions:
120129
contents: read
121130
packages: write
122131

123132
steps:
133+
- name: Resolve release tag
134+
id: ref
135+
run: |
136+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
137+
echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
138+
else
139+
echo "tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT"
140+
fi
141+
124142
- name: Checkout
125143
uses: actions/checkout@v6
126144
with:
127145
fetch-depth: 0
128-
ref: ${{ github.event.workflow_run.head_sha }}
129-
130-
- name: Get latest release tag
131-
id: previoustag
132-
uses: WyriHaximus/github-action-get-previous-tag@v2
146+
ref: ${{ steps.ref.outputs.tag }}
133147

134148
- name: Docker meta
135149
id: meta
136150
uses: docker/metadata-action@v6
137151
with:
138152
images: ghcr.io/bitsocialnet/bitsocial-cli
139153
tags: |
140-
type=semver,pattern={{version}},value=${{ steps.previoustag.outputs.tag }}
141-
type=semver,pattern={{major}}.{{minor}},value=${{ steps.previoustag.outputs.tag }}
142-
type=semver,pattern={{major}},value=${{ steps.previoustag.outputs.tag }}
154+
type=semver,pattern={{version}},value=${{ steps.ref.outputs.tag }}
155+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.ref.outputs.tag }}
156+
type=semver,pattern={{major}},value=${{ steps.ref.outputs.tag }}
143157
type=raw,value=latest
144158
145159
- name: Set up QEMU

0 commit comments

Comments
 (0)