Skip to content

Commit 95ba49a

Browse files
authored
build: Update Lerna to v6 and use Nx caching for builds (#6555)
1 parent aadd855 commit 95ba49a

File tree

34 files changed

+2161
-1602
lines changed

34 files changed

+2161
-1602
lines changed

.github/workflows/build.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ jobs:
120120
changed_browser: ${{ steps.changed.outputs.browser }}
121121
changed_browser_integration: ${{ steps.changed.outputs.browser_integration }}
122122
changed_any_code: ${{ steps.changed.outputs.any_code }}
123+
# Note: These next three have to be checked as strings ('true'/'false')!
124+
is_master: ${{ github.ref == 'refs/heads/master' }}
125+
is_release: ${{ startsWith(github.ref, 'refs/heads/release/') }}
126+
force_skip_cache:
127+
${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-skip-cache') }}
123128

124129
job_install_deps:
125130
name: Install Dependencies
@@ -139,14 +144,19 @@ jobs:
139144
- name: Compute dependency cache key
140145
id: compute_lockfile_hash
141146
run: echo "hash=${{ hashFiles('yarn.lock') }}" >> "$GITHUB_OUTPUT"
147+
148+
# When the `ci-skip-cache` label is added to a PR, we always want to skip dependency cache
142149
- name: Check dependency cache
143150
uses: actions/cache@v3
144151
id: cache_dependencies
152+
if: needs.job_get_metadata.outputs.force_skip_cache == 'false'
145153
with:
146154
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
147155
key: ${{ steps.compute_lockfile_hash.outputs.hash }}
156+
148157
- name: Install dependencies
149-
if: steps.cache_dependencies.outputs.cache-hit == ''
158+
if:
159+
steps.cache_dependencies.outputs.cache-hit == '' || needs.job_get_metadata.outputs.force_skip_cache == 'true'
150160
run: yarn install --ignore-engines --frozen-lockfile
151161
outputs:
152162
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
@@ -168,12 +178,35 @@ jobs:
168178
with:
169179
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
170180
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
181+
171182
- name: Check build cache
172183
uses: actions/cache@v3
173184
id: cache_built_packages
185+
if: needs.job_get_metadata.outputs.force_skip_cache == 'false'
174186
with:
175187
path: ${{ env.CACHED_BUILD_PATHS }}
176188
key: ${{ env.BUILD_CACHE_KEY }}
189+
190+
- name: NX cache
191+
uses: actions/cache@v3
192+
# Disable cache when:
193+
# - on master
194+
# - on release branches
195+
# - when PR has `ci-skip-cache` label
196+
if: |
197+
needs.job_get_metadata.outputs.is_master == 'false' &&
198+
needs.job_get_metadata.outputs.is_release == 'false' &&
199+
needs.job_get_metadata.outputs.force_skip_cache == 'false'
200+
with:
201+
path: node_modules/.cache/nx
202+
key: nx-${{ runner.os }}-${{ github.ref }}-${{ env.HEAD_COMMIT }}
203+
# GH will use the first restore-key it finds that matches
204+
# So it will start by looking for one from the same branch, else take the newest one it can find elsewhere
205+
restore-keys: |
206+
nx-${{ runner.os }}-${{ github.ref }}-${{ env.HEAD_COMMIT }}
207+
nx-${{ runner.os }}-${{ github.ref }}
208+
nx-${{ runner.os }}
209+
177210
- name: Build packages
178211
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
179212
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
@@ -232,7 +265,7 @@ jobs:
232265
timeout-minutes: 15
233266
runs-on: ubuntu-20.04
234267
# Size Check will error out outside of the context of a PR
235-
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
268+
if: github.event_name == 'pull_request' || needs.job_get_metadata.outputs.is_master == 'true'
236269
steps:
237270
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
238271
uses: actions/checkout@v3
@@ -258,7 +291,7 @@ jobs:
258291
- name: Check bundle sizes
259292
uses: getsentry/size-limit-action@v5
260293
# Don't run size check on release branches - at that point, we're already committed
261-
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
294+
if: needs.job_get_metadata.outputs.is_release == 'false'
262295
with:
263296
github_token: ${{ secrets.GITHUB_TOKEN }}
264297
skip_step: build
@@ -320,7 +353,7 @@ jobs:
320353
needs: [job_get_metadata, job_build]
321354
runs-on: ubuntu-20.04
322355
# Build artifacts are only needed for releasing workflow.
323-
if: startsWith(github.ref, 'refs/heads/release/')
356+
if: needs.job_get_metadata.outputs.is_release == 'true'
324357
steps:
325358
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
326359
uses: actions/checkout@v3
@@ -339,7 +372,7 @@ jobs:
339372
path: ${{ env.CACHED_BUILD_PATHS }}
340373
key: ${{ env.BUILD_CACHE_KEY }}
341374
- name: Pack
342-
run: yarn build:npm
375+
run: yarn build:tarball
343376
- name: Archive artifacts
344377
uses: actions/[email protected]
345378
with:

docs/new-sdk-release-checklist.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This page serves as a checklist of what to do when releasing a new SDK for the f
2121
- [ ] Make sure that the `LICENSE` file exists and has the correct license (We default to the `MIT` license)
2222
- [ ] Also check, that the same license is mentioned in `package.json`
2323

24-
- [ ] Make sure that the tarball (`yarn build:npm`) has all the necessary contents
24+
- [ ] Make sure that the tarball (`yarn build:tarball`) has all the necessary contents
2525

2626
For basic SDKs, this means that the tarball has at least these files:
2727

lerna.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"lerna": "3.4.0",
2+
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
33
"version": "7.30.0",
4-
"packages": "packages/*",
4+
"packages": ["packages/*"],
55
"npmClient": "yarn",
66
"useWorkspaces": true
77
}

nx.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"tasksRunnerOptions": {
3+
"default": {
4+
"runner": "nx/tasks-runners/default",
5+
"options": {
6+
"cacheableOperations": [
7+
"build:bundle",
8+
"build:transpile",
9+
"build:tarball",
10+
"build:types"
11+
]
12+
}
13+
}
14+
},
15+
"targetDefaults": {
16+
"build:bundle": {
17+
"dependsOn": [
18+
"^build:transpile",
19+
"build:transpile",
20+
"^build:types",
21+
"build:types"
22+
],
23+
"outputs": [
24+
"{projectRoot}/build/bundles"
25+
]
26+
},
27+
"build:tarball": {
28+
"dependsOn": [
29+
"^build:transpile",
30+
"build:transpile",
31+
"^build:types",
32+
"build:types"
33+
],
34+
"outputs": []
35+
},
36+
"build:transpile": {
37+
"dependsOn": [
38+
"^build:transpile:uncached",
39+
"^build:transpile",
40+
"build:transpile:uncached"
41+
],
42+
"outputs": [
43+
"{projectRoot}/build/npm",
44+
"{projectRoot}/build/esm",
45+
"{projectRoot}/build/cjs"
46+
]
47+
},
48+
"build:types": {
49+
"dependsOn": [
50+
"^build:types"
51+
],
52+
"outputs": [
53+
"{projectRoot}/build/types",
54+
"{projectRoot}/build/npm/types"
55+
]
56+
}
57+
},
58+
"targets": {
59+
"@sentry/serverless": {
60+
"build:bundle": {
61+
"dependsOn": [],
62+
"outputs": [
63+
"{projectRoot}/build/aws"
64+
]
65+
}
66+
}
67+
}
68+
}

package.json

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
{
22
"private": true,
33
"scripts": {
4-
"build": "node ./scripts/verify-packages-versions.js && yarn run-p build:rollup build:types build:bundle && yarn build:extras",
5-
"build:bundle": "yarn ts-node scripts/ensure-bundle-deps.ts && yarn lerna run --parallel build:bundle",
6-
"build:dev": "run-p build:types build:rollup",
7-
"build:dev:filter": "lerna run --stream --concurrency 1 --sort build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
8-
"build:extras": "lerna run --parallel build:extras",
9-
"build:rollup": "lerna run --parallel build:rollup",
10-
"build:types": "lerna run --stream build:types",
11-
"build:watch": "lerna run --parallel build:watch",
12-
"build:dev:watch": "lerna run --parallel build:dev:watch",
4+
"build": "node ./scripts/verify-packages-versions.js && run-s build:types build:transpile build:bundle",
5+
"build:bundle": "lerna run build:bundle",
6+
"build:dev": "run-s build:types build:transpile",
7+
"build:dev:filter": "lerna run build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
8+
"build:transpile": "lerna run build:transpile",
9+
"build:types": "lerna run build:types",
10+
"build:watch": "lerna run build:watch",
11+
"build:dev:watch": "lerna run build:dev:watch",
1312
"build:types:watch": "ts-node scripts/build-types-watch.ts",
14-
"build:npm": "lerna run --parallel build:npm",
15-
"circularDepCheck": "lerna run --parallel circularDepCheck",
13+
"build:tarball": "lerna run build:tarball",
14+
"circularDepCheck": "lerna run circularDepCheck",
1615
"clean": "run-p clean:build clean:caches",
17-
"clean:build": "lerna run --parallel clean",
16+
"clean:build": "lerna run clean",
1817
"clean:caches": "yarn rimraf eslintcache && yarn jest --clearCache",
1918
"clean:deps": "lerna clean --yes && rm -rf node_modules && yarn",
2019
"clean:all": "run-p clean:build clean:caches clean:deps",
2120
"codecov": "codecov",
22-
"fix": "lerna run --parallel fix",
23-
"link:yarn": "lerna exec --parallel yarn link",
24-
"lint": "lerna run --parallel lint",
25-
"lint:eslint": "lerna run --parallel lint:eslint",
21+
"fix": "lerna run fix",
22+
"link:yarn": "lerna exec yarn link",
23+
"lint": "lerna run lint",
24+
"lint:eslint": "lerna run lint:eslint",
2625
"postpublish": "lerna run --stream --concurrency 1 postpublish",
27-
"test": "lerna run --ignore @sentry-internal/browser-integration-tests --ignore @sentry-internal/node-integration-tests --stream --concurrency 1 --sort test",
28-
"test-ci": "ts-node ./scripts/test.ts",
29-
"test-ci-browser": "cross-env TESTS_SKIP=node ts-node ./scripts/test.ts",
30-
"test-ci-node": "cross-env TESTS_SKIP=browser ts-node ./scripts/test.ts",
26+
"test": "lerna run --ignore @sentry-internal/* test",
27+
"test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby}\" --ignore @sentry-internal/*",
28+
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
3129
"postinstall": "patch-package"
3230
},
3331
"volta": {
@@ -87,7 +85,7 @@
8785
"jsdom": "^19.0.0",
8886
"karma-browserstack-launcher": "^1.5.1",
8987
"karma-firefox-launcher": "^1.1.0",
90-
"lerna": "3.13.4",
88+
"lerna": "^6.0.3",
9189
"madge": "4.0.2",
9290
"magic-string": "^0.27.0",
9391
"mocha": "^6.1.4",
@@ -116,5 +114,5 @@
116114
"@types/express-serve-static-core": "4.17.30"
117115
},
118116
"version": "0.0.0",
119-
"dependencies": {}
117+
"name": "sentry-javascript"
120118
}

packages/angular/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
"zone.js": "^0.11.8"
4242
},
4343
"scripts": {
44-
"build": "yarn build:ngc",
45-
"build:ngc": "ng build --prod",
44+
"build": "yarn build:transpile",
45+
"build:transpile": "ng build --prod",
4646
"build:dev": "run-s build",
47-
"build:extras": "yarn build",
48-
"build:watch": "run-p build:ngc:watch",
49-
"build:ngc:watch": "ng build --prod --watch",
50-
"build:npm": "npm pack ./build",
47+
"build:watch": "run-p build:transpile:watch",
48+
"build:transpile:watch": "ng build --prod --watch",
49+
"build:tarball": "npm pack ./build",
5150
"circularDepCheck": "madge --circular src/index.ts",
5251
"clean": "rimraf build coverage sentry-angular-*.tgz",
5352
"fix": "run-s fix:eslint fix:prettier",

packages/browser/package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,15 @@
4444
"webpack": "^4.30.0"
4545
},
4646
"scripts": {
47-
"build": "run-p build:rollup build:bundle build:types",
48-
"build:bundle": "yarn ts-node ../../scripts/ensure-bundle-deps.ts && yarn rollup --config rollup.bundle.config.js",
49-
"build:dev": "run-p build:rollup build:types",
50-
"build:rollup": "rollup -c rollup.npm.config.js",
47+
"build": "run-p build:transpile build:bundle build:types",
48+
"build:bundle": "rollup --config rollup.bundle.config.js",
49+
"build:transpile": "rollup -c rollup.npm.config.js",
5150
"build:types": "tsc -p tsconfig.types.json",
52-
"build:watch": "run-p build:rollup:watch build:bundle:watch build:types:watch",
51+
"build:watch": "run-p build:transpile:watch build:bundle:watch build:types:watch",
5352
"build:bundle:watch": "rollup --config rollup.bundle.config.js --watch",
54-
"build:dev:watch": "run-p build:rollup:watch build:types:watch",
55-
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
53+
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
5654
"build:types:watch": "tsc -p tsconfig.types.json --watch",
57-
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
55+
"build:tarball": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
5856
"circularDepCheck": "madge --circular src/index.ts",
5957
"clean": "rimraf build coverage .rpt2_cache sentry-browser-*.tgz",
6058
"fix": "run-s fix:eslint fix:prettier",

packages/core/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"tslib": "^1.9.3"
2222
},
2323
"scripts": {
24-
"build": "run-p build:rollup build:types",
24+
"build": "run-p build:transpile build:types",
2525
"build:dev": "run-s build",
26-
"build:rollup": "rollup -c rollup.npm.config.js",
26+
"build:transpile": "rollup -c rollup.npm.config.js",
2727
"build:types": "tsc -p tsconfig.types.json",
28-
"build:watch": "run-p build:rollup:watch build:types:watch",
28+
"build:watch": "run-p build:transpile:watch build:types:watch",
2929
"build:dev:watch": "run-s build:watch",
30-
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
30+
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
3131
"build:types:watch": "tsc -p tsconfig.types.json --watch",
32-
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
32+
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
3333
"circularDepCheck": "madge --circular src/index.ts",
3434
"clean": "rimraf build coverage sentry-core-*.tgz",
3535
"fix": "run-s fix:eslint fix:prettier",

packages/e2e-tests/publish-packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'path';
66
const repositoryRoot = path.resolve(__dirname, '../..');
77

88
// Create tarballs
9-
childProcess.execSync('yarn build:npm', { encoding: 'utf8', cwd: repositoryRoot, stdio: 'inherit' });
9+
childProcess.execSync('yarn build:tarball', { encoding: 'utf8', cwd: repositoryRoot, stdio: 'inherit' });
1010

1111
// Get absolute paths of all the packages we want to publish to the fake registry
1212
const packageTarballPaths = glob.sync('packages/*/sentry-*.tgz', {

packages/ember/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"scripts": {
2020
"build": "ember build --environment=production",
21-
"build:npm": "ember ts:precompile && npm pack && ember ts:clean",
21+
"build:tarball": "ember ts:precompile && npm pack && ember ts:clean",
2222
"clean": "yarn rimraf sentry-ember-*.tgz",
2323
"lint": "run-p lint:js lint:hbs lint:ts",
2424
"lint:hbs": "ember-template-lint .",

packages/eslint-config-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"clean": "yarn rimraf sentry-internal-eslint-config-sdk-*.tgz",
4040
"lint": "prettier --check \"**/*.js\"",
4141
"fix": "prettier --write \"**/*.js\"",
42-
"build:npm": "npm pack",
42+
"build:tarball": "npm pack",
4343
"circularDepCheck": "madge --circular src/index.js"
4444
},
4545
"volta": {

packages/eslint-plugin-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
3434
"lint:prettier": "prettier --check \"{src,test}/**/*.js\"",
3535
"test": "mocha test --recursive",
36-
"build:npm": "npm pack",
36+
"build:tarball": "npm pack",
3737
"circularDepCheck": "madge --circular src/index.js"
3838
},
3939
"volta": {

packages/gatsby/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535
"react": "^18.0.0"
3636
},
3737
"scripts": {
38-
"build": "run-p build:rollup build:types && yarn build:extras",
38+
"build": "run-p build:transpile build:types",
3939
"build:dev": "run-s build",
40-
"build:extras": "yarn build:plugin",
4140
"build:plugin": "tsc -p tsconfig.plugin.json",
41+
"build:transpile": "run-p build:rollup build:plugin",
4242
"build:rollup": "rollup -c rollup.npm.config.js",
4343
"build:types": "tsc -p tsconfig.types.json",
44-
"build:watch": "run-p build:rollup:watch build:types:watch",
44+
"build:watch": "run-p build:transpile:watch build:types:watch",
4545
"build:dev:watch": "run-s build:watch",
46-
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
46+
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
4747
"build:types:watch": "tsc -p tsconfig.types.json --watch",
48-
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
48+
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
4949
"circularDepCheck": "madge --circular src/index.ts",
5050
"clean": "rimraf build coverage *.d.ts sentry-gatsby-*.tgz",
5151
"fix": "run-s fix:eslint fix:prettier",

0 commit comments

Comments
 (0)