Skip to content

Commit c705fbb

Browse files
authored
chore: trigger action from forks (#520)
1 parent 0318ea3 commit c705fbb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/core/realtime-js/.github/workflows/preview-release.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ on:
2727
- 'package-lock.json'
2828
- 'tsconfig.json'
2929

30-
# PR triggers - only when labeled
31-
pull_request:
30+
# PR triggers - only when labeled
31+
# Using pull_request_target to access secrets when PRs come from forks
32+
pull_request_target:
3233
types: [labeled, synchronize]
3334

3435
jobs:
@@ -39,7 +40,7 @@ jobs:
3940
(
4041
github.event_name == 'workflow_dispatch' ||
4142
github.event_name == 'push' ||
42-
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
43+
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
4344
)
4445
runs-on: ubuntu-latest
4546
outputs:
@@ -48,6 +49,9 @@ jobs:
4849
steps:
4950
- name: Checkout code
5051
uses: actions/checkout@v4
52+
with:
53+
# For pull_request_target, we need to explicitly checkout the PR's head
54+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
5155

5256
- name: Setup Node.js
5357
uses: actions/setup-node@v4
@@ -123,7 +127,7 @@ jobs:
123127
triggering_pr: prNumber.toString(),
124128
preview_url: '${{ needs.preview.outputs.preview-url }}',
125129
package_name: '${{ needs.preview.outputs.package-name }}',
126-
triggering_sha: context.eventName === 'pull_request' ? context.payload.pull_request.head.sha : context.sha
130+
triggering_sha: context.eventName === 'pull_request_target' ? context.payload.pull_request.head.sha : context.sha
127131
}
128132
});
129133
@@ -135,7 +139,7 @@ jobs:
135139
}
136140
137141
- name: Find existing preview comment
138-
if: github.event_name == 'pull_request'
142+
if: github.event_name == 'pull_request_target'
139143
uses: peter-evans/find-comment@v3
140144
id: find-comment
141145
with:
@@ -145,7 +149,7 @@ jobs:
145149
body-includes: '<!-- realtime-js-preview-status -->'
146150

147151
- name: Create or update preview comment
148-
if: github.event_name == 'pull_request'
152+
if: github.event_name == 'pull_request_target'
149153
uses: peter-evans/create-or-update-comment@v4
150154
with:
151155
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)