Skip to content

Commit 5cd695c

Browse files
authored
chore: trigger action from forks (#1099)
## What kind of change does this PR introduce? Using `pull_request_target` to access secrets when PRs come from forks. This is secure, since we control which PRs trigger the preview. ## What is the current behavior? The workflow cannot run on PRs from forks because it does not have access to `app-id`. ## What is the new behavior? Use `pull_request_target` to get access to secrets.
1 parent ce1f116 commit 5cd695c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

.github/workflows/preview-release.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ on:
2727
- 'tsconfig.json'
2828

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

3334
jobs:
@@ -38,7 +39,7 @@ jobs:
3839
(
3940
github.event_name == 'workflow_dispatch' ||
4041
github.event_name == 'push' ||
41-
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
42+
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
4243
)
4344
runs-on: ubuntu-latest
4445
outputs:
@@ -122,7 +123,7 @@ jobs:
122123
triggering_pr: prNumber.toString(),
123124
preview_url: '${{ needs.preview.outputs.preview-url }}',
124125
package_name: '${{ needs.preview.outputs.package-name }}',
125-
triggering_sha: context.eventName === 'pull_request' ? context.payload.pull_request.head.sha : context.sha
126+
triggering_sha: context.eventName === 'pull_request_target' ? context.payload.pull_request.head.sha : context.sha
126127
}
127128
});
128129
@@ -134,7 +135,7 @@ jobs:
134135
}
135136
136137
- name: Find existing preview comment
137-
if: github.event_name == 'pull_request'
138+
if: github.event_name == 'pull_request_target'
138139
uses: peter-evans/find-comment@v3
139140
id: find-comment
140141
with:
@@ -144,7 +145,7 @@ jobs:
144145
body-includes: '<!-- auth-js-preview-status -->'
145146

146147
- name: Create or update preview comment
147-
if: github.event_name == 'pull_request'
148+
if: github.event_name == 'pull_request_target'
148149
uses: peter-evans/create-or-update-comment@v4
149150
with:
150151
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)