Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ permissions:
contents: read
pull-requests: read

env:
NX_NO_CLOUD: true
NX_CACHE_FILES: "modules/*/src/**/*.ts,modules/*/src/**/*.js,modules/*/*.json"

jobs:
unit-test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -63,16 +67,31 @@ jobs:
- name: Check In-Repo Package Versions
run: yarn run check-versions

- name: restore nx cache
id: nx-cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
with:
path: |
.nx/cache
modules/*/dist
key: ${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
restore-keys: |
${{ runner.os }}-nx-${{ matrix.node-version }}-${{ hashFiles('yarn.lock') }}-
${{ runner.os }}-nx-${{ matrix.node-version }}-

- name: build packages
env:
# Workaround for https://github.com/nodejs/node/issues/51555
DISABLE_V8_COMPILE_CACHE: '1'
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
run: yarn run postinstall

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

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

- name: restore nx cache
id: nx-cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
with:
path: |
.nx/cache
modules/*/dist
key: ${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
restore-keys: |
${{ runner.os }}-nx-license-${{ hashFiles('yarn.lock') }}-
${{ runner.os }}-nx-license-

- name: build packages
env:
# Workaround for https://github.com/nodejs/node/issues/51555
DISABLE_V8_COMPILE_CACHE: '1'
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}
run: yarn run postinstall

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

- name: restore nx cache
id: nx-cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3
if: "!contains( github.event.pull_request.labels.*.name, 'SKIP_CACHE')"
with:
path: |
.nx/cache
modules/*/dist
key: ${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-${{ hashFiles(env.NX_CACHE_FILES) }}
restore-keys: |
${{ runner.os }}-nx-browser-${{ hashFiles('yarn.lock') }}-
${{ runner.os }}-nx-browser-

- name: build packages
if: steps.lerna-cache.outputs.cache-hit == 'true'
env:
Expand All @@ -262,6 +308,7 @@ jobs:
run: yarn run browser-tests
env:
BITGOJS_TEST_PASSWORD: ${{ secrets.BITGOJS_TEST_PASSWORD }}
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'SKIP_CACHE') && 'true' || '' }}

docker-build:
runs-on: ubuntu-latest
Expand Down
40 changes: 30 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
name: Publish @bitgo-beta
on:
workflow_dispatch:
# push:
# branches:
# - master

permissions:
contents: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

env:
NX_NO_CLOUD: true
NX_SKIP_NX_CACHE: true
NX_DISABLE_NX_CACHE: true
NX_SKIP_REMOTE_CACHE: true
NX_DISABLE_REMOTE_CACHE: true
NX_CACHE: false

jobs:
publish:
name: Publish Release
Expand All @@ -25,9 +30,6 @@ jobs:
with:
node-version-file: .nvmrc

- name: Install BitGoJS
run: yarn install --with-frozen-lockfile

- name: Set Environment Variable for Alpha
if: github.ref != 'refs/heads/master' # only publish changes if on feature branches
run: |
Expand All @@ -48,16 +50,34 @@ jobs:
echo "@bitgo-beta:registry=https://registry.npmjs.org" >> .npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.BETA_TOKEN }}" >> .npmrc
echo "//registry.npmjs.org/:always-auth=true" >> .npmrc

- name: Install
env:
NOYARNPOSTINSTALL: true
run: yarn install --with-frozen-lockfile --ignore-scripts

- name: Clean all caches
run: |
# Clean NX cache
npx nx reset
# Clean TypeScript incremental build cache
find . -name "tsconfig.tsbuildinfo" -delete
# Clean dist directories to force full rebuild
find ./modules -name "dist" -type d -exec rm -rf {} + 2>/dev/null || true
# Clean node_modules/.cache
find ./modules -path "*/node_modules/.cache" -type d -exec rm -rf {} + 2>/dev/null || true

- name: Rebuild packages
env:
NOYARNPOSTINSTALL: true
run: yarn lerna run build --stream

- name: Prepare Release
run: |
rm -rfd ./modules/web-demo
rm -rfd ./modules/express
npx tsx ./scripts/prepare-release.ts ${{ env.preid }}

- name: Rebuild packages
run: yarn


- name: Commit Local Changes
run: git commit -am "Auto updated ${{ env.preid }} branch" --no-verify || echo "No changes to commit"

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ modules/**/pack-scoped/
coverage
/.direnv/
.claude/
.nx/
CLAUDE.sessions.md
sessions/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ CHANGELOG.md
flake.lock

modules/babylonlabs-io-btc-staking-ts/

/.nx/workspace-data
62 changes: 62 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,64 @@ yarn integration-test
yarn coverage
```

### Test Caching
BitGoJS uses Lerna + Nx for local test caching to speed up development:

```bash
# Tests are automatically cached when you run them
yarn unit-test

# Cache status is shown in output:
# - Fresh run: Tests execute normally
# - Cache hit: "[existing outputs match the cache, left as is]"

# Clear cache if needed
yarn clean-cache

# Cache works with all test commands
yarn unit-test --scope @bitgo/sdk-core # Caches per package
yarn unit-test-changed # Caches changed packages
```

The cache automatically invalidates when:
- Source files change
- Test files change
- Dependencies change
- Configuration files change (tsconfig.json, .mocharc.*, package.json)

### CI Caching

BitGoJS CI uses both GitHub Actions cache and Nx cache for optimal performance:

**GitHub Actions Cache**:
- Caches `node_modules` and `modules/*/node_modules`
- Caches `.nx/cache` and `modules/*/dist` directories
- Cache keys include source file hashes for proper invalidation

**Nx Cache**:
- Automatically enabled in CI (via `useNx: true` in lerna.json)
- Caches build outputs and test results
- Respects task dependencies (tests depend on builds)

**Skipping Cache**:
- Add the `SKIP_CACHE` label to a PR to bypass all caching
- This forces fresh installs and builds
- When `SKIP_CACHE` is used:
- GitHub Actions cache is not restored
- Nx caching is disabled (`NX_SKIP_NX_CACHE=true`)
- All tasks run fresh without any caching

**Troubleshooting**:
If you encounter module resolution errors in CI:
```bash
# Option 1: Use --skip-nx-cache flag
yarn unit-test --skip-nx-cache

# Option 2: Clear cache and rebuild
yarn clean-cache
yarn build
```

### Browser Compatibility
```bash
# Run browser tests
Expand Down Expand Up @@ -121,3 +179,7 @@ This will generate the necessary boilerplate for a new coin implementation.
## Node.js Version Support

BitGoJS supports Node.js versions >=20 and <23, with NPM >=3.10.10.

## Sessions System Behaviors

@CLAUDE.sessions.md
3 changes: 1 addition & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
"version": {
"message": "chore(root): publish modules"
}
},
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": false
"useNx": true
}
1 change: 1 addition & 0 deletions modules/babylonlabs-io-btc-staking-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"author": "Babylon Labs Ltd.",
"license": "SEE LICENSE IN LICENSE",
"devDependencies": {
"@types/glob": "^8.1.0",
"dts-bundle-generator": "^9.3.1",
"esbuild": "^0.20.2",
"nanoevents": "^9.1.0"
Expand Down
3 changes: 0 additions & 3 deletions modules/express/encryptedPrivKeys.json

This file was deleted.

6 changes: 6 additions & 0 deletions modules/express/test/unit/clientRoutes/externalSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ describe('External signer', () => {
if (nock.isActive()) {
nock.restore();
}

// Clean up encryptedPrivKeys.json file if it exists
const encryptedPrivKeysPath = 'encryptedPrivKeys.json';
if (fs.existsSync(encryptedPrivKeysPath)) {
fs.unlinkSync(encryptedPrivKeysPath);
}
});

it('should read an encrypted prv from signerFileSystemPath and pass it to coin.signTransaction', async () => {
Expand Down
84 changes: 84 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "unit-test", "integration-test"],
"cacheDirectory": ".nx/cache",
"parallel": 3,
"skipNxCache": false
}
}
},
"targetDefaults": {
"build": {
"cache": true,
"dependsOn": ["^build"],
"inputs": [
"production",
"{projectRoot}/**/*.json",
"{projectRoot}/tsconfig.json",
"{projectRoot}/package.json",
"{workspaceRoot}/tsconfig.json",
"{workspaceRoot}/tsconfig.packages.json"
],
"outputs": [
"{projectRoot}/dist"
]
},
"unit-test": {
"cache": true,
"dependsOn": ["build"],
"inputs": [
"default",
"{projectRoot}/**/*.ts",
"{projectRoot}/**/*.js",
"{projectRoot}/**/*.json",
"{projectRoot}/.mocharc.*",
"{projectRoot}/tsconfig.json",
"{projectRoot}/package.json",
"{workspaceRoot}/tsconfig.json"
],
"outputs": [
"{projectRoot}/.nyc_output",
"{projectRoot}/coverage"
]
},
"integration-test": {
"cache": true,
"dependsOn": ["build"],
"inputs": [
"default",
"{projectRoot}/**/*.ts",
"{projectRoot}/**/*.js",
"{projectRoot}/**/*.json",
"{projectRoot}/.mocharc.*",
"{projectRoot}/tsconfig.json",
"{projectRoot}/package.json",
"{workspaceRoot}/tsconfig.json"
],
"outputs": [
"{projectRoot}/.nyc_output",
"{projectRoot}/coverage"
]
}
},
"namedInputs": {
"default": [
"{projectRoot}/**/*",
"!{projectRoot}/**/*.md",
"!{projectRoot}/**/*.spec.ts",
"!{projectRoot}/**/*.spec.js",
"!{projectRoot}/**/test/**",
"!{projectRoot}/.nyc_output/**",
"!{projectRoot}/coverage/**",
"!{projectRoot}/dist/**",
"!{projectRoot}/lib/**",
"!{projectRoot}/node_modules/**"
],
"production": [
"default"
]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"https-browserify": "^1.0.0",
"husky": "^8.0.1",
"improved-yarn-audit": "^3.0.0",
"lerna": "^5.5.0",
"lerna": "^8.2.4",
"lint-staged": "^12.4.1",
"make-dir": "^3.1.0",
"mocha": "10.6.0",
Expand Down Expand Up @@ -128,6 +128,7 @@
"check-fmt-changed": "lerna run check-fmt --since origin/${GITHUB_REPO_BRANCH:-master}..HEAD --stream --parallel",
"check-fmt": "lerna run check-fmt --stream --parallel",
"check-commits": "yarn commitlint --from=origin/${GITHUB_REPO_BRANCH:-master} -V",
"clean-cache": "npx nx reset",
"check-deps": "tsx ./scripts/check-package-dependencies.ts",
"check-versions": "node ./check-package-versions.js",
"dev": "tsc -b ./tsconfig.packages.json -w",
Expand Down
Loading
Loading