Skip to content

Commit e78dbd6

Browse files
authored
fix: use workflow_run instead of workflow_call due to Trusted Publisher restrictions (#310)
fix: use workflow_run instead of workflow_call due to Trusted Publishers restriction
1 parent 4a427e5 commit e78dbd6

File tree

2 files changed

+27
-49
lines changed

2 files changed

+27
-49
lines changed

.github/workflows/publish.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ name: Publish
44

55
on:
66
workflow_dispatch:
7-
workflow_call:
8-
inputs:
9-
branch:
10-
description: The branch containing the release code snapshot
11-
required: true
12-
type: string
13-
default: ""
7+
workflow_run:
8+
workflows: ["Release"]
9+
types:
10+
- completed
1411
push:
1512
branches:
1613
- main
1714

1815
permissions:
1916
contents: write
2017
id-token: write
18+
actions: read
2119

2220
jobs:
2321
publish-ea:
@@ -72,14 +70,28 @@ jobs:
7270
npm publish --verbose --tag ea --access public --provenance
7371
7472
publish-release:
75-
if: github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch'
73+
if: (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || github.event_name == 'workflow_dispatch'
7674
runs-on: ubuntu-latest
7775
name: Publish release to NPM
7876
steps:
77+
- name: Get releasebranch.txt artifact from Release pipeline
78+
if: github.event_name == 'workflow_run'
79+
uses: actions/download-artifact@v5
80+
with:
81+
name: releasebranch.txt
82+
run-id: ${{ github.event.workflow_run.id }}
83+
github-token: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Read releasebranch.txt
86+
id: releasebranch
87+
run: |
88+
echo "branch=$(cat releasebranch.txt)" >> "$GITHUB_OUTPUT"
89+
rm releasebranch.txt
90+
7991
- name: Checkout sources
8092
uses: actions/checkout@v4
8193
with:
82-
ref: ${{ inputs.branch || github.ref }}
94+
ref: ${{ (github.event_name == 'workflow_run' && steps.releasebranch.outputs.branch) || github.ref }}
8395
fetch-depth: 0
8496

8597
- name: Install node 24

.github/workflows/release.yml

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222
permissions:
2323
contents: write
2424
pull-requests: write
25-
outputs:
26-
version: ${{ steps.bump.outputs.version }}
2725
steps:
2826
- name: Checkout sources
2927
uses: actions/checkout@v4
@@ -42,33 +40,6 @@ jobs:
4240
git config user.name "${{ github.actor }}"
4341
git config user.email "${{ github.actor }}@users.noreply.github.com"
4442
45-
- name: Get previous released annotated tag
46-
id: last-release
47-
run: |
48-
# Get the latest tag that doesn't have -ea suffix (handles both -ea. and -ea- formats)
49-
TAG=$(git tag -l --sort=-version:refname | grep -vE -- '-ea[.-]' | head -n 1)
50-
if [ -z "$TAG" ]; then
51-
# If no release tag exists, use the base version from package.json
52-
BASE_VERSION=$(node -p "require('./package.json').version" | sed -E 's/-ea[.-][0-9]+$//')
53-
echo "base-tag=$BASE_VERSION" >> "$GITHUB_OUTPUT"
54-
echo "full-tag=$BASE_VERSION" >> "$GITHUB_OUTPUT"
55-
else
56-
echo "base-tag=$TAG" >> "$GITHUB_OUTPUT"
57-
echo "full-tag=$TAG" >> "$GITHUB_OUTPUT"
58-
fi
59-
60-
- name: Get first tag in current development iteration
61-
id: fetch-tag
62-
run: |
63-
BASE_TAG="${{ steps.last-release.outputs.base-tag }}"
64-
# Find the oldest EA tag for this base version (handles both -ea. and -ea- formats)
65-
OLDEST_EA_TAG=$(git tag -l --sort=creatordate | grep -E "^${BASE_TAG}-ea[.-]" | head -n 1)
66-
if [ -n "$OLDEST_EA_TAG" ]; then
67-
echo "oldest-tag=$OLDEST_EA_TAG" >> "$GITHUB_OUTPUT"
68-
else
69-
echo "oldest-tag=$BASE_TAG" >> "$GITHUB_OUTPUT"
70-
fi
71-
7243
- name: Update package with new version
7344
id: bump
7445
run: |
@@ -91,6 +62,12 @@ jobs:
9162
git add package-lock.json
9263
git commit -m "build: release ${{ steps.bump.outputs.version }} [skip ci]"
9364
git push origin "$BRANCH"
65+
echo "$BRANCH" > releasebranch.txt
66+
67+
- uses: actions/upload-artifact@v2
68+
with:
69+
name: releasebranch
70+
path: releasebranch.txt
9471

9572
- name: Create GitHub release tag
9673
uses: softprops/action-gh-release@v1
@@ -111,14 +88,3 @@ jobs:
11188
--head "release/v${{ steps.bump.outputs.version }}"
11289
env:
11390
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114-
115-
trigger-publish:
116-
name: Trigger Publish pipeline
117-
needs: create-release
118-
permissions:
119-
contents: write
120-
id-token: write
121-
uses: ./.github/workflows/publish.yml
122-
with:
123-
branch: "release/v${{ needs.create-release.outputs.version }}"
124-

0 commit comments

Comments
 (0)