Skip to content

Commit 8fd38f4

Browse files
authored
Merge pull request #22 from proxymesh/ci/publish-via-workflow-run
ci: trigger Publish after Release on merge (workflow_run)
2 parents d31e313 + 33517c9 commit 8fd38f4

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,62 @@ on:
44
release:
55
types: [published]
66
workflow_dispatch:
7+
# GitHub does not start new workflow runs for events caused by the default
8+
# GITHUB_TOKEN (e.g. gh release create in another workflow). After
9+
# "Release on merge" creates a release, trigger publish here instead.
10+
workflow_run:
11+
workflows: [Release on merge]
12+
types: [completed]
713

814
permissions:
915
contents: read
1016
id-token: write
1117

1218
jobs:
1319
publish:
20+
if: >-
21+
github.event_name != 'workflow_run' ||
22+
github.event.workflow_run.conclusion == 'success'
1423
runs-on: ubuntu-latest
1524
steps:
1625
- uses: actions/checkout@v6
26+
with:
27+
ref: ${{ github.event_name == 'workflow_run' && 'main' || github.event_name == 'release' && github.ref || 'main' }}
28+
29+
- name: Decide whether to publish
30+
id: gate
31+
env:
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
set -euo pipefail
35+
if [[ "${{ github.event_name }}" != "workflow_run" ]]; then
36+
echo "publish=true" >> "${GITHUB_OUTPUT}"
37+
exit 0
38+
fi
39+
VERSION="$(node -p "require('./package.json').version")"
40+
TAG="v-${VERSION}"
41+
if gh release view "${TAG}" --repo "${{ github.repository }}" >/dev/null 2>&1; then
42+
echo "publish=true" >> "${GITHUB_OUTPUT}"
43+
else
44+
echo "No GitHub release ${TAG} yet (or release job was skipped); skipping publish."
45+
echo "publish=false" >> "${GITHUB_OUTPUT}"
46+
fi
1747
1848
# Omit registry-url: setup-node otherwise sets NODE_AUTH_TOKEN to a placeholder and npm publish uses that instead of OIDC.
1949
- name: Setup Node
50+
if: steps.gate.outputs.publish == 'true'
2051
uses: actions/setup-node@v6
2152
with:
2253
node-version: 22
2354
check-latest: true
2455
cache: npm
2556

2657
- name: Upgrade npm for trusted publishing (OIDC)
58+
if: steps.gate.outputs.publish == 'true'
2759
run: npm install -g npm@">=11.5.1"
2860

2961
- name: Ensure versions match
62+
if: steps.gate.outputs.publish == 'true'
3063
shell: bash
3164
run: |
3265
set -euo pipefail
@@ -46,11 +79,14 @@ jobs:
4679
fi
4780
4881
- name: Install dependencies
82+
if: steps.gate.outputs.publish == 'true'
4983
run: npm install --ignore-scripts --no-package-lock
5084

5185
- name: Publish to npm
86+
if: steps.gate.outputs.publish == 'true'
5287
run: npm publish --access public --provenance
5388

5489
- name: Publish to JSR
90+
if: steps.gate.outputs.publish == 'true'
5591
run: npx jsr publish
5692

.github/workflows/release-on-merge.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Release on merge
22

33
# When a release/* PR merges into main, create a GitHub release (tag v-<version>).
4-
# The published release triggers publish.yml (npm + JSR).
4+
# Events from GITHUB_TOKEN do not start other workflows; publish.yml is triggered via
5+
# workflow_run when this workflow completes (see publish.yml).
56

67
on:
78
pull_request:

0 commit comments

Comments
 (0)