Skip to content

Commit 3e3b453

Browse files
Revert "Revert "feat: upgrade lerna and enable local cache""
1 parent c4fdfac commit 3e3b453

File tree

12 files changed

+4167
-4312
lines changed

12 files changed

+4167
-4312
lines changed

.github/workflows/ci.yml

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

17+
env:
18+
NX_NO_CLOUD: true
19+
NX_CACHE_FILES: "modules/*/src/**/*.ts,modules/*/src/**/*.js,modules/*/*.json"
20+
1721
jobs:
1822
unit-test:
1923
runs-on: ubuntu-latest
@@ -63,16 +67,31 @@ jobs:
6367
- name: Check In-Repo Package Versions
6468
run: yarn run check-versions
6569

70+
- name: restore nx cache
71+
id: nx-cache
72+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
73+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
74+
with:
75+
path: |
76+
.nx/cache
77+
modules/*/dist
78+
key: ${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
79+
restore-keys: |
80+
${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-
81+
${{ runner.os }}-nx-${{ matrix.node-version }}-
82+
6683
- name: build packages
6784
env:
6885
# Workaround for https://github.com/nodejs/node/issues/51555
6986
DISABLE_V8_COMPILE_CACHE: '1'
87+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
7088
run: yarn run postinstall
7189

7290
- name: Unit Test
7391
run: yarn run unit-test-changed
7492
env:
7593
BITGOJS_TEST_PASSWORD: ${{ secrets.BITGOJS_TEST_PASSWORD }}
94+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
7695

7796
# - name: Upload Code Coverage
7897
# run: |
@@ -158,10 +177,24 @@ jobs:
158177
if: steps.lerna-cache.outputs.cache-hit != 'true'
159178
run: yarn install --with-frozen-lockfile --ignore-scripts
160179

180+
- name: restore nx cache
181+
id: nx-cache
182+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
183+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
184+
with:
185+
path: |
186+
.nx/cache
187+
modules/*/dist
188+
key: ${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
189+
restore-keys: |
190+
${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-
191+
${{ runner.os }}-nx-license-
192+
161193
- name: build packages
162194
env:
163195
# Workaround for https://github.com/nodejs/node/issues/51555
164196
DISABLE_V8_COMPILE_CACHE: '1'
197+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
165198
run: yarn run postinstall
166199

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

287+
- name: restore nx cache
288+
id: nx-cache
289+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
290+
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
291+
with:
292+
path: |
293+
.nx/cache
294+
modules/*/dist
295+
key: ${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
296+
restore-keys: |
297+
${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-
298+
${{ runner.os }}-nx-browser-
299+
254300
- name: build packages
255301
if: steps.lerna-cache.outputs.cache-hit == 'true'
256302
env:
@@ -262,6 +308,7 @@ jobs:
262308
run: yarn run browser-tests
263309
env:
264310
BITGOJS_TEST_PASSWORD: ${{ secrets.BITGOJS_TEST_PASSWORD }}
311+
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
265312

266313
docker-build:
267314
runs-on: ubuntu-latest

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ permissions:
1111
concurrency:
1212
group: ${{ github.workflow }}-${{ github.ref }}
1313

14+
env:
15+
NX_NO_CLOUD: true
16+
NX_SKIP_NX_CACHE: true
17+
1418
jobs:
1519
publish:
1620
name: Publish Release

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ modules/**/pack-scoped/
1818
coverage
1919
/.direnv/
2020
.claude/
21+
.nx/
22+
CLAUDE.sessions.md
23+
sessions/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ CHANGELOG.md
88
flake.lock
99

1010
modules/babylonlabs-io-btc-staking-ts/
11+
12+
/.nx/workspace-data

CLAUDE.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,64 @@ yarn integration-test
5454
yarn coverage
5555
```
5656

57+
### Test Caching
58+
BitGoJS uses Lerna + Nx for local test caching to speed up development:
59+
60+
```bash
61+
# Tests are automatically cached when you run them
62+
yarn unit-test
63+
64+
# Cache status is shown in output:
65+
# - Fresh run: Tests execute normally
66+
# - Cache hit: "[existing outputs match the cache, left as is]"
67+
68+
# Clear cache if needed
69+
yarn clean-cache
70+
71+
# Cache works with all test commands
72+
yarn unit-test --scope @bitgo/sdk-core # Caches per package
73+
yarn unit-test-changed # Caches changed packages
74+
```
75+
76+
The cache automatically invalidates when:
77+
- Source files change
78+
- Test files change
79+
- Dependencies change
80+
- Configuration files change (tsconfig.json, .mocharc.*, package.json)
81+
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:
106+
```bash
107+
# Option 1: Use --skip-nx-cache flag
108+
yarn unit-test --skip-nx-cache
109+
110+
# Option 2: Clear cache and rebuild
111+
yarn clean-cache
112+
yarn build
113+
```
114+
57115
### Browser Compatibility
58116
```bash
59117
# Run browser tests
@@ -121,3 +179,7 @@ This will generate the necessary boilerplate for a new coin implementation.
121179
## Node.js Version Support
122180

123181
BitGoJS supports Node.js versions >=20 and <23, with NPM >=3.10.10.
182+
183+
## Sessions System Behaviors
184+
185+
@CLAUDE.sessions.md

lerna.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
22
"version": "independent",
33
"npmClient": "yarn",
4-
"useWorkspaces": true,
54
"command": {
65
"version": {
76
"message": "chore(root): publish modules"
87
}
98
},
109
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
11-
"useNx": false
10+
"useNx": true
1211
}

modules/babylonlabs-io-btc-staking-ts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"author": "Babylon Labs Ltd.",
3333
"license": "SEE LICENSE IN LICENSE",
3434
"devDependencies": {
35+
"@types/glob": "^8.1.0",
3536
"dts-bundle-generator": "^9.3.1",
3637
"esbuild": "^0.20.2",
3738
"nanoevents": "^9.1.0"

modules/express/encryptedPrivKeys.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

modules/express/test/unit/clientRoutes/externalSign.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ describe('External signer', () => {
9898
if (nock.isActive()) {
9999
nock.restore();
100100
}
101+
102+
// Clean up encryptedPrivKeys.json file if it exists
103+
const encryptedPrivKeysPath = 'encryptedPrivKeys.json';
104+
if (fs.existsSync(encryptedPrivKeysPath)) {
105+
fs.unlinkSync(encryptedPrivKeysPath);
106+
}
101107
});
102108

103109
it('should read an encrypted prv from signerFileSystemPath and pass it to coin.signTransaction', async () => {

nx.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"$schema": "./node_modules/nx/schemas/nx-schema.json",
3+
"tasksRunnerOptions": {
4+
"default": {
5+
"runner": "nx/tasks-runners/default",
6+
"options": {
7+
"cacheableOperations": ["build", "unit-test", "integration-test"],
8+
"cacheDirectory": ".nx/cache",
9+
"parallel": 3,
10+
"skipNxCache": false
11+
}
12+
}
13+
},
14+
"targetDefaults": {
15+
"build": {
16+
"cache": true,
17+
"dependsOn": ["^build"],
18+
"inputs": [
19+
"production",
20+
"{projectRoot}/**/*.json",
21+
"{projectRoot}/tsconfig.json",
22+
"{projectRoot}/package.json",
23+
"{workspaceRoot}/tsconfig.json",
24+
"{workspaceRoot}/tsconfig.packages.json"
25+
],
26+
"outputs": [
27+
"{projectRoot}/dist"
28+
]
29+
},
30+
"unit-test": {
31+
"cache": true,
32+
"dependsOn": ["build"],
33+
"inputs": [
34+
"default",
35+
"{projectRoot}/**/*.ts",
36+
"{projectRoot}/**/*.js",
37+
"{projectRoot}/**/*.json",
38+
"{projectRoot}/.mocharc.*",
39+
"{projectRoot}/tsconfig.json",
40+
"{projectRoot}/package.json",
41+
"{workspaceRoot}/tsconfig.json"
42+
],
43+
"outputs": [
44+
"{projectRoot}/.nyc_output",
45+
"{projectRoot}/coverage"
46+
]
47+
},
48+
"integration-test": {
49+
"cache": true,
50+
"dependsOn": ["build"],
51+
"inputs": [
52+
"default",
53+
"{projectRoot}/**/*.ts",
54+
"{projectRoot}/**/*.js",
55+
"{projectRoot}/**/*.json",
56+
"{projectRoot}/.mocharc.*",
57+
"{projectRoot}/tsconfig.json",
58+
"{projectRoot}/package.json",
59+
"{workspaceRoot}/tsconfig.json"
60+
],
61+
"outputs": [
62+
"{projectRoot}/.nyc_output",
63+
"{projectRoot}/coverage"
64+
]
65+
}
66+
},
67+
"namedInputs": {
68+
"default": [
69+
"{projectRoot}/**/*",
70+
"!{projectRoot}/**/*.md",
71+
"!{projectRoot}/**/*.spec.ts",
72+
"!{projectRoot}/**/*.spec.js",
73+
"!{projectRoot}/**/test/**",
74+
"!{projectRoot}/.nyc_output/**",
75+
"!{projectRoot}/coverage/**",
76+
"!{projectRoot}/dist/**",
77+
"!{projectRoot}/lib/**",
78+
"!{projectRoot}/node_modules/**"
79+
],
80+
"production": [
81+
"default"
82+
]
83+
}
84+
}

0 commit comments

Comments
 (0)