Skip to content

Commit dcd59fb

Browse files
danbot315Daniel Clayton
andauthored
ci: publish snapshot packages when PR body includes #snapshot (#14)
* ci: add PR #snapshot marker flow to publish tagged snapshot packages * fix: provide GITHUB_TOKEN for snapshot changeset version step * fix: configure npm auth before PR snapshot publish * fix: run #snapshot publish on pull_request_target with package write token * fix: gate snapshot publish on PR marker and harden release auth --------- Co-authored-by: Daniel Clayton <dan@Daniels-Mac-mini.local>
1 parent 296b3c1 commit dcd59fb

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7+
pull_request_target:
8+
types: [opened, edited, synchronize, reopened]
79

810
concurrency:
911
group: ${{ github.workflow }}-${{ github.ref }}
@@ -15,6 +17,7 @@ permissions:
1517
jobs:
1618
quality:
1719
name: Quality checks
20+
if: github.event_name != 'pull_request_target'
1821
runs-on: ubuntu-latest
1922

2023
steps:
@@ -40,3 +43,58 @@ jobs:
4043

4144
- name: Core contract tests
4245
run: bun run test -- packages/core/src/workflow-generator.test.ts packages/core/src/context.test.ts packages/core/src/config.test.ts packages/core/src/plugins/shared-workflow-helper.test.ts
46+
47+
snapshot-publish:
48+
name: Snapshot publish (PR marker)
49+
if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.body || '', '#snapshot') && github.event.pull_request.head.repo.full_name == github.repository
50+
runs-on: ubuntu-latest
51+
permissions:
52+
contents: read
53+
packages: write
54+
55+
steps:
56+
- name: Checkout PR head
57+
uses: actions/checkout@v4
58+
with:
59+
ref: ${{ github.event.pull_request.head.sha }}
60+
61+
- name: Setup Bun
62+
uses: oven-sh/setup-bun@v2
63+
with:
64+
bun-version: 1.2.22
65+
66+
- name: Install dependencies
67+
run: bun install --frozen-lockfile
68+
69+
- name: Build
70+
run: bun run build
71+
72+
- name: Detect pending changesets
73+
id: changesets
74+
run: |
75+
COUNT=$(find .changeset -maxdepth 1 -name '*.md' ! -name 'README.md' | wc -l | tr -d ' ')
76+
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
77+
if [ "$COUNT" -eq 0 ]; then
78+
echo "No pending changesets found. Skipping snapshot publish."
79+
fi
80+
81+
- name: Version snapshot from changesets
82+
if: steps.changesets.outputs.count != '0'
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
run: bunx changeset version --snapshot pr-${{ github.event.pull_request.number }}
86+
87+
- name: Configure npm auth for GitHub Packages
88+
if: steps.changesets.outputs.count != '0'
89+
env:
90+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
run: |
92+
echo "@dotgithub:registry=https://npm.pkg.github.com" >> ~/.npmrc
93+
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
94+
95+
- name: Publish snapshot tag
96+
if: steps.changesets.outputs.count != '0'
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
run: bunx changeset publish --tag pr-${{ github.event.pull_request.number }} --registry https://npm.pkg.github.com

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
4444
- name: Version packages from changesets
4545
if: steps.changesets.outputs.count != '0'
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4648
run: bun run changeset:version
4749

4850
- name: Commit version updates to main
@@ -54,6 +56,14 @@ jobs:
5456
git commit -m "chore(release): version packages [skip ci]" || exit 0
5557
git push
5658
59+
- name: Configure npm auth for GitHub Packages
60+
if: steps.changesets.outputs.count != '0'
61+
env:
62+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
echo "@dotgithub:registry=https://npm.pkg.github.com" >> ~/.npmrc
65+
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
66+
5767
- name: Publish packages
5868
if: steps.changesets.outputs.count != '0'
5969
env:

0 commit comments

Comments
 (0)