Skip to content

Commit 7b226d2

Browse files
committed
ci(repo): cache snapi baselines and watch @clerk/ui
Publish the API baseline to a GHA cache on push to main and the release branches, keyed by commit sha. PR runs restore from that cache with a prefix-match fallback, and only rebuild the baseline via worktree on a full miss. Add @clerk/ui to the watched package set with a tsc-based build:declarations task matching @clerk/shared's pattern.
1 parent dd6e886 commit 7b226d2

4 files changed

Lines changed: 102 additions & 14 deletions

File tree

.github/workflows/api-changes.yml

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
name: API Changes
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
- release/v4
8+
- release/core-2
9+
paths:
10+
- 'packages/clerk-js/**'
11+
- 'packages/react/**'
12+
- 'packages/shared/**'
13+
- 'packages/ui/**'
14+
- 'snapi.config.json'
15+
- '.github/workflows/api-changes.yml'
416
pull_request:
517
types: [opened, synchronize, reopened, ready_for_review]
618
branches:
@@ -11,6 +23,7 @@ on:
1123
- 'packages/clerk-js/**'
1224
- 'packages/react/**'
1325
- 'packages/shared/**'
26+
- 'packages/ui/**'
1427
- 'snapi.config.json'
1528
- '.github/workflows/api-changes.yml'
1629

@@ -19,11 +32,58 @@ permissions:
1932

2033
concurrency:
2134
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
22-
cancel-in-progress: true
35+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
36+
37+
env:
38+
SNAPI_PACKAGE: github:clerk/snapi#8c021a2796b313cdefa945a715df8f02e4f99867
39+
SNAPI_FILTERS: >-
40+
--filter=@clerk/clerk-js
41+
--filter=@clerk/react
42+
--filter=@clerk/shared
43+
--filter=@clerk/ui
2344
2445
jobs:
46+
publish-baseline:
47+
if: github.event_name == 'push'
48+
name: Publish API Baseline
49+
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
50+
continue-on-error: true
51+
defaults:
52+
run:
53+
shell: bash
54+
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
55+
56+
steps:
57+
- name: Checkout Repo
58+
uses: actions/checkout@v4
59+
with:
60+
filter: 'blob:none'
61+
show-progress: false
62+
63+
- name: Setup
64+
uses: ./.github/actions/init-blacksmith
65+
with:
66+
cache-enabled: true
67+
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
68+
turbo-team: ${{ vars.TURBO_TEAM }}
69+
turbo-token: ${{ secrets.TURBO_TOKEN }}
70+
71+
- name: Build declarations
72+
run: pnpm turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS
73+
74+
- name: Generate API snapshot
75+
run: |
76+
pnpm dlx --package "$SNAPI_PACKAGE" snapi snapshot \
77+
--output "$GITHUB_WORKSPACE/.api-snapshots-baseline"
78+
79+
- name: Save baseline to cache
80+
uses: actions/cache/save@v4
81+
with:
82+
path: .api-snapshots-baseline
83+
key: snapi-baseline-${{ github.sha }}
84+
2585
check-api:
26-
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
86+
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == false }}
2787
name: API Changes
2888
runs-on: 'blacksmith-8vcpu-ubuntu-2204'
2989
continue-on-error: true
@@ -32,13 +92,6 @@ jobs:
3292
shell: bash
3393
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}
3494

35-
env:
36-
SNAPI_PACKAGE: github:clerk/snapi#8c021a2796b313cdefa945a715df8f02e4f99867
37-
SNAPI_FILTERS: >-
38-
--filter=@clerk/clerk-js
39-
--filter=@clerk/react
40-
--filter=@clerk/shared
41-
4295
steps:
4396
- name: Checkout Repo
4497
uses: actions/checkout@v4
@@ -48,34 +101,47 @@ jobs:
48101
filter: 'blob:none'
49102
show-progress: false
50103

51-
- name: Fetch base branch
52-
run: git fetch origin "${GITHUB_BASE_REF}:refs/remotes/origin/${GITHUB_BASE_REF}" --depth=100
53-
54104
- name: Setup
55-
id: config
56105
uses: ./.github/actions/init-blacksmith
57106
with:
58107
cache-enabled: true
59108
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
60109
turbo-team: ${{ vars.TURBO_TEAM }}
61110
turbo-token: ${{ secrets.TURBO_TOKEN }}
62111

112+
- name: Restore baseline from cache
113+
id: baseline-cache
114+
uses: actions/cache/restore@v4
115+
with:
116+
path: .api-snapshots-baseline
117+
key: snapi-baseline-${{ github.event.pull_request.base.sha }}
118+
restore-keys: |
119+
snapi-baseline-
120+
63121
- name: Build current declarations
64122
run: pnpm turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS
65123

124+
- name: Fetch base branch
125+
if: steps.baseline-cache.outputs.cache-matched-key == ''
126+
run: git fetch origin "${GITHUB_BASE_REF}:refs/remotes/origin/${GITHUB_BASE_REF}" --depth=100
127+
66128
- name: Create baseline worktree
129+
if: steps.baseline-cache.outputs.cache-matched-key == ''
67130
run: |
68131
mkdir -p .worktrees
69132
git worktree add .worktrees/snapi-baseline "origin/${GITHUB_BASE_REF}"
70133
cp snapi.config.json .worktrees/snapi-baseline/snapi.config.json
71134
72135
- name: Install baseline dependencies
136+
if: steps.baseline-cache.outputs.cache-matched-key == ''
73137
run: pnpm --dir .worktrees/snapi-baseline install --frozen-lockfile
74138

75139
- name: Build baseline declarations
140+
if: steps.baseline-cache.outputs.cache-matched-key == ''
76141
run: pnpm --dir .worktrees/snapi-baseline turbo build:declarations $TURBO_ARGS $SNAPI_FILTERS
77142

78143
- name: Generate baseline API snapshots
144+
if: steps.baseline-cache.outputs.cache-matched-key == ''
79145
run: |
80146
pnpm --dir .worktrees/snapi-baseline dlx --package "$SNAPI_PACKAGE" snapi snapshot \
81147
--output "$GITHUB_WORKSPACE/.api-snapshots-baseline"

packages/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"scripts": {
7272
"build": "pnpm build:umd && pnpm build:esm && pnpm check:no-rhc && pnpm type-check",
7373
"build:analyze": "rspack build --config rspack.config.js --env production --env analyze --analyze",
74+
"build:declarations": "tsc -p tsconfig.declarations.json",
7475
"build:esm": "tsdown",
7576
"build:rsdoctor": "RSDOCTOR=true rspack build --config rspack.config.js --env production",
7677
"build:umd": "rspack build --config rspack.config.js --env production",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationDir": "./dist",
6+
"declarationMap": true,
7+
"emitDeclarationOnly": true,
8+
"skipLibCheck": true
9+
},
10+
"exclude": [
11+
"node_modules",
12+
"**/*.test.ts",
13+
"**/*.test.tsx",
14+
"**/*.spec.ts",
15+
"**/*.spec.tsx",
16+
"**/__tests__/**",
17+
"**/__mocks__/**",
18+
"**/test/**",
19+
"**/tests/**"
20+
]
21+
}

snapi.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"packages": ["packages/clerk-js", "packages/react", "packages/shared"],
2+
"packages": ["packages/clerk-js", "packages/react", "packages/shared", "packages/ui"],
33
"snapshotDir": ".api-snapshots",
44
"mainBranch": "main",
55
"checkVersionBump": true,

0 commit comments

Comments
 (0)