Skip to content

Commit af5edbf

Browse files
authored
Add Changeset workflow (#1563)
1 parent 7f751b3 commit af5edbf

File tree

6 files changed

+1173
-84
lines changed

6 files changed

+1173
-84
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": []
11+
}

.github/workflows/release.yml

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,86 @@
11
name: Release to npm
22

33
on:
4-
pull_request:
5-
types:
6-
- closed
7-
branches:
8-
- main
4+
# Fire only after the "Tests" workflow completes
5+
workflow_run:
6+
workflows: ["Tests"] # must match your Tests workflow name exactly
7+
types: [completed]
8+
9+
permissions:
10+
contents: read # default for all jobs; least-privileged
11+
12+
concurrency:
13+
group: release-${{ github.workflow }}-${{ github.run_id }}
14+
cancel-in-progress: false
915

1016
jobs:
11-
release:
12-
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
17+
publish:
18+
# Only proceed if:
19+
# - Tests concluded successfully
20+
# - Event was a push (not PR) to main
21+
# - The head repository is THIS repository (not a fork)
22+
if: >
23+
github.event.workflow_run.conclusion == 'success' &&
24+
github.event.workflow_run.event == 'push' &&
25+
github.event.workflow_run.head_branch == 'main' &&
26+
github.event.workflow_run.head_repository.full_name == github.repository
1327
runs-on: ubuntu-latest
1428

29+
# Elevate only this job to get OIDC for npm provenance
30+
permissions:
31+
contents: read
32+
id-token: write
33+
34+
environment:
35+
# Optional: protect with required reviewers (Settings → Environments → npm)
36+
name: npm
37+
1538
steps:
16-
- name: Checkout Repository
39+
# 1) Sparse, read-only checkout of ONLY the files needed for publish.
40+
# No GitHub token persisted; avoids running arbitrary repo scripts.
41+
- name: Checkout (sparse, no creds)
1742
uses: actions/checkout@v4
1843
with:
19-
fetch-depth: 0
44+
ref: ${{ github.event.workflow_run.head_sha }}
45+
fetch-depth: 1
46+
persist-credentials: false
47+
sparse-checkout: |
48+
package.json
49+
README.md
50+
LICENSE
2051
21-
- name: Set up Node.js
22-
uses: actions/setup-node@v4
52+
# 2) Download the dist/ artifact produced by the Tests workflow build.
53+
- name: Download dist artifact
54+
uses: actions/download-artifact@v4
2355
with:
24-
node-version: '20'
25-
registry-url: 'https://registry.npmjs.org/'
56+
name: radui-ui-dist
57+
path: dist
2658

27-
- name: Install Dependencies
28-
run: npm ci
59+
# 3) Hard-disable all npm lifecycle scripts to prevent code execution.
60+
- name: Disable npm scripts
61+
run: |
62+
npm config set ignore-scripts true
63+
echo "npm_config_ignore_scripts=true" >> $GITHUB_ENV
2964
30-
- name: Build Package
31-
run: npm run build:rollup
65+
# 4) Read the version that Changesets bumped.
66+
- name: Read version
67+
id: pkg
68+
run: echo "version=$(node -p \"require('./package.json').version\")" >> $GITHUB_OUTPUT
3269

33-
- name: Get current version
34-
id: package_version
35-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
70+
# 5) Skip if this exact version is already on npm (idempotent reruns).
71+
- name: Check if version exists on npm
72+
id: exists
73+
run: |
74+
if npm view @radui/ui@${{ steps.pkg.outputs.version }} version >/dev/null 2>&1; then
75+
echo "exists=true" >> $GITHUB_OUTPUT
76+
else
77+
echo "exists=false" >> $GITHUB_OUTPUT
78+
fi
3679
80+
# 6) Publish the already-tested artifact with provenance.
81+
# No install, no build, no scripts, minimal trust surface.
3782
- name: Publish to npm
38-
run: npm publish --access public
83+
if: steps.exists.outputs.exists == 'false'
3984
env:
4085
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN_FROM_KOTAPI }}
86+
run: npm publish --access public --provenance

.github/workflows/test.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ concurrency:
4040

4141
jobs:
4242
test:
43-
name: Jest ${{ matrix.shard }}/${{ matrix.total }}
43+
name: Jest (${{ matrix.shard }}/${{ matrix.total }})
4444
runs-on: ubuntu-latest
4545
strategy:
4646
fail-fast: false
@@ -81,3 +81,13 @@ jobs:
8181

8282
- name: Build package
8383
run: npm run build:rollup
84+
85+
# Upload dist only on pushes to main (skip for PRs)
86+
- name: Upload dist artifact
87+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: radui-ui-dist
91+
path: dist
92+
if-no-files-found: error
93+
retention-days: 2

0 commit comments

Comments
 (0)