Skip to content

Commit c0aeaae

Browse files
feat: add PR tarball workflow with direct download link (#576)
* feat: add PR tarball workflow with direct download link On every PR, the build workflow now also runs `npm pack` and uploads the resulting tarball as a GitHub Release asset. A sticky comment is posted on the PR with a direct download link and a one-liner npm install command. The temporary release is automatically cleaned up when the PR is closed or merged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove cleanup job to preserve tarballs for old PRs Removes the cleanup-pr-tarball job so tarball releases persist after PR close. This allows testing packages from old/closed PRs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: upgrade sticky-pull-request-comment to v3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add scheduled cleanup for old PR tarball releases Runs daily at midnight UTC. Deletes PR tarball releases (and their tags) older than 7 days. Can also be triggered manually. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 41570f0 commit c0aeaae

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ jobs:
4747
with:
4848
name: coverage-report
4949
path: coverage/
50+
- name: Pack tarball
51+
if: matrix.node-version == '20.x'
52+
run: npm pack
53+
- name: Upload tarball artifact
54+
if: matrix.node-version == '20.x'
55+
uses: actions/upload-artifact@v7
56+
with:
57+
name: tarball
58+
path: '*.tgz'
5059

5160
coverage:
5261
needs: build
@@ -71,3 +80,60 @@ jobs:
7180
vite-config-path: vitest.unit.config.ts
7281
file-coverage-mode: none
7382
coverage-thresholds: '{ "lines": 50, "branches": 50, "functions": 50, "statements": 50 }'
83+
84+
pr-tarball:
85+
needs: build
86+
runs-on: ubuntu-latest
87+
if: github.event_name == 'pull_request'
88+
permissions:
89+
contents: write
90+
pull-requests: write
91+
92+
steps:
93+
- uses: actions/checkout@v6
94+
- name: Download tarball artifact
95+
uses: actions/download-artifact@v8
96+
with:
97+
name: tarball
98+
path: tarball/
99+
- name: Get tarball info
100+
id: tarball
101+
run: |
102+
TARBALL_NAME=$(ls tarball/*.tgz | head -1 | xargs basename)
103+
echo "name=$TARBALL_NAME" >> $GITHUB_OUTPUT
104+
- name: Create or update PR release
105+
id: release
106+
env:
107+
GH_TOKEN: ${{ github.token }}
108+
PR_NUMBER: ${{ github.event.pull_request.number }}
109+
TARBALL_NAME: ${{ steps.tarball.outputs.name }}
110+
run: |
111+
TAG="pr-${PR_NUMBER}-tarball"
112+
113+
# Delete existing release if it exists (to update the tarball)
114+
gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true
115+
116+
# Create a new pre-release with the tarball
117+
gh release create "$TAG" \
118+
"tarball/${TARBALL_NAME}" \
119+
--title "PR #${PR_NUMBER} Tarball" \
120+
--notes "Auto-generated tarball for PR #${PR_NUMBER}." \
121+
--prerelease \
122+
--target "${{ github.event.pull_request.head.sha }}"
123+
124+
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${TARBALL_NAME}"
125+
echo "url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
126+
- name: Comment on PR
127+
uses: marocchino/sticky-pull-request-comment@v3
128+
with:
129+
header: tarball
130+
message: |
131+
## Package Tarball
132+
133+
**[${{ steps.tarball.outputs.name }}](${{ steps.release.outputs.url }})**
134+
135+
### How to install
136+
137+
```bash
138+
npm install ${{ steps.release.outputs.url }}
139+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Cleanup PR Tarballs
2+
3+
on:
4+
schedule:
5+
# Run daily at midnight UTC
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
cleanup:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v6
18+
- name: Delete PR tarball releases older than 7 days
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
run: |
22+
CUTOFF=$(date -u -d '7 days ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -v-7d +%Y-%m-%dT%H:%M:%SZ)
23+
24+
gh release list --limit 100 --json tagName,createdAt,isPrerelease \
25+
--jq '.[] | select(.isPrerelease and (.tagName | startswith("pr-")) and (.tagName | endswith("-tarball")))' \
26+
| jq -r --arg cutoff "$CUTOFF" 'select(.createdAt < $cutoff) | .tagName' \
27+
| while read -r TAG; do
28+
echo "Deleting old tarball release: $TAG"
29+
gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true
30+
done

0 commit comments

Comments
 (0)