Skip to content

Commit f7023ec

Browse files
feat: enable cache in CI
TICKET: WP-6096
1 parent 7306a1f commit f7023ec

File tree

2 files changed

+73
-8
lines changed

2 files changed

+73
-8
lines changed

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ permissions:
1414
contents: read
1515
pull-requests: read
1616

17+
env:
18+
NX_NO_CLOUD: true
19+
1720
jobs:
1821
unit-test:
1922
runs-on: ubuntu-latest
@@ -63,16 +66,31 @@ jobs:
6366
- name: Check In-Repo Package Versions
6467
run: yarn run check-versions
6568

69+
- name: restore nx cache
70+
id: nx-cache
71+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
72+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
73+
with:
74+
path: |
75+
.nx/cache
76+
modules/*/dist
77+
key: ${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles('modules/*/src/**/*.ts', 'modules/*/src/**/*.js', 'modules/*/*.json', '!modules/*/package-lock.json') }}
78+
restore-keys: |
79+
${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-
80+
${{ runner.os }}-nx-${{ matrix.node-version }}-
81+
6682
- name: build packages
6783
env:
6884
# Workaround for https://github.com/nodejs/node/issues/51555
6985
DISABLE_V8_COMPILE_CACHE: '1'
86+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
7087
run: yarn run postinstall
7188

7289
- name: Unit Test
7390
run: yarn run unit-test-changed
7491
env:
7592
BITGOJS_TEST_PASSWORD: ${{ secrets.BITGOJS_TEST_PASSWORD }}
93+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
7694

7795
# - name: Upload Code Coverage
7896
# run: |
@@ -158,10 +176,24 @@ jobs:
158176
if: steps.lerna-cache.outputs.cache-hit != 'true'
159177
run: yarn install --with-frozen-lockfile --ignore-scripts
160178

179+
- name: restore nx cache
180+
id: nx-cache
181+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
182+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
183+
with:
184+
path: |
185+
.nx/cache
186+
modules/*/dist
187+
key: ${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-${{ hashFiles('modules/*/src/**/*.ts', 'modules/*/src/**/*.js', 'modules/*/*.json', '!modules/*/package-lock.json') }}
188+
restore-keys: |
189+
${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-
190+
${{ runner.os }}-nx-license-
191+
161192
- name: build packages
162193
env:
163194
# Workaround for https://github.com/nodejs/node/issues/51555
164195
DISABLE_V8_COMPILE_CACHE: '1'
196+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
165197
run: yarn run postinstall
166198

167199
- name: Run Fossa Analysis
@@ -251,6 +283,19 @@ jobs:
251283
if: steps.lerna-cache.outputs.cache-hit != 'true' || contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')
252284
run: yarn install --with-frozen-lockfile
253285

286+
- name: restore nx cache
287+
id: nx-cache
288+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
289+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
290+
with:
291+
path: |
292+
.nx/cache
293+
modules/*/dist
294+
key: ${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-${{ hashFiles('modules/*/src/**/*.ts', 'modules/*/src/**/*.js', 'modules/*/*.json', '!modules/*/package-lock.json') }}
295+
restore-keys: |
296+
${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-
297+
${{ runner.os }}-nx-browser-
298+
254299
- name: build packages
255300
if: steps.lerna-cache.outputs.cache-hit == 'true'
256301
env:
@@ -262,6 +307,7 @@ jobs:
262307
run: yarn run browser-tests
263308
env:
264309
BITGOJS_TEST_PASSWORD: ${{ secrets.BITGOJS_TEST_PASSWORD }}
310+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
265311

266312
docker-build:
267313
runs-on: ubuntu-latest

CLAUDE.md

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,37 @@ The cache automatically invalidates when:
7979
- Dependencies change
8080
- Configuration files change (tsconfig.json, .mocharc.*, package.json)
8181

82-
**Note for CI**: Nx caching requires proper dependency management. Tests depend on build outputs, so ensure packages are built before running tests. The `yarn postinstall` step must run even when node_modules are cached.
83-
84-
If you encounter TypeScript module resolution errors in CI, you can disable Nx caching by:
82+
### CI Caching
83+
84+
BitGoJS CI uses both GitHub Actions cache and Nx cache for optimal performance:
85+
86+
**GitHub Actions Cache**:
87+
- Caches `node_modules` and `modules/*/node_modules`
88+
- Caches `.nx/cache` and `modules/*/dist` directories
89+
- Cache keys include source file hashes for proper invalidation
90+
91+
**Nx Cache**:
92+
- Automatically enabled in CI (via `useNx: true` in lerna.json)
93+
- Caches build outputs and test results
94+
- Respects task dependencies (tests depend on builds)
95+
96+
**Skipping Cache**:
97+
- Add the `SKIP_CACHE` label to a PR to bypass all caching
98+
- This forces fresh installs and builds
99+
- When `SKIP_CACHE` is used:
100+
- GitHub Actions cache is not restored
101+
- Nx caching is disabled (`NX_SKIP_NX_CACHE=true`)
102+
- All tasks run fresh without any caching
103+
104+
**Troubleshooting**:
105+
If you encounter module resolution errors in CI:
85106
```bash
86107
# Option 1: Use --skip-nx-cache flag
87108
yarn unit-test --skip-nx-cache
88109

89-
# Option 2: Set environment variable
90-
NX_SKIP_NX_CACHE=true yarn unit-test
91-
92-
# Option 3: Temporarily disable in lerna.json
93-
# Set "useNx": false
110+
# Option 2: Clear cache and rebuild
111+
yarn clean-cache
112+
yarn build
94113
```
95114

96115
### Browser Compatibility

0 commit comments

Comments
 (0)