Skip to content

Commit db5f11f

Browse files
rsslldnphyclaude
andcommitted
Add GitHub Action workflow for preview package publishing
Automatically publishes every commit to GitHub Packages with a version like 0.0.0-branch.sha, tagged as 'preview'. Keeps the 50 most recent preview versions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a4274cd commit db5f11f

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Publish Preview Packages
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- "dependabot/**"
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: ./.github/actions/ci-setup
19+
20+
- name: Configure npm for GitHub Packages
21+
run: |
22+
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc
23+
24+
- name: Build package
25+
run: pnpm build
26+
27+
- name: Generate version string
28+
id: version
29+
run: |
30+
BRANCH="${GITHUB_REF_NAME}"
31+
# Sanitize branch name for npm (replace invalid chars with -)
32+
BRANCH_SAFE=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
33+
SHORT_SHA="${GITHUB_SHA::7}"
34+
VERSION="0.0.0-${BRANCH_SAFE}.${SHORT_SHA}"
35+
echo "version=$VERSION" >> $GITHUB_OUTPUT
36+
echo "Publishing version: $VERSION"
37+
38+
- name: Update package version
39+
run: pnpm version ${{ steps.version.outputs.version }} --no-git-tag-version
40+
41+
- name: Publish package
42+
run: pnpm publish --access public --tag preview --no-git-checks
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Summary
47+
run: |
48+
echo "## Published Package" >> $GITHUB_STEP_SUMMARY
49+
echo "" >> $GITHUB_STEP_SUMMARY
50+
echo "Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
51+
echo "" >> $GITHUB_STEP_SUMMARY
52+
echo "Install with:" >> $GITHUB_STEP_SUMMARY
53+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
54+
echo "pnpm add @casekit/unindent@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
55+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
56+
57+
cleanup:
58+
runs-on: ubuntu-latest
59+
needs: publish
60+
permissions:
61+
packages: write
62+
63+
steps:
64+
- name: Delete old preview versions
65+
uses: actions/delete-package-versions@v5
66+
with:
67+
package-name: unindent
68+
package-type: npm
69+
min-versions-to-keep: 50
70+
delete-only-pre-release-versions: true
71+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)