Skip to content

Commit 02c6fa1

Browse files
ci(docker): add workflow_dispatch to build a SHA-tagged preview image
`docker.yml` only triggered on `push` to `master` and on `v*` tags, so there was no way to build an image from an unmerged branch. Previewing a change end to end before merging therefore had no image to deploy, and because the concurrency group is `docker-${github.ref}` a *pending* master run can still be superseded by the next push — so an arbitrary master SHA is not guaranteed to have an image either. Add a `workflow_dispatch` trigger with an optional `ref` input: - The manual run checks out `inputs.ref` (falling back to `github.sha`), resolves the exact commit, and publishes a `sha-<short>` image tag for that commit. The `latest` and `v*`/semver tags stay gated to the push and tag events, so a dispatch never publishes a release tag. - `type=sha` is kept exactly as-is for push/tag events; the dispatch tag is emitted as a raw `sha-<short>` of the resolved commit so it is correct even when the built ref differs from `github.sha`. - The commit stamped into the image (`PAPERCLIP_BUILD_COMMIT`) is taken from the same resolved commit; on push/tag it equals `github.sha`, so those builds are unchanged. This is intentionally not the release workflow, which publishes a stable `v*` tag — a much bigger act than building a review image. The resulting `sha-<short>` tag is consumed as an ordinary app ref by the fleet deploy tooling, so nothing downstream changes. Tested: `actionlint` clean on the workflow; YAML parses; verified the diff leaves the push/tag paths byte-for-byte behaviourally identical (`ref` and `PAPERCLIP_BUILD_COMMIT` both resolve to `github.sha`, and `type=sha` is unchanged when `github.event_name != 'workflow_dispatch'`). Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent 19be4cf commit 02c6fa1

1 file changed

Lines changed: 63 additions & 4 deletions

File tree

.github/workflows/docker.yml

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ on:
66
- "master"
77
tags:
88
- "v*"
9+
# Manual builds so an unmerged ref can be previewed before it lands. This
10+
# publishes a SHA-tagged image and no `latest`/`v*` (release) tag — it is a
11+
# review image, not a release — and the deploy tooling accepts the resulting
12+
# `sha-<short>` tag as an ordinary app ref, so nothing downstream changes.
13+
# Deliberately not the release workflow: that one publishes a stable `v*`
14+
# release, a far bigger act than building a preview image.
15+
workflow_dispatch:
16+
inputs:
17+
ref:
18+
description: "Branch, tag, or commit SHA to build. Defaults to the ref this run was dispatched on."
19+
required: false
20+
type: string
21+
default: ""
922

1023
permissions:
1124
contents: read
@@ -26,10 +39,29 @@ jobs:
2639
- name: Checkout
2740
uses: actions/checkout@v7
2841
with:
42+
# push/tag builds resolve to github.sha — the checkout default, so
43+
# their behaviour is unchanged. A manual run may override it with the
44+
# `ref` input to build an unmerged branch, tag, or commit.
45+
ref: ${{ inputs.ref || github.sha }}
2946
# Full history and tags so `git describe` below can compute the
3047
# release version to stamp into the image.
3148
fetch-depth: 0
3249

50+
# Pin every downstream reference to the exact commit that was checked
51+
# out. On push/tag builds this equals github.sha; on a manual run it is
52+
# the head of the `ref` input, which can differ from github.sha (the ref
53+
# the dispatch ran on). The SHA image tag and the commit stamped into the
54+
# image are both derived from this, so a manual build always tags the
55+
# commit it actually built.
56+
- name: Resolve build ref
57+
id: resolve-ref
58+
run: |
59+
set -euo pipefail
60+
sha="$(git rev-parse HEAD)"
61+
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
62+
echo "short_sha=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"
63+
echo "Building ${GITHUB_REF} at ${sha}"
64+
3365
# `.git` is dockerignored, so a running image cannot derive its own
3466
# version and otherwise reports the source package.json placeholder in
3567
# analytics and the debug panel. Compute it here from the pristine
@@ -140,7 +172,11 @@ jobs:
140172
type=raw,value=latest,enable={{is_default_branch}}
141173
type=semver,pattern={{version}}
142174
type=semver,pattern={{major}}.{{minor}}
143-
type=sha
175+
# push/tag builds keep the stock sha tag (sha-<short> of github.sha).
176+
# A manual run may build a ref other than github.sha, so it tags the
177+
# resolved commit instead — same sha-<short> format, correct commit.
178+
type=sha,enable=${{ github.event_name != 'workflow_dispatch' }}
179+
type=raw,value=sha-${{ steps.resolve-ref.outputs.short_sha }},enable=${{ github.event_name == 'workflow_dispatch' }}
144180
labels: |
145181
io.github.paperclipai.schema.last-migration=${{ steps.schema.outputs.last }}
146182
io.github.paperclipai.schema.migration-count=${{ steps.schema.outputs.count }}
@@ -155,7 +191,7 @@ jobs:
155191
target: production
156192
build-args: |
157193
PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}
158-
PAPERCLIP_BUILD_COMMIT=${{ github.sha }}
194+
PAPERCLIP_BUILD_COMMIT=${{ steps.resolve-ref.outputs.sha }}
159195
CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}
160196
platforms: linux/amd64,linux/arm64
161197
push: true
@@ -183,10 +219,29 @@ jobs:
183219
- name: Checkout
184220
uses: actions/checkout@v7
185221
with:
222+
# push/tag builds resolve to github.sha — the checkout default, so
223+
# their behaviour is unchanged. A manual run may override it with the
224+
# `ref` input to build an unmerged branch, tag, or commit.
225+
ref: ${{ inputs.ref || github.sha }}
186226
# Full history and tags so `git describe` below can compute the
187227
# release version to stamp into the image.
188228
fetch-depth: 0
189229

230+
# Pin every downstream reference to the exact commit that was checked
231+
# out. On push/tag builds this equals github.sha; on a manual run it is
232+
# the head of the `ref` input, which can differ from github.sha (the ref
233+
# the dispatch ran on). The SHA image tag and the commit stamped into the
234+
# image are both derived from this, so a manual build always tags the
235+
# commit it actually built.
236+
- name: Resolve build ref
237+
id: resolve-ref
238+
run: |
239+
set -euo pipefail
240+
sha="$(git rev-parse HEAD)"
241+
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
242+
echo "short_sha=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"
243+
echo "Building ${GITHUB_REF} at ${sha}"
244+
190245
# `.git` is dockerignored, so a running image cannot derive its own
191246
# version and otherwise reports the source package.json placeholder in
192247
# analytics and the debug panel. Compute it here from the pristine
@@ -301,7 +356,11 @@ jobs:
301356
type=raw,value=latest,enable={{is_default_branch}}
302357
type=semver,pattern={{version}}
303358
type=semver,pattern={{major}}.{{minor}}
304-
type=sha
359+
# push/tag builds keep the stock sha tag (sha-<short> of github.sha).
360+
# A manual run may build a ref other than github.sha, so it tags the
361+
# resolved commit instead — same sha-<short> format, correct commit.
362+
type=sha,enable=${{ github.event_name != 'workflow_dispatch' }}
363+
type=raw,value=sha-${{ steps.resolve-ref.outputs.short_sha }},enable=${{ github.event_name == 'workflow_dispatch' }}
305364
labels: |
306365
io.github.paperclipai.schema.last-migration=${{ steps.schema.outputs.last }}
307366
io.github.paperclipai.schema.migration-count=${{ steps.schema.outputs.count }}
@@ -316,7 +375,7 @@ jobs:
316375
build-args: |
317376
CLOUD_BUNDLED_PLUGINS=daytona
318377
PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}
319-
PAPERCLIP_BUILD_COMMIT=${{ github.sha }}
378+
PAPERCLIP_BUILD_COMMIT=${{ steps.resolve-ref.outputs.sha }}
320379
CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}
321380
# amd64 only, unlike the self-hosted image above: the cloud variant
322381
# is consumed exclusively by managed-deployment hosts, which run

0 commit comments

Comments
 (0)