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
206+ 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
162215 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,27 @@ 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+ pr-number : ${{ github.event.pull_request.number }}
293+ comment-tag : publish
294+ mode : delete
295+ - if : github.event_name == 'pull_request_target'
296+ uses : thollander/actions-comment-pull-request@v3
297+ with :
298+ message : |
299+ The latest push to this pull request has been published to JSR and npm as a pre-release:
300+
301+ - [`jsr:@fedify/fedify@${{ steps.versioning.outputs.version }}`][1]
302+ - [`jsr:@fedify/cli@${{ steps.versioning.outputs.version }}`][2]
303+ - [`npm:@fedify/fedify@${{ steps.versioning.outputs.short_version }}`][3]
304+
305+ [1]: https://jsr.io/@fedify/fedify@${{ steps.versioning.outputs.version }}
306+ [2]: https://jsr.io/@fedify/cli@${{ steps.versioning.outputs.version }}
307+ [3]: https://www.npmjs.com/package/@fedify/fedify/v/${{ steps.versioning.outputs.short_version }}
308+ pr-number : ${{ github.event.pull_request.number }}
309+ comment-tag : publish
237310
238311 publish-examples-blog :
239312 if : github.event_name == 'push'
@@ -243,7 +316,13 @@ jobs:
243316 id-token : write
244317 contents : read
245318 steps :
246- - uses : actions/checkout@v4
319+ - if : github.event_name == 'push'
320+ uses : actions/checkout@v4
321+ - if : github.event_name == 'pull_request_target'
322+ uses : actions/checkout@v4
323+ with :
324+ repository : ${{ github.event.pull_request.head.repo.full_name }}
325+ ref : ${{ github.event.pull_request.head.sha }}
247326 - uses : denoland/setup-deno@v2
248327 with :
249328 deno-version : v2.x
@@ -256,40 +335,47 @@ jobs:
256335 root : .
257336
258337 publish-docs :
259- if : github.event_name == 'push'
260338 needs : [publish]
261339 runs-on : ubuntu-latest
262340 permissions :
263341 id-token : write
264342 pages : write
265343 deployments : write
344+ pull-requests : write
345+ statuses : write
266346 environment :
267347 name : github-pages
268348 url : ${{ steps.deployment.outputs.page_url }}
269349 steps :
270- - uses : actions/checkout@v4
350+ - if : github.event_name == 'push'
351+ uses : actions/checkout@v4
352+ - if : github.event_name == 'pull_request_target'
353+ uses : actions/checkout@v4
354+ with :
355+ repository : ${{ github.event.pull_request.head.repo.full_name }}
356+ ref : ${{ github.event.pull_request.head.sha }}
271357 - uses : pnpm/action-setup@v4
272358 with :
273359 version : 10
274360 - run : |
275361 set -ex
276362 pnpm install
363+ pnpm add -D "@fedify/fedify@$SHORT_VERSION"
277364 if [[ "$GITHUB_EVENT_NAME" = "push" && "$GITHUB_REF_TYPE" = "tag" ]]; then
278- pnpm add -D "@fedify/fedify@$GITHUB_REF_NAME"
279365 EXTRA_NAV_TEXT=Unstable \
280366 EXTRA_NAV_LINK="$UNSTABLE_DOCS_URL" \
281367 SITEMAP_HOSTNAME="$STABLE_DOCS_URL" \
282368 JSR_REF_VERSION=stable \
283369 pnpm run build
284370 else
285- pnpm add -D @fedify/fedify@dev
286371 EXTRA_NAV_TEXT=Stable \
287372 EXTRA_NAV_LINK="$STABLE_DOCS_URL" \
288373 SITEMAP_HOSTNAME="$UNSTABLE_DOCS_URL" \
289374 JSR_REF_VERSION=unstable \
290375 pnpm run build
291376 fi
292377 env:
378+ SHORT_VERSION: ${{ needs.publish.outputs.short_version }}
293379 PLAUSIBLE_DOMAIN: ${{ secrets.PLAUSIBLE_DOMAIN }}
294380 STABLE_DOCS_URL: ${{ vars.STABLE_DOCS_URL }}
295381 UNSTABLE_DOCS_URL: ${{ vars.UNSTABLE_DOCS_URL }}
@@ -300,17 +386,34 @@ jobs:
300386 - id : deployment
301387 if : github.event_name == 'push' && github.ref_type == 'tag'
302388 uses : actions/deploy-pages@v4
303- - if : github.event_name == 'pull_request' || github.ref_type == 'branch'
304- uses : nwtgck/actions-netlify@v3.0
305- with :
306- publish-dir : docs/.vitepress/dist
307- production-branch : main
308- github-token : ${{ github.token }}
309- enable-pull-request-comment : false
310- enable-commit-comment : false
311- env :
312- NETLIFY_AUTH_TOKEN : ${{ secrets.NETLIFY_AUTH_TOKEN }}
313- NETLIFY_SITE_ID : ${{ secrets.NETLIFY_SITE_ID }}
314- timeout-minutes : 2
389+ - if : github.event_name == 'push' && github.ref == 'refs/heads/main'
390+ uses : cloudflare/wrangler-action@v3
391+ with :
392+ apiToken : ${{ secrets.CLOUDFLARE_API_TOKEN }}
393+ accountId : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
394+ gitHubToken : ${{ github.token }}
395+ command : >-
396+ pages deploy docs/.vitepress/dist
397+ --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME }}
398+ - if : github.event_name == 'pull_request_target'
399+ id : wrangler
400+ uses : cloudflare/wrangler-action@v3
401+ with :
402+ apiToken : ${{ secrets.CLOUDFLARE_API_TOKEN }}
403+ accountId : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
404+ gitHubToken : ${{ github.token }}
405+ command : >-
406+ pages deploy docs/.vitepress/dist
407+ --project-name=${{ vars.CLOUDFLARE_PROJECT_NAME }}
408+ --branch=pr-${{ github.event.pull_request.number }}
409+ - if : github.event_name == 'pull_request_target'
410+ uses : thollander/actions-comment-pull-request@v3
411+ with :
412+ message : |
413+ The docs for this pull request have been published:
414+
415+ <${{ steps.wrangler.outputs.deployment-url }}>
416+ pr-number : ${{ github.event.pull_request.number }}
417+ comment-tag : docs
315418
316- # cSpell: ignore submark softprops npmjs deployctl nwtgck
419+ # cSpell: ignore submark softprops npmjs deployctl nwtgck thollander elif
0 commit comments