Skip to content

Commit 784fea4

Browse files
committed
chore: try-nix-caching
1 parent 6eb6d0f commit 784fea4

File tree

3 files changed

+161
-111
lines changed

3 files changed

+161
-111
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ on:
44

55
env:
66
NX_CLOUD_ENCRYPTION_KEY: ${{ secrets.NX_CLOUD_ENCRYPTION_KEY }}
7-
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.PR_NX_CLOUD_ACCESS_TOKEN }} # Read Only
7+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.PR_NX_CLOUD_ACCESS_TOKEN }} # Read/Write in CI
88
NX_CLOUD_DISTRIBUTED_EXECUTION: true
99
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
1010
CI: true
1111

12-
# recommended to set a concurrency group
1312
concurrency:
1413
group: preview-pages-${{ github.ref }}
1514
cancel-in-progress: true
@@ -22,49 +21,53 @@ jobs:
2221
pull-requests: write
2322
contents: write
2423
id-token: write
24+
2525
steps:
2626
- uses: actions/checkout@v4
2727
with:
2828
fetch-depth: 0
29+
30+
# ----- Nix + Cachix (used to hydrate pnpm store) -----
2931
- name: Install Nix
3032
uses: DeterminateSystems/nix-installer-action@v10
3133

32-
- name: Configure Nix Cache
34+
- name: Configure Nix Cache (Cachix)
3335
uses: cachix/cachix-action@v14
3436
with:
35-
# TODO: Create a cache on cachix.org for your project and add the name here
3637
name: ping-javascript-sdk
37-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
3838

39-
- name: Install Dependencies
40-
run: nix develop --command bash -c 'pnpm install --frozen-lockfile'
39+
# Build the pnpm store from pnpm-lock.yaml (pushes/substitutes via Cachix)
40+
- name: Build pnpm store (from lockfile)
41+
id: pnpmstore
42+
run: |
43+
set -euo pipefail
44+
OUT="$(nix build --print-out-paths .#pnpmStore)"
45+
echo "PNPM_STORE_PATH_NIX=$OUT" >> "$GITHUB_ENV"
46+
echo "out=$OUT" >> "$GITHUB_OUTPUT"
47+
48+
# Install deps offline using the hydrated store
49+
- name: Install Dependencies (offline via pnpm store)
50+
run: nix develop --command bash -lc 'export PNPM_STORE_PATH="$PNPM_STORE_PATH_NIX"; pnpm install --frozen-lockfile --offline'
51+
52+
# ----- Playwright via Nix (no network install, cached by binary cache) -----
53+
- name: Use Playwright browsers from Nix
54+
run: |
55+
echo "PLAYWRIGHT_BROWSERS_PATH=$(nix build --no-link --print-out-paths nixpkgs#playwright-driver.browsers)/share/playwright" >> $GITHUB_ENV
56+
echo "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1" >> $GITHUB_ENV
4157
42-
# This line enables distribution
43-
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
58+
# ----- Nx Cloud (DTE) — unchanged -----
4459
- name: Start Nx Cloud CI Run
4560
run: nix develop --command bash -c 'pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN"'
4661

4762
- name: Check Sync
4863
run: nix develop --command bash -c 'pnpm nx sync:check'
4964

50-
- name: Cache Playwright browsers
51-
uses: actions/cache@v4
52-
with:
53-
path: ~/.cache/ms-playwright
54-
key: ${{ runner.os }}-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
55-
restore-keys: |
56-
${{ runner.os }}-playwright-
57-
58-
- name: Install Playwright Browsers
59-
run: nix develop --command bash -c 'pnpm exec playwright install'
60-
6165
- uses: nrwl/nx-set-shas@v4
62-
# This line is needed for nx affected to work when CI is running on a PR
63-
- run: git branch --track main origin/main
66+
- run: git branch --track main origin/main || git branch -f main origin/main
6467

6568
- name: Run Core Nx Commands
6669
run: |
67-
nix develop --command bash -c '
70+
nix develop --command bash -lc '
6871
pnpm exec nx-cloud record -- nx format:check
6972
pnpm exec nx affected -t build typecheck lint test e2e-ci
7073
'
@@ -91,7 +94,7 @@ jobs:
9194
run: nix develop --command bash -c 'NX_CLOUD_DISTRIBUTED_EXECUTION=false pnpm nx run-many -t build'
9295

9396
- name: Preview Publish
94-
run: nix develop --command bash -c 'pnpm pkg-pr-new publish './packages/*' './packages/sdk-effects/*' --packageManager=pnpm'
97+
run: nix develop --command bash -c 'pnpm pkg-pr-new publish "./packages/*" "./packages/sdk-effects/*" --packageManager=pnpm'
9598

9699
- name: build docs
97100
run: nix develop --command bash -c 'pnpm generate-docs'
@@ -120,18 +123,14 @@ jobs:
120123
- name: Calculate bundle sizes
121124
id: bundle-analysis
122125
run: |
123-
nix develop --command bash -c '
124-
# Make script executable
126+
nix develop --command bash -lc '
125127
chmod +x ./scripts/bundle-sizes.sh
126-
# Check if baseline exists
127128
if [ -f "previous_sizes.json" ]; then
128129
echo "✅ Using baseline size data from main branch"
129-
echo "Baseline data preview:"
130-
cat previous_sizes.json | head -5
130+
head -5 previous_sizes.json || true
131131
else
132132
echo "⚠️ No baseline size data found - this will be the first measurement"
133133
fi
134-
# Run the bundle size calculation
135134
./scripts/bundle-sizes.sh
136135
'
137136
@@ -177,7 +176,6 @@ jobs:
177176
- **Baseline**: Comparison against the latest build from the `main` branch
178177
- **Files included**: All build outputs except source maps and TypeScript build cache
179178
- **Exclusions**: `.map`, `.tsbuildinfo`, and `.d.ts.map` files
180-
181179
</details>
182180
183181
---

.github/workflows/publish.yml

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,22 @@ jobs:
4747
with:
4848
fetch-depth: 0
4949
token: ${{ secrets.GH_TOKEN }}
50-
- name: Install Nix
51-
uses: DeterminateSystems/nix-installer-action@v10
50+
- uses: pnpm/action-setup@v4
51+
with:
52+
run_install: false
53+
- uses: actions/setup-node@v4
54+
id: cache
55+
with:
56+
node-version-file: '.node-version'
57+
cache: 'pnpm'
58+
registry-url: 'https://registry.npmjs.org'
5259

53-
- name: Install Dependencies
54-
run: |
55-
nix develop --command bash -c '
56-
npm install -g npm@latest
57-
pnpm install --frozen-lockfile
58-
'
60+
- name: Update npm
61+
run: npm install -g npm@latest
62+
63+
- run: pnpm install --frozen-lockfile
5964

60-
- name: Start Nx Cloud CI Run
61-
run: nix develop --command bash -c 'NX_CLOUD_DISTRIBUTED_EXECUTION=false pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN"'
65+
- run: pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN"
6266

6367
- name: Cache Playwright browsers
6468
uses: actions/cache@v4
@@ -68,13 +72,14 @@ jobs:
6872
restore-keys: |
6973
${{ runner.os }}-playwright-
7074
71-
- name: Install Browsers, Configure Pnpm, and Run Nx Affected
72-
run: |
73-
nix develop --command bash -c '
74-
pnpm exec playwright install
75-
pnpm config set store-dir $PNPM_CACHE_FOLDER
76-
pnpm exec nx affected -t build lint test e2e-ci
77-
'
75+
- run: pnpm exec playwright install
76+
77+
- uses: nrwl/nx-set-shas@v4
78+
79+
- name: setup pnpm config
80+
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
81+
82+
- run: pnpm exec nx affected -t build lint test e2e-ci
7883

7984
- uses: actions/upload-artifact@v4
8085
if: ${{ !cancelled() }}
@@ -89,8 +94,8 @@ jobs:
8994
uses: changesets/action@v1
9095
id: changesets
9196
with:
92-
publish: nix develop --command bash -c 'pnpm ci:release'
93-
version: nix develop --command bash -c 'pnpm ci:version'
97+
publish: pnpm ci:release
98+
version: pnpm ci:version
9499
title: Release PR
95100
branch: main
96101
commit: 'chore: version-packages'
@@ -99,6 +104,9 @@ jobs:
99104
HOME: ${{ github.workspace }}
100105
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
101106

107+
- run: pnpm pkg-pr-new publish './packages/*' './packages/sdk-effects/*' --packageManager=pnpm --comment=off
108+
if: steps.changesets.outputs.published == 'false'
109+
102110
- name: Send GitHub Action data to a Slack workflow
103111
if: steps.changesets.outputs.published == 'true'
104112
uses: slackapi/[email protected]
@@ -108,21 +116,18 @@ jobs:
108116
webhook-type: webhook-trigger
109117
payload: steps.changesets.outputs.publishedPackages
110118

111-
- name: Preview Publish
112-
if: steps.changesets.outputs.published == 'false'
113-
114-
run: nix develop --command bash -c 'pnpm pkg-pr-new publish './packages/*' './packages/sdk-effects/*' --packageManager=pnpm'
115-
116119
- uses: codecov/codecov-action@v5
117120
with:
118121
files: ./packages/**/coverage/*.xml
119122
token: ${{ secrets.CODECOV_TOKEN }}
120123

121124
- name: Ensure builds run
122-
run: nix develop --command bash -c 'pnpm nx run-many -t build'
125+
run: pnpm nx run-many -t build
126+
env:
127+
NX_CLOUD_DISTRIBUTED_EXECUTION: false
123128

124129
- name: Build docs
125-
run: nix develop --command bash -c 'pnpm generate-docs'
130+
run: pnpm generate-docs
126131

127132
- name: Publish api docs
128133
if: steps.changesets.outputs.published == 'true'
@@ -142,14 +147,12 @@ jobs:
142147

143148
- name: Calculate baseline bundle sizes
144149
run: |
145-
nix develop --command bash -c '
146-
chmod +x ./scripts/bundle-sizes.sh
147-
rm -f previous_sizes.json
148-
echo "📊 Calculating fresh baseline bundle sizes for main branch"
149-
./scripts/bundle-sizes.sh
150-
echo "✅ Baseline bundle sizes calculated"
151-
cat previous_sizes.json
152-
'
150+
chmod +x ./scripts/bundle-sizes.sh
151+
rm -f previous_sizes.json
152+
echo "📊 Calculating fresh baseline bundle sizes for main branch"
153+
./scripts/bundle-sizes.sh
154+
echo "✅ Baseline bundle sizes calculated"
155+
cat previous_sizes.json
153156
154157
- name: Upload baseline bundle sizes
155158
uses: actions/upload-artifact@v4
@@ -174,23 +177,20 @@ jobs:
174177
with:
175178
fetch-depth: 0
176179
ref: ${{ inputs.branch }}
180+
- uses: pnpm/action-setup@v4
181+
with:
182+
run_install: false
183+
- uses: actions/setup-node@v4
184+
with:
185+
node-version-file: '.node-version'
186+
cache: 'pnpm'
177187

178-
- name: Install Nix
179-
uses: DeterminateSystems/nix-installer-action@v10
188+
- name: Update npm
189+
run: npm install -g npm@latest
180190

181-
- name: Configure Nix Cache
182-
uses: cachix/cachix-action@v14
183-
with:
184-
name: ping-javascript-sdk # Matches the cache name in ci.yml
185-
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
191+
- run: pnpm install --frozen-lockfile
186192

187-
- name: Install Dependencies and Start CI Run
188-
run: |
189-
nix develop --command bash -c '
190-
npm install -g npm@latest
191-
pnpm install --frozen-lockfile
192-
pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN"
193-
'
193+
- run: pnpm dlx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yml" --stop-agents-after="e2e-ci" --with-env-vars="CODECOV_TOKEN"
194194

195195
- name: Cache Playwright browsers
196196
uses: actions/cache@v4
@@ -200,13 +200,16 @@ jobs:
200200
restore-keys: |
201201
${{ runner.os }}-playwright-
202202
203-
- name: Install Browsers, Configure Pnpm, and Run Nx
204-
run: |
205-
nix develop --command bash -c '
206-
pnpm exec playwright install
207-
pnpm config set store-dir $PNPM_CACHE_FOLDER
208-
pnpm exec nx run-many -t build test e2e-ci
209-
'
203+
- run: pnpm exec playwright install
204+
205+
- uses: nrwl/nx-set-shas@v4
206+
with:
207+
main-branch-name: main
208+
209+
- name: setup pnpm config
210+
run: pnpm config set store-dir $PNPM_CACHE_FOLDER
211+
212+
- run: pnpm exec nx run-many -t build test e2e-ci
210213

211214
- uses: actions/upload-artifact@v4
212215
if: ${{ !cancelled() }}
@@ -216,11 +219,11 @@ jobs:
216219
./**/.playwright/**
217220
retention-days: 30
218221

219-
- name: Version and Publish Packages
220-
run: |
221-
nix develop --command bash -c '
222-
pnpm changeset version --snapshot ${{ inputs.prerelease }}
223-
pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }}
224-
'
222+
- name: Version Packages as prerelease
223+
run: pnpm changeset version --snapshot ${{ inputs.prerelease }}
225224
env:
226225
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
226+
227+
# The actual npm publish that must occur in the authorized file
228+
- name: Publish packages with dist-tag
229+
run: pnpm publish -r --tag ${{ inputs.dist_tag }} --no-git-checks --access ${{ inputs.access }}

0 commit comments

Comments
 (0)