Skip to content

Commit 397c0a9

Browse files
committed
Merge branch 'develop'
2 parents f3799b8 + de1f482 commit 397c0a9

File tree

2 files changed

+70
-28
lines changed

2 files changed

+70
-28
lines changed
Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: Publish Sandbox Docker Image
2-
2+
33
on:
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

98
env:
109
IMAGE_NAME: ghcr.io/usherlabs/fiet-sandbox/cex-broker
@@ -14,8 +13,37 @@ permissions:
1413
packages: write
1514

1615
jobs:
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:
@@ -27,6 +55,8 @@ jobs:
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
@@ -38,14 +68,6 @@ jobs:
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"

.github/workflows/publish.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,36 @@ on:
66
push:
77
tags:
88
- "v*"
9+
- "sandbox-v[0-9]*.[0-9]*.[0-9]*"
10+
- "sandbox-v[0-9]*.[0-9]*.[0-9]*-*"
911

1012
jobs:
13+
check-npm-version:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
should_publish: ${{ steps.npm-check.outputs.should_publish }}
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
21+
- name: Check whether package version already exists on npm
22+
id: npm-check
23+
run: |
24+
PACKAGE_NAME="$(node -p "require('./package.json').name")"
25+
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
26+
echo "Checking ${PACKAGE_NAME}@${PACKAGE_VERSION}"
27+
28+
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
29+
echo "Package version already published; skipping publish job."
30+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
31+
else
32+
echo "Package version not published yet; publish job will run."
33+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
34+
fi
35+
1136
publish:
37+
needs: check-npm-version
38+
if: needs.check-npm-version.outputs.should_publish == 'true'
1239
runs-on: ubuntu-latest
1340

1441
steps:
@@ -35,4 +62,4 @@ jobs:
3562
- name: Publish to npm
3663
run: bun publish -p --access public
3764
env:
38-
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
65+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)