Skip to content

Commit 517939b

Browse files
arbrandesclaude
andcommitted
feat: add workflows to publish PR packages for testing
When a PR is labeled "package-pr", the CI workflow uploads the npm pack tarball as an artifact. A separate workflow_run-triggered workflow then attaches it to a GitHub release tagged pr-<number> and updates the PR description with the download link. A cleanup workflow deletes the release when the PR is closed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7e13eb9 commit 517939b

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,14 @@ jobs:
3333
run: npm run test
3434
- name: Build Test Site
3535
run: cd test-site; npm run build
36+
- name: Save PR metadata
37+
if: contains(github.event.pull_request.labels.*.name, 'package-pr')
38+
run: echo "${{ github.event.pull_request.number }}" > pack/pr-number.txt
39+
- name: Upload package artifact
40+
if: contains(github.event.pull_request.labels.*.name, 'package-pr')
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: npm-package
44+
path: |
45+
pack/*.tgz
46+
pack/pr-number.txt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Package PR Cleanup
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup:
12+
if: contains(github.event.pull_request.labels.*.name, 'package-pr')
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Delete PR release
17+
env:
18+
GH_TOKEN: ${{ github.token }}
19+
run: |
20+
TAG="pr-${{ github.event.pull_request.number }}"
21+
gh release delete "$TAG" --repo "${{ github.repository }}" --yes --cleanup-tag || true

.github/workflows/package-pr.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Package PR
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Default CI"]
6+
types: [completed]
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
actions: read
12+
13+
jobs:
14+
package:
15+
if: >-
16+
github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion == 'success' &&
18+
!startsWith(github.event.workflow_run.head_branch, 'renovate/')
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Download artifact
23+
uses: actions/download-artifact@v4
24+
with:
25+
name: npm-package
26+
run-id: ${{ github.event.workflow_run.id }}
27+
github-token: ${{ github.token }}
28+
29+
- name: Read PR number
30+
id: pr
31+
run: echo "number=$(cat pr-number.txt)" >> "$GITHUB_OUTPUT"
32+
33+
- name: Upload package to a temporary release
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
TAG="pr-${{ steps.pr.outputs.number }}"
38+
gh release delete "$TAG" --repo "${{ github.repository }}" --yes --cleanup-tag || true
39+
gh release create "$TAG" *.tgz \
40+
--repo "${{ github.repository }}" \
41+
--target "${{ github.event.workflow_run.head_sha }}" \
42+
--prerelease \
43+
--title "PR #${{ steps.pr.outputs.number }}" \
44+
--notes "Test package for PR #${{ steps.pr.outputs.number }}"
45+
46+
- name: Update PR description with package link
47+
env:
48+
GH_TOKEN: ${{ github.token }}
49+
run: |
50+
TAG="pr-${{ steps.pr.outputs.number }}"
51+
ASSET_URL=$(gh release view "$TAG" --repo "${{ github.repository }}" --json assets --jq '.assets[0].url')
52+
BODY=$(gh pr view "${{ steps.pr.outputs.number }}" --repo "${{ github.repository }}" --json body --jq '.body // ""')
53+
MARKER_START="<!-- package-link-start -->"
54+
MARKER_END="<!-- package-link-end -->"
55+
PACKAGE_BLOCK="${MARKER_START}
56+
### Latest PR package
57+
58+
${ASSET_URL}
59+
${MARKER_END}"
60+
61+
if echo "$BODY" | grep -q "$MARKER_START"; then
62+
BODY=$(echo "$BODY" | awk -v start="$MARKER_START" -v block="$PACKAGE_BLOCK" '
63+
$0 ~ start { print block; skip=1; next }
64+
skip && /<!-- package-link-end -->/ { skip=0; next }
65+
!skip { print }
66+
')
67+
else
68+
BODY="${BODY}
69+
70+
${PACKAGE_BLOCK}"
71+
fi
72+
73+
echo "$BODY" > /tmp/pr_body.txt
74+
gh pr edit "${{ steps.pr.outputs.number }}" --repo "${{ github.repository }}" --body-file /tmp/pr_body.txt

0 commit comments

Comments
 (0)