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.sha }}
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.sha }}
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.sha }}
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.sha }}
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.sha }}
109139 - uses : denoland/setup-deno@v2
110140 with :
111141 deno-version : v2.x
@@ -134,8 +164,18 @@ jobs:
134164 permissions :
135165 id-token : write
136166 contents : write
167+ pull-requests : write
168+ outputs :
169+ version : ${{ steps.versioning.outputs.version }}
170+ short_version : ${{ steps.versioning.outputs.short_version }}
137171 steps :
138- - uses : actions/checkout@v4
172+ - if : github.event_name == 'push'
173+ uses : actions/checkout@v4
174+ - if : github.event_name == 'pull_request_target'
175+ uses : actions/checkout@v4
176+ with :
177+ repository : ${{ github.event.pull_request.head.repo.full_name }}
178+ ref : ${{ github.event.pull_request.head.sha }}
139179 - uses : denoland/setup-deno@v2
140180 with :
141181 deno-version : v2.x
@@ -145,21 +185,35 @@ jobs:
145185 - uses : pnpm/action-setup@v4
146186 with :
147187 version : 10
148- - if : github.ref_type == 'branch'
188+ - if : github.event_name == 'push' && github. ref_type == 'branch'
149189 run : |
150190 jq \
151191 --arg build "$GITHUB_RUN_NUMBER" \
152192 --arg commit "${GITHUB_SHA::8}" \
153193 '.version = .version + "-dev." + $build + "+" + $commit' \
154194 deno.json > deno.json.tmp
155195 mv deno.json.tmp deno.json
196+ working-directory : ${{ github.workspace }}/fedify/
197+ - if : github.event_name == 'pull_request_target'
198+ run : |
156199 jq \
200+ --arg pr_number "$PR_NUMBER" \
157201 --arg build "$GITHUB_RUN_NUMBER" \
158- --arg commit "${GITHUB_SHA ::8}" \
159- '.version = .version + "-dev ." + $build + "+" + $commit' \
160- package .json > package .json.tmp
161- mv package .json.tmp package .json
202+ --arg commit "${PR_SHA ::8}" \
203+ '.version = .version + "-pr." + $pr_number + " ." + $build + "+" + $commit' \
204+ deno .json > deno .json.tmp
205+ mv deno .json.tmp deno .json
162206 working-directory : ${{ github.workspace }}/fedify/
207+ env :
208+ PR_NUMBER : ${{ github.event.pull_request.number }}
209+ PR_SHA : ${{ github.event.pull_request.head.sha }}
210+ - id : versioning
211+ run : |
212+ set -ex
213+ echo version="$(jq -r .version deno.json)" >> $GITHUB_OUTPUT
214+ echo short_version="$(jq -r .version deno.json | sed 's/[+].*//')" >> $GITHUB_OUTPUT
215+ working-directory : ${{ github.workspace }}/fedify/
216+ - run : deno task -r sync-version
163217 - if : github.ref_type == 'tag'
164218 run : |
165219 set -ex
@@ -202,29 +256,27 @@ jobs:
202256 fedify/fedify-fedify-*.tgz
203257 cli/fedify-cli-*
204258 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
259+ - run : deno task publish --allow-dirty
209260 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
261+ - run : deno task publish --allow-dirty
214262 working-directory : ${{ github.workspace }}/cli/
215- - if : |
216- github.event_name == 'push' &&
217- github.ref_type == 'tag' || github.ref == 'refs/heads/main'
218- run: |
263+ - run : |
219264 set -ex
220265 npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
221266 if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
222267 npm publish --provenance --access public fedify-fedify-*.tgz
268+ elif [[ "$GITHUB_EVENT_NAME" = "pull_request_target" ]]; then
269+ npm publish \
270+ --provenance \
271+ --access public \
272+ --tag "pr-$PR_NUMBER" \
273+ fedify-fedify-*.tgz
223274 else
224275 npm publish --provenance --access public --tag dev fedify-fedify-*.tgz
225276 fi
226277 env:
227278 NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
279+ PR_NUMBER: ${{ github.event.pull_request.number }}
228280 working-directory: ${{ github.workspace }}/fedify/
229281 - if : github.event_name == 'push' && github.ref_type == 'tag'
230282 run : |
@@ -234,6 +286,20 @@ jobs:
234286 env :
235287 NPM_AUTH_TOKEN : ${{ secrets.NPM_AUTH_TOKEN }}
236288 working-directory : ${{ github.workspace }}/cli/
289+ - if : github.event_name == 'pull_request_target'
290+ uses : thollander/actions-comment-pull-request@v3
291+ with :
292+ message : |
293+ The latest push to this pull request has been published to JSR and npm as a pre-release:
294+
295+ - [`jsr:@fedify/fedify@${{ steps.versioning.outputs.version }}`][1]
296+ - [`jsr:@fedify/cli@${{ steps.versioning.outputs.version }}`][2]
297+ - [`npm:@fedify/fedify@${{ steps.versioning.outputs.short_version }}`][3]
298+
299+ [1]: https://jsr.io/@fedify/fedify@${{ steps.versioning.outputs.version }}
300+ [2]: https://jsr.io/@fedify/cli@${{ steps.versioning.outputs.version }}
301+ [3]: https://www.npmjs.com/package/@fedify/fedify/v/${{ steps.versioning.outputs.short_version }}
302+ pr-number : ${{ github.event.pull_request.number }}
237303
238304 publish-examples-blog :
239305 if : github.event_name == 'push'
@@ -243,7 +309,13 @@ jobs:
243309 id-token : write
244310 contents : read
245311 steps :
246- - uses : actions/checkout@v4
312+ - if : github.event_name == 'push'
313+ uses : actions/checkout@v4
314+ - if : github.event_name == 'pull_request_target'
315+ uses : actions/checkout@v4
316+ with :
317+ repository : ${{ github.event.pull_request.head.repo.full_name }}
318+ ref : ${{ github.event.pull_request.head.sha }}
247319 - uses : denoland/setup-deno@v2
248320 with :
249321 deno-version : v2.x
@@ -256,7 +328,6 @@ jobs:
256328 root : .
257329
258330 publish-docs :
259- if : github.event_name == 'push'
260331 needs : [publish]
261332 runs-on : ubuntu-latest
262333 permissions :
@@ -267,29 +338,35 @@ jobs:
267338 name : github-pages
268339 url : ${{ steps.deployment.outputs.page_url }}
269340 steps :
270- - uses : actions/checkout@v4
341+ - if : github.event_name == 'push'
342+ uses : actions/checkout@v4
343+ - if : github.event_name == 'pull_request_target'
344+ uses : actions/checkout@v4
345+ with :
346+ repository : ${{ github.event.pull_request.head.repo.full_name }}
347+ ref : ${{ github.event.pull_request.head.sha }}
271348 - uses : pnpm/action-setup@v4
272349 with :
273350 version : 10
274351 - run : |
275352 set -ex
276353 pnpm install
354+ pnpm add -D "@fedify/fedify@$SHORT_VERSION"
277355 if [[ "$GITHUB_EVENT_NAME" = "push" && "$GITHUB_REF_TYPE" = "tag" ]]; then
278- pnpm add -D "@fedify/fedify@$GITHUB_REF_NAME"
279356 EXTRA_NAV_TEXT=Unstable \
280357 EXTRA_NAV_LINK="$UNSTABLE_DOCS_URL" \
281358 SITEMAP_HOSTNAME="$STABLE_DOCS_URL" \
282359 JSR_REF_VERSION=stable \
283360 pnpm run build
284361 else
285- pnpm add -D @fedify/fedify@dev
286362 EXTRA_NAV_TEXT=Stable \
287363 EXTRA_NAV_LINK="$STABLE_DOCS_URL" \
288364 SITEMAP_HOSTNAME="$UNSTABLE_DOCS_URL" \
289365 JSR_REF_VERSION=unstable \
290366 pnpm run build
291367 fi
292368 env:
369+ SHORT_VERSION: ${{ needs.publish.outputs.short_version }}
293370 PLAUSIBLE_DOMAIN: ${{ secrets.PLAUSIBLE_DOMAIN }}
294371 STABLE_DOCS_URL: ${{ vars.STABLE_DOCS_URL }}
295372 UNSTABLE_DOCS_URL: ${{ vars.UNSTABLE_DOCS_URL }}
@@ -300,17 +377,17 @@ jobs:
300377 - id : deployment
301378 if : github.event_name == 'push' && github.ref_type == 'tag'
302379 uses : actions/deploy-pages@v4
303- - if : github.event_name == 'pull_request ' || github.ref_type == 'branch'
380+ - if : github.event_name == 'pull_request_target ' || github.ref_type == 'branch'
304381 uses : nwtgck/actions-netlify@v3.0
305382 with :
306383 publish-dir : docs/.vitepress/dist
307384 production-branch : main
308385 github-token : ${{ github.token }}
309- enable-pull-request-comment : false
386+ enable-pull-request-comment : true
310387 enable-commit-comment : false
311388 env :
312389 NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
313390 NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
314391 timeout-minutes : 2
315392
316- # cSpell: ignore submark softprops npmjs deployctl nwtgck
393+ # cSpell: ignore submark softprops npmjs deployctl nwtgck thollander elif
0 commit comments