11name : build
2- on : [push, pull_request ]
2+ on : [push, pull_request_target ]
33
44jobs :
55 test :
1414 checks : write
1515 pull-requests : write
1616 steps :
17- - uses : actions/checkout@v4
17+ - if : github.event_name == 'push'
18+ uses : actions/checkout@v4
19+ - if : github.event_name == 'pull_request_target'
20+ uses : actions/checkout@v4
21+ with :
22+ repository : ${{ github.event.pull_request.head.repo.full_name }}
23+ ref : ${{ github.event.pull_request.head.ref }}
1824 - uses : denoland/setup-deno@v2
1925 with :
2026 deno-version : v2.x
5460 fail-fast : false
5561 runs-on : ${{ matrix.os }}
5662 steps :
57- - uses : actions/checkout@v4
63+ - if : github.event_name == 'push'
64+ uses : actions/checkout@v4
65+ - if : github.event_name == 'pull_request_target'
66+ uses : actions/checkout@v4
67+ with :
68+ repository : ${{ github.event.pull_request.head.repo.full_name }}
69+ ref : ${{ github.event.pull_request.head.ref }}
5870 - uses : denoland/setup-deno@v2
5971 with :
6072 deno-version : v2.x
7486 fail-fast : false
7587 runs-on : ${{ matrix.os }}
7688 steps :
77- - uses : actions/checkout@v4
89+ - if : github.event_name == 'push'
90+ uses : actions/checkout@v4
91+ - if : github.event_name == 'pull_request_target'
92+ uses : actions/checkout@v4
93+ with :
94+ repository : ${{ github.event.pull_request.head.repo.full_name }}
95+ ref : ${{ github.event.pull_request.head.ref }}
7896 - uses : denoland/setup-deno@v2
7997 with :
8098 deno-version : v2.x
@@ -93,7 +111,13 @@ jobs:
93111 lint :
94112 runs-on : ubuntu-latest
95113 steps :
96- - uses : actions/checkout@v4
114+ - if : github.event_name == 'push'
115+ uses : actions/checkout@v4
116+ - if : github.event_name == 'pull_request_target'
117+ uses : actions/checkout@v4
118+ with :
119+ repository : ${{ github.event.pull_request.head.repo.full_name }}
120+ ref : ${{ github.event.pull_request.head.ref }}
97121 - uses : denoland/setup-deno@v2
98122 with :
99123 deno-version : v2.x
@@ -105,7 +129,13 @@ jobs:
105129 id-token : write
106130 contents : read
107131 steps :
108- - uses : actions/checkout@v4
132+ - if : github.event_name == 'push'
133+ uses : actions/checkout@v4
134+ - if : github.event_name == 'pull_request_target'
135+ uses : actions/checkout@v4
136+ with :
137+ repository : ${{ github.event.pull_request.head.repo.full_name }}
138+ ref : ${{ github.event.pull_request.head.ref }}
109139 - uses : denoland/setup-deno@v2
110140 with :
111141 deno-version : v2.x
@@ -135,7 +165,13 @@ jobs:
135165 id-token : write
136166 contents : write
137167 steps :
138- - uses : actions/checkout@v4
168+ - if : github.event_name == 'push'
169+ uses : actions/checkout@v4
170+ - if : github.event_name == 'pull_request_target'
171+ uses : actions/checkout@v4
172+ with :
173+ repository : ${{ github.event.pull_request.head.repo.full_name }}
174+ ref : ${{ github.event.pull_request.head.ref }}
139175 - uses : denoland/setup-deno@v2
140176 with :
141177 deno-version : v2.x
@@ -145,21 +181,34 @@ jobs:
145181 - uses : pnpm/action-setup@v4
146182 with :
147183 version : 10
148- - if : github.ref_type == 'branch'
184+ - if : github.event_name == 'push' && github. ref_type == 'branch'
149185 run : |
150186 jq \
151187 --arg build "$GITHUB_RUN_NUMBER" \
152188 --arg commit "${GITHUB_SHA::8}" \
153189 '.version = .version + "-dev." + $build + "+" + $commit' \
154190 deno.json > deno.json.tmp
155191 mv deno.json.tmp deno.json
192+ working-directory : ${{ github.workspace }}/fedify/
193+ - if : github.event_name == 'pull_request_target'
194+ run : |
156195 jq \
196+ --arg pr_number "$PR_NUMBER" \
157197 --arg build "$GITHUB_RUN_NUMBER" \
158198 --arg commit "${GITHUB_SHA::8}" \
159- '.version = .version + "-dev ." + $build + "+" + $commit' \
160- package .json > package .json.tmp
161- mv package .json.tmp package .json
199+ '.version = .version + "-pr." + $pr_number + " ." + $build + "+" + $commit' \
200+ deno .json > deno .json.tmp
201+ mv deno .json.tmp deno .json
162202 working-directory : ${{ github.workspace }}/fedify/
203+ env :
204+ PR_NUMBER : ${{ github.event.pull_request.number }}
205+ - id : versioning
206+ run : |
207+ set -ex
208+ echo version="$(jq -r .version deno.json)" >> $GITHUB_OUTPUT
209+ echo short_version="$(jq -r .version deno.json | sed 's/[+].*//')" >> $GITHUB_OUTPUT
210+ working-directory : ${{ github.workspace }}/fedify/
211+ - run : deno task -r sync-version
163212 - if : github.ref_type == 'tag'
164213 run : |
165214 set -ex
@@ -202,29 +251,27 @@ jobs:
202251 fedify/fedify-fedify-*.tgz
203252 cli/fedify-cli-*
204253 generate_release_notes : false
205- - if : |
206- github.event_name == 'push' &&
207- github.ref_type == 'tag' || github.ref == 'refs/heads/main'
208- run: deno task publish --allow-dirty
254+ - run : deno task publish --allow-dirty
209255 working-directory : ${{ github.workspace }}/fedify/
210- - if : |
211- github.event_name == 'push' &&
212- github.ref_type == 'tag' || github.ref == 'refs/heads/main'
213- run: deno task publish --allow-dirty
256+ - run : deno task publish --allow-dirty
214257 working-directory : ${{ github.workspace }}/cli/
215- - if : |
216- github.event_name == 'push' &&
217- github.ref_type == 'tag' || github.ref == 'refs/heads/main'
218- run: |
258+ - run : |
219259 set -ex
220260 npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
221261 if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
222262 npm publish --provenance --access public fedify-fedify-*.tgz
263+ elif [[ "$GITHUB_EVENT_NAME" = "pull_request_target" ]]; then
264+ npm publish \
265+ --provenance \
266+ --access public \
267+ --tag "pr-$PR_NUMBER" \
268+ fedify-fedify-*.tgz
223269 else
224270 npm publish --provenance --access public --tag dev fedify-fedify-*.tgz
225271 fi
226272 env:
227273 NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
274+ PR_NUMBER: ${{ github.event.pull_request.number }}
228275 working-directory: ${{ github.workspace }}/fedify/
229276 - if : github.event_name == 'push' && github.ref_type == 'tag'
230277 run : |
@@ -234,6 +281,20 @@ jobs:
234281 env :
235282 NPM_AUTH_TOKEN : ${{ secrets.NPM_AUTH_TOKEN }}
236283 working-directory : ${{ github.workspace }}/cli/
284+ - if : github.event_name == 'pull_request_target'
285+ uses : thollander/actions-comment-pull-request@v3
286+ with :
287+ message : |
288+ The latest push to this pull request has been published to JSR and npm
289+ as a pre-release:
290+
291+ - [`jsr:@fedify/fedify@${{ steps.versioning.outputs.version }}`][1]
292+ - [`jsr:@fedify/cli@${{ steps.versioning.outputs.version }}`][2]
293+ - [`npm:@fedify/fedify@${{ steps.versioning.outputs.short_version }}`][3]
294+
295+ [1]: https://jsr.io/@fedify/fedify@${{ steps.versioning.outputs.version }}
296+ [2]: https://jsr.io/@fedify/cli@${{ steps.versioning.outputs.version }}
297+ [3]: https://www.npmjs.com/package/@fedify/fedify/v/${{ steps.versioning.outputs.short_version }}
237298
238299 publish-examples-blog :
239300 if : github.event_name == 'push'
@@ -243,7 +304,13 @@ jobs:
243304 id-token : write
244305 contents : read
245306 steps :
246- - uses : actions/checkout@v4
307+ - if : github.event_name == 'push'
308+ uses : actions/checkout@v4
309+ - if : github.event_name == 'pull_request_target'
310+ uses : actions/checkout@v4
311+ with :
312+ repository : ${{ github.event.pull_request.head.repo.full_name }}
313+ ref : ${{ github.event.pull_request.head.ref }}
247314 - uses : denoland/setup-deno@v2
248315 with :
249316 deno-version : v2.x
@@ -267,7 +334,13 @@ jobs:
267334 name : github-pages
268335 url : ${{ steps.deployment.outputs.page_url }}
269336 steps :
270- - uses : actions/checkout@v4
337+ - if : github.event_name == 'push'
338+ uses : actions/checkout@v4
339+ - if : github.event_name == 'pull_request_target'
340+ uses : actions/checkout@v4
341+ with :
342+ repository : ${{ github.event.pull_request.head.repo.full_name }}
343+ ref : ${{ github.event.pull_request.head.ref }}
271344 - uses : pnpm/action-setup@v4
272345 with :
273346 version : 10
@@ -300,17 +373,17 @@ jobs:
300373 - id : deployment
301374 if : github.event_name == 'push' && github.ref_type == 'tag'
302375 uses : actions/deploy-pages@v4
303- - if : github.event_name == 'pull_request ' || github.ref_type == 'branch'
376+ - if : github.event_name == 'pull_request_target ' || github.ref_type == 'branch'
304377 uses : nwtgck/actions-netlify@v3.0
305378 with :
306379 publish-dir : docs/.vitepress/dist
307380 production-branch : main
308381 github-token : ${{ github.token }}
309- enable-pull-request-comment : false
382+ enable-pull-request-comment : true
310383 enable-commit-comment : false
311384 env :
312385 NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
313386 NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
314387 timeout-minutes : 2
315388
316- # cSpell: ignore submark softprops npmjs deployctl nwtgck
389+ # cSpell: ignore submark softprops npmjs deployctl nwtgck thollander elif
0 commit comments