Skip to content

Commit 0cec411

Browse files
ci(docker): never emit latest/v* from a manual preview build
The workflow_dispatch `ref` input is meant to preview an unmerged branch, and the only ref guaranteed to carry this workflow after merge is master — so the expected way to run it is dispatch-from-master with `ref` set to the branch. But on a workflow_dispatch dispatched from master, `github.ref` is the default branch, so `type=raw,value=latest,enable={{is_default_branch}}` still fired: a preview image would move `latest` and poison every host that pulls it. `type=semver` was likewise ungated (a dispatch from a v* tag would have minted a release tag pointing at the previewed ref). Gate both off for workflow_dispatch so a manual run can only ever produce the `sha-<short>` tag. The `latest` gate now checks the default branch explicitly instead of `{{is_default_branch}}` so it can also exclude the dispatch case; on push:master and tag:v* the emitted tags are unchanged. Tested: js-yaml and ruby YAML both parse the file; grep confirms both the self-hosted and cloud meta blocks are gated symmetrically. Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent 02c6fa1 commit 0cec411

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/docker.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,15 @@ jobs:
169169
with:
170170
images: ghcr.io/${{ github.repository }}
171171
tags: |
172-
type=raw,value=latest,enable={{is_default_branch}}
173-
type=semver,pattern={{version}}
174-
type=semver,pattern={{major}}.{{minor}}
172+
# `latest` and `v*` are release pointers. Gate them off for manual
173+
# (workflow_dispatch) runs — even one dispatched from master — so a
174+
# preview build can never move `latest` or mint a release tag. The
175+
# explicit default-branch check replaces `{{is_default_branch}}`,
176+
# which is also true on a dispatch from master and would otherwise
177+
# leak `latest` onto a preview image.
178+
type=raw,value=latest,enable=${{ github.ref_name == github.event.repository.default_branch && github.event_name != 'workflow_dispatch' }}
179+
type=semver,pattern={{version}},enable=${{ github.event_name != 'workflow_dispatch' }}
180+
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name != 'workflow_dispatch' }}
175181
# push/tag builds keep the stock sha tag (sha-<short> of github.sha).
176182
# A manual run may build a ref other than github.sha, so it tags the
177183
# resolved commit instead — same sha-<short> format, correct commit.
@@ -353,9 +359,15 @@ jobs:
353359
flavor: |
354360
suffix=-cloud,onlatest=true
355361
tags: |
356-
type=raw,value=latest,enable={{is_default_branch}}
357-
type=semver,pattern={{version}}
358-
type=semver,pattern={{major}}.{{minor}}
362+
# `latest` and `v*` are release pointers. Gate them off for manual
363+
# (workflow_dispatch) runs — even one dispatched from master — so a
364+
# preview build can never move `latest` or mint a release tag. The
365+
# explicit default-branch check replaces `{{is_default_branch}}`,
366+
# which is also true on a dispatch from master and would otherwise
367+
# leak `latest` onto a preview image.
368+
type=raw,value=latest,enable=${{ github.ref_name == github.event.repository.default_branch && github.event_name != 'workflow_dispatch' }}
369+
type=semver,pattern={{version}},enable=${{ github.event_name != 'workflow_dispatch' }}
370+
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name != 'workflow_dispatch' }}
359371
# push/tag builds keep the stock sha tag (sha-<short> of github.sha).
360372
# A manual run may build a ref other than github.sha, so it tags the
361373
# resolved commit instead — same sha-<short> format, correct commit.

0 commit comments

Comments
 (0)