Skip to content

Commit 930d919

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 930d919

2 files changed

Lines changed: 47 additions & 16 deletions

File tree

.github/workflows/build.yaml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,34 @@ jobs:
145145
- uses: pnpm/action-setup@v4
146146
with:
147147
version: 10
148-
- if: github.ref_type == 'branch'
148+
- if: github.event_name == 'push' && github.ref_type == 'branch'
149149
run: |
150150
jq \
151151
--arg build "$GITHUB_RUN_NUMBER" \
152152
--arg commit "${GITHUB_SHA::8}" \
153153
'.version = .version + "-dev." + $build + "+" + $commit' \
154154
deno.json > deno.json.tmp
155155
mv deno.json.tmp deno.json
156+
working-directory: ${{ github.workspace }}/fedify/
157+
- if: github.event_name == 'pull_request'
158+
run: |
156159
jq \
160+
--arg pr_number "$PR_NUMBER" \
157161
--arg build "$GITHUB_RUN_NUMBER" \
158162
--arg commit "${GITHUB_SHA::8}" \
159-
'.version = .version + "-dev." + $build + "+" + $commit' \
160-
package.json > package.json.tmp
161-
mv package.json.tmp package.json
163+
'.version = .version + "-pr." + $pr_number + "." + $build + "+" + $commit' \
164+
deno.json > deno.json.tmp
165+
mv deno.json.tmp deno.json
162166
working-directory: ${{ github.workspace }}/fedify/
167+
env:
168+
PR_NUMBER: ${{ github.event.pull_request.number }}
169+
- id: versioning
170+
run: |
171+
set -ex
172+
echo version="$(jq -r .version deno.json)" >> $GITHUB_OUTPUT
173+
echo short_version="$(jq -r .version deno.json | sed 's/[+].*//')" >> $GITHUB_OUTPUT
174+
working-directory: ${{ github.workspace }}/fedify/
175+
- run: deno task -r sync-version
163176
- if: github.ref_type == 'tag'
164177
run: |
165178
set -ex
@@ -202,29 +215,27 @@ jobs:
202215
fedify/fedify-fedify-*.tgz
203216
cli/fedify-cli-*
204217
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
218+
- run: deno task publish --allow-dirty
209219
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
220+
- run: deno task publish --allow-dirty
214221
working-directory: ${{ github.workspace }}/cli/
215-
- if: |
216-
github.event_name == 'push' &&
217-
github.ref_type == 'tag' || github.ref == 'refs/heads/main'
218-
run: |
222+
- run: |
219223
set -ex
220224
npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
221225
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
222226
npm publish --provenance --access public fedify-fedify-*.tgz
227+
elif [[ "$GITHUB_EVENT_NAME" = "pull_request" ]]; then
228+
npm publish \
229+
--provenance \
230+
--access public \
231+
--tag "pr-$PR_NUMBER" \
232+
fedify-fedify-*.tgz
223233
else
224234
npm publish --provenance --access public --tag dev fedify-fedify-*.tgz
225235
fi
226236
env:
227237
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
238+
PR_NUMBER: ${{ github.event.pull_request.number }}
228239
working-directory: ${{ github.workspace }}/fedify/
229240
- if: github.event_name == 'push' && github.ref_type == 'tag'
230241
run: |
@@ -234,6 +245,16 @@ jobs:
234245
env:
235246
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
236247
working-directory: ${{ github.workspace }}/cli/
248+
- if: github.event_name == 'pull_request'
249+
uses: thollander/actions-comment-pull-request@v3
250+
with:
251+
message: |
252+
The latest push to this pull request has been published to JSR and npm
253+
as a pre-release:
254+
255+
- [`jsr:@fedify/fedify@${{ steps.versioning.outputs.version }}`](https://jsr.io/@fedify/fedify@${{ steps.versioning.outputs.version }})
256+
- [`jsr:@fedify/cli@${{ steps.versioning.outputs.version }}`](https://jsr.io/@fedify/cli@${{ steps.versioning.outputs.version }})
257+
- [`npm:@fedify/fedify@${{ steps.versioning.outputs.short_version }}`](https://www.npmjs.com/package/@fedify/fedify/v/${{ steps.versioning.outputs.short_version }})
237258
238259
publish-examples-blog:
239260
if: github.event_name == 'push'

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)