11name : Publish Sandbox Docker Image
2-
2+
33on :
4- push :
5- tags :
6- - ' sandbox-v[0-9]*.[0-9]*.[0-9]*' # Matches sandbox specific semver tags in the format of sandbox-v1.2.3
7- - ' sandbox-v[0-9]*.[0-9]*.[0-9]*-*' # Matches sandbox specific semver tags in the format of sandbox-v1.2.3-beta
4+ workflow_run :
5+ workflows : ["Publish"]
6+ types : [completed]
87
98env :
109 IMAGE_NAME : ghcr.io/usherlabs/fiet-sandbox/cex-broker
@@ -14,8 +13,37 @@ permissions:
1413 packages : write
1514
1615jobs :
16+ prepare :
17+ name : Resolve sandbox tag
18+ runs-on : ubuntu-latest
19+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
20+ outputs :
21+ sandbox_version : ${{ steps.resolve.outputs.sandbox_version }}
22+ steps :
23+ - name : Checkout repository at triggering commit
24+ uses : actions/checkout@v4
25+ with :
26+ ref : ${{ github.event.workflow_run.head_sha }}
27+ fetch-depth : 0
28+
29+ - name : Resolve sandbox tag and version
30+ id : resolve
31+ run : |
32+ SANDBOX_TAG="$(git tag --points-at "${{ github.event.workflow_run.head_sha }}" | rg '^sandbox-v' -m 1 || true)"
33+ if [ -z "$SANDBOX_TAG" ]; then
34+ echo "No sandbox-v tag on triggering commit; skipping sandbox publish."
35+ echo "sandbox_version=" >> "$GITHUB_OUTPUT"
36+ exit 0
37+ fi
38+
39+ SANDBOX_VERSION="${SANDBOX_TAG#sandbox-v}"
40+ echo "Resolved sandbox version: $SANDBOX_VERSION"
41+ echo "sandbox_version=$SANDBOX_VERSION" >> "$GITHUB_OUTPUT"
42+
1743 build :
1844 name : Build (${{ matrix.arch }})
45+ needs : prepare
46+ if : ${{ needs.prepare.outputs.sandbox_version != '' }}
1947 runs-on : ${{ matrix.runner }}
2048 strategy :
2149 matrix :
2755 steps :
2856 - name : Checkout repository
2957 uses : actions/checkout@v4
58+ with :
59+ ref : ${{ github.event.workflow_run.head_sha }}
3060
3161 - name : Set up Docker Buildx
3262 uses : docker/setup-buildx-action@v3
3868 username : ${{ github.actor }}
3969 password : ${{ secrets.GITHUB_TOKEN }}
4070
41- - name : Extract metadata
42- id : meta
43- uses : docker/metadata-action@v5
44- with :
45- images : ${{ env.IMAGE_NAME }}
46- tags : |
47- type=match,pattern=sandbox-v(\d+\.\d+\.\d+.*),group=1
48-
4971 - name : Build and push Docker image
5072 uses : docker/build-push-action@v6
5173 with :
@@ -54,15 +76,16 @@ jobs:
5476 platforms : linux/${{ matrix.arch }}
5577 push : true
5678 tags : |
57- ${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta .outputs.json).tag-names[0] }}-${{ matrix.arch }}
79+ ${{ env.IMAGE_NAME }}:${{ needs.prepare .outputs.sandbox_version }}-${{ matrix.arch }}
5880 ${{ env.IMAGE_NAME }}:latest-${{ matrix.arch }}
5981 cache-from : type=gha,scope=${{ matrix.arch }}
6082 cache-to : type=gha,mode=max,scope=${{ matrix.arch }}
6183
6284 manifest :
6385 name : Publish multi-arch manifest
6486 runs-on : ubuntu-latest
65- needs : build
87+ needs : [prepare, build]
88+ if : ${{ needs.prepare.outputs.sandbox_version != '' }}
6689 steps :
6790 - name : Log in to GitHub Container Registry
6891 uses : docker/login-action@v3
@@ -74,21 +97,13 @@ jobs:
7497 - name : Set up Docker Buildx
7598 uses : docker/setup-buildx-action@v3
7699
77- - name : Extract metadata
78- id : meta
79- uses : docker/metadata-action@v5
80- with :
81- images : ${{ env.IMAGE_NAME }}
82- tags : |
83- type=match,pattern=sandbox-v(\d+\.\d+\.\d+.*),group=1
84-
85100 - name : Create and push manifest
86101 run : |
87102 docker buildx imagetools create \
88- --tag "${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta .outputs.json).tag-names[0] }}" \
103+ --tag "${{ env.IMAGE_NAME }}:${{ needs.prepare .outputs.sandbox_version }}" \
89104 --tag "${{ env.IMAGE_NAME }}:latest" \
90- "${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta .outputs.json).tag-names[0] }}-amd64" \
91- "${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta .outputs.json).tag-names[0] }}-arm64"
105+ "${{ env.IMAGE_NAME }}:${{ needs.prepare .outputs.sandbox_version }}-amd64" \
106+ "${{ env.IMAGE_NAME }}:${{ needs.prepare .outputs.sandbox_version }}-arm64"
92107
93- docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${{ fromJSON(steps.meta .outputs.json).tag-names[0] }}"
108+ docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:${{ needs.prepare .outputs.sandbox_version }}"
94109 docker buildx imagetools inspect "${{ env.IMAGE_NAME }}:latest"
0 commit comments