Skip to content

Commit ca87bba

Browse files
arbrandesclaude
andcommitted
build: publish PR packages as pre-releases when labeled
When a PR has the "package" label, CI will run `npm pack` and upload the tarball as a GitHub pre-release. A separate cleanup workflow deletes the pre-release when the PR is closed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc18e45 commit ca87bba

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- '**'
1010

11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
1115
jobs:
1216
tests:
1317
runs-on: ubuntu-latest
@@ -43,3 +47,40 @@ jobs:
4347
with:
4448
token: ${{ secrets.CODECOV_TOKEN }}
4549
fail_ci_if_error: true
50+
51+
- name: Pack
52+
if: contains(github.event.pull_request.labels.*.name, 'package')
53+
run: npm pack
54+
55+
- name: Upload package to a temporary release
56+
if: contains(github.event.pull_request.labels.*.name, 'package')
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
run: |
60+
TAG="pr-${{ github.event.pull_request.number }}"
61+
gh release delete "$TAG" --yes --cleanup-tag || true
62+
gh release create "$TAG" *.tgz \
63+
--prerelease \
64+
--title "PR #${{ github.event.pull_request.number }}" \
65+
--notes "Test package for PR #${{ github.event.pull_request.number }}"
66+
67+
- name: Update PR description with package link
68+
if: contains(github.event.pull_request.labels.*.name, 'package')
69+
env:
70+
GH_TOKEN: ${{ github.token }}
71+
run: |
72+
TAG="pr-${{ github.event.pull_request.number }}"
73+
ASSET_URL=$(gh release view "$TAG" --json assets --jq '.assets[0].url')
74+
75+
gh pr view "${{ github.event.pull_request.number }}" --json body --jq '.body' > /tmp/pr_body.txt
76+
77+
MARKER_START="<!-- package-link-start -->"
78+
MARKER_END="<!-- package-link-end -->"
79+
80+
if grep -q "$MARKER_START" /tmp/pr_body.txt; then
81+
sed -i "/$MARKER_START/,/$MARKER_END/c\\$MARKER_START\n### Latest PR package\n\n$ASSET_URL\n$MARKER_END" /tmp/pr_body.txt
82+
else
83+
printf '\n%s\n%s\n\n%s\n%s\n' "$MARKER_START" "### Latest PR package" "$ASSET_URL" "$MARKER_END" >> /tmp/pr_body.txt
84+
fi
85+
86+
gh pr edit "${{ github.event.pull_request.number }}" --body-file /tmp/pr_body.txt
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Cleanup PR Package
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
cleanup:
9+
if: contains(github.event.pull_request.labels.*.name, 'package')
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Delete PR release
14+
env:
15+
GH_TOKEN: ${{ github.token }}
16+
run: |
17+
TAG="pr-${{ github.event.pull_request.number }}"
18+
gh release delete "$TAG" --repo "${{ github.repository }}" --yes --cleanup-tag || true

0 commit comments

Comments
 (0)