Skip to content

Commit f01b80b

Browse files
committed
Add pull request pre-release builds and publishing
Enhance CI workflow to automatically build and publish pre-release versions for pull requests with versioning scheme including PR number, build number, and commit hash. Add automatic PR comments to notify about published pre-releases and update documentation.
1 parent 67c26e1 commit f01b80b

2 files changed

Lines changed: 103 additions & 28 deletions

File tree

.github/workflows/build.yaml

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build
2-
on: [push, pull_request]
2+
on: [push, pull_request_target]
33

44
jobs:
55
test:
@@ -14,7 +14,12 @@ jobs:
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+
ref: ${{ github.event.pull_request.head.ref }}
1823
- uses: denoland/setup-deno@v2
1924
with:
2025
deno-version: v2.x
@@ -54,7 +59,12 @@ jobs:
5459
fail-fast: false
5560
runs-on: ${{ matrix.os }}
5661
steps:
57-
- uses: actions/checkout@v4
62+
- if: github.event_name == 'push'
63+
uses: actions/checkout@v4
64+
- if: github.event_name == 'pull_request_target'
65+
uses: actions/checkout@v4
66+
with:
67+
ref: ${{ github.event.pull_request.head.ref }}
5868
- uses: denoland/setup-deno@v2
5969
with:
6070
deno-version: v2.x
@@ -74,7 +84,12 @@ jobs:
7484
fail-fast: false
7585
runs-on: ${{ matrix.os }}
7686
steps:
77-
- uses: actions/checkout@v4
87+
- if: github.event_name == 'push'
88+
uses: actions/checkout@v4
89+
- if: github.event_name == 'pull_request_target'
90+
uses: actions/checkout@v4
91+
with:
92+
ref: ${{ github.event.pull_request.head.ref }}
7893
- uses: denoland/setup-deno@v2
7994
with:
8095
deno-version: v2.x
@@ -93,7 +108,12 @@ jobs:
93108
lint:
94109
runs-on: ubuntu-latest
95110
steps:
96-
- uses: actions/checkout@v4
111+
- if: github.event_name == 'push'
112+
uses: actions/checkout@v4
113+
- if: github.event_name == 'pull_request_target'
114+
uses: actions/checkout@v4
115+
with:
116+
ref: ${{ github.event.pull_request.head.ref }}
97117
- uses: denoland/setup-deno@v2
98118
with:
99119
deno-version: v2.x
@@ -105,7 +125,12 @@ jobs:
105125
id-token: write
106126
contents: read
107127
steps:
108-
- uses: actions/checkout@v4
128+
- if: github.event_name == 'push'
129+
uses: actions/checkout@v4
130+
- if: github.event_name == 'pull_request_target'
131+
uses: actions/checkout@v4
132+
with:
133+
ref: ${{ github.event.pull_request.head.ref }}
109134
- uses: denoland/setup-deno@v2
110135
with:
111136
deno-version: v2.x
@@ -135,7 +160,12 @@ jobs:
135160
id-token: write
136161
contents: write
137162
steps:
138-
- uses: actions/checkout@v4
163+
- if: github.event_name == 'push'
164+
uses: actions/checkout@v4
165+
- if: github.event_name == 'pull_request_target'
166+
uses: actions/checkout@v4
167+
with:
168+
ref: ${{ github.event.pull_request.head.ref }}
139169
- uses: denoland/setup-deno@v2
140170
with:
141171
deno-version: v2.x
@@ -145,21 +175,34 @@ jobs:
145175
- uses: pnpm/action-setup@v4
146176
with:
147177
version: 10
148-
- if: github.ref_type == 'branch'
178+
- if: github.event_name == 'push' && github.ref_type == 'branch'
149179
run: |
150180
jq \
151181
--arg build "$GITHUB_RUN_NUMBER" \
152182
--arg commit "${GITHUB_SHA::8}" \
153183
'.version = .version + "-dev." + $build + "+" + $commit' \
154184
deno.json > deno.json.tmp
155185
mv deno.json.tmp deno.json
186+
working-directory: ${{ github.workspace }}/fedify/
187+
- if: github.event_name == 'pull_request_target'
188+
run: |
156189
jq \
190+
--arg pr_number "$PR_NUMBER" \
157191
--arg build "$GITHUB_RUN_NUMBER" \
158192
--arg commit "${GITHUB_SHA::8}" \
159-
'.version = .version + "-dev." + $build + "+" + $commit' \
160-
package.json > package.json.tmp
161-
mv package.json.tmp package.json
193+
'.version = .version + "-pr." + $pr_number + "." + $build + "+" + $commit' \
194+
deno.json > deno.json.tmp
195+
mv deno.json.tmp deno.json
162196
working-directory: ${{ github.workspace }}/fedify/
197+
env:
198+
PR_NUMBER: ${{ github.event.pull_request.number }}
199+
- id: versioning
200+
run: |
201+
set -ex
202+
echo version="$(jq -r .version deno.json)" >> $GITHUB_OUTPUT
203+
echo short_version="$(jq -r .version deno.json | sed 's/[+].*//')" >> $GITHUB_OUTPUT
204+
working-directory: ${{ github.workspace }}/fedify/
205+
- run: deno task -r sync-version
163206
- if: github.ref_type == 'tag'
164207
run: |
165208
set -ex
@@ -202,29 +245,27 @@ jobs:
202245
fedify/fedify-fedify-*.tgz
203246
cli/fedify-cli-*
204247
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
248+
- run: deno task publish --allow-dirty
209249
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
250+
- run: deno task publish --allow-dirty
214251
working-directory: ${{ github.workspace }}/cli/
215-
- if: |
216-
github.event_name == 'push' &&
217-
github.ref_type == 'tag' || github.ref == 'refs/heads/main'
218-
run: |
252+
- run: |
219253
set -ex
220254
npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
221255
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
222256
npm publish --provenance --access public fedify-fedify-*.tgz
257+
elif [[ "$GITHUB_EVENT_NAME" = "pull_request_target" ]]; then
258+
npm publish \
259+
--provenance \
260+
--access public \
261+
--tag "pr-$PR_NUMBER" \
262+
fedify-fedify-*.tgz
223263
else
224264
npm publish --provenance --access public --tag dev fedify-fedify-*.tgz
225265
fi
226266
env:
227267
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
268+
PR_NUMBER: ${{ github.event.pull_request.number }}
228269
working-directory: ${{ github.workspace }}/fedify/
229270
- if: github.event_name == 'push' && github.ref_type == 'tag'
230271
run: |
@@ -234,6 +275,20 @@ jobs:
234275
env:
235276
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
236277
working-directory: ${{ github.workspace }}/cli/
278+
- if: github.event_name == 'pull_request_target'
279+
uses: thollander/actions-comment-pull-request@v3
280+
with:
281+
message: |
282+
The latest push to this pull request has been published to JSR and npm
283+
as a pre-release:
284+
285+
- [`jsr:@fedify/fedify@${{ steps.versioning.outputs.version }}`][1]
286+
- [`jsr:@fedify/cli@${{ steps.versioning.outputs.version }}`][2]
287+
- [`npm:@fedify/fedify@${{ steps.versioning.outputs.short_version }}`][3]
288+
289+
[1]: https://jsr.io/@fedify/fedify@${{ steps.versioning.outputs.version }}
290+
[2]: https://jsr.io/@fedify/cli@${{ steps.versioning.outputs.version }}
291+
[3]: https://www.npmjs.com/package/@fedify/fedify/v/${{ steps.versioning.outputs.short_version }}
237292
238293
publish-examples-blog:
239294
if: github.event_name == 'push'
@@ -243,7 +298,12 @@ jobs:
243298
id-token: write
244299
contents: read
245300
steps:
246-
- uses: actions/checkout@v4
301+
- if: github.event_name == 'push'
302+
uses: actions/checkout@v4
303+
- if: github.event_name == 'pull_request_target'
304+
uses: actions/checkout@v4
305+
with:
306+
ref: ${{ github.event.pull_request.head.ref }}
247307
- uses: denoland/setup-deno@v2
248308
with:
249309
deno-version: v2.x
@@ -267,7 +327,12 @@ jobs:
267327
name: github-pages
268328
url: ${{ steps.deployment.outputs.page_url }}
269329
steps:
270-
- uses: actions/checkout@v4
330+
- if: github.event_name == 'push'
331+
uses: actions/checkout@v4
332+
- if: github.event_name == 'pull_request_target'
333+
uses: actions/checkout@v4
334+
with:
335+
ref: ${{ github.event.pull_request.head.ref }}
271336
- uses: pnpm/action-setup@v4
272337
with:
273338
version: 10
@@ -300,17 +365,17 @@ jobs:
300365
- id: deployment
301366
if: github.event_name == 'push' && github.ref_type == 'tag'
302367
uses: actions/deploy-pages@v4
303-
- if: github.event_name == 'pull_request' || github.ref_type == 'branch'
368+
- if: github.event_name == 'pull_request_target' || github.ref_type == 'branch'
304369
uses: nwtgck/actions-netlify@v3.0
305370
with:
306371
publish-dir: docs/.vitepress/dist
307372
production-branch: main
308373
github-token: ${{ github.token }}
309-
enable-pull-request-comment: false
374+
enable-pull-request-comment: true
310375
enable-commit-comment: false
311376
env:
312377
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
313378
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
314379
timeout-minutes: 2
315380

316-
# cSpell: ignore submark softprops npmjs deployctl nwtgck
381+
# cSpell: ignore submark softprops npmjs deployctl nwtgck thollander elif

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ A patch set should include the following:
131131

132132
Feature pull requests should target the *main* branch.
133133

134+
### Pull request builds
135+
136+
Each pull request is automatically built and published to the JSR and npm
137+
registries as a pre-release. You can test the pull request by installing
138+
the pre-release version of the Fedify library. The version number of
139+
the pre-release version consists of the base version number, the pull request
140+
number, the build number, and the commit hash, which looks like
141+
`1.2.3-pr.456.789+abcdef01`. You can find the exact version number in
142+
the comment left by the build process in the pull request.
143+
134144

135145
Build
136146
-----

0 commit comments

Comments
 (0)