Skip to content

build: Update Lerna to v6 and use Nx caching for builds #6555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 11, 2023
Merged
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
43 changes: 38 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ jobs:
changed_browser: ${{ steps.changed.outputs.browser }}
changed_browser_integration: ${{ steps.changed.outputs.browser_integration }}
changed_any_code: ${{ steps.changed.outputs.any_code }}
# Note: These next three have to be checked as strings ('true'/'false')!
is_master: ${{ github.ref == 'refs/heads/master' }}
is_release: ${{ startsWith(github.ref, 'refs/heads/release/') }}
force_skip_cache:
${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-skip-cache') }}

job_install_deps:
name: Install Dependencies
Expand All @@ -139,14 +144,19 @@ jobs:
- name: Compute dependency cache key
id: compute_lockfile_hash
run: echo "hash=${{ hashFiles('yarn.lock') }}" >> "$GITHUB_OUTPUT"

# When the `ci-skip-cache` label is added to a PR, we always want to skip dependency cache
- name: Check dependency cache
uses: actions/cache@v3
id: cache_dependencies
if: needs.job_get_metadata.outputs.force_skip_cache == 'false'
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ steps.compute_lockfile_hash.outputs.hash }}

- name: Install dependencies
if: steps.cache_dependencies.outputs.cache-hit == ''
if:
steps.cache_dependencies.outputs.cache-hit == '' || needs.job_get_metadata.outputs.force_skip_cache == 'true'
run: yarn install --ignore-engines --frozen-lockfile
outputs:
dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}
Expand All @@ -168,12 +178,35 @@ jobs:
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}

- name: Check build cache
uses: actions/cache@v3
id: cache_built_packages
if: needs.job_get_metadata.outputs.force_skip_cache == 'false'
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}

- name: NX cache
uses: actions/cache@v3
# Disable cache when:
# - on master
# - on release branches
# - when PR has `ci-skip-cache` label
if: |
needs.job_get_metadata.outputs.is_master == 'false' &&
needs.job_get_metadata.outputs.is_release == 'false' &&
needs.job_get_metadata.outputs.force_skip_cache == 'false'
with:
path: node_modules/.cache/nx
key: nx-${{ runner.os }}-${{ github.ref }}-${{ env.HEAD_COMMIT }}
# GH will use the first restore-key it finds that matches
# So it will start by looking for one from the same branch, else take the newest one it can find elsewhere
restore-keys: |
nx-${{ runner.os }}-${{ github.ref }}-${{ env.HEAD_COMMIT }}
nx-${{ runner.os }}-${{ github.ref }}
nx-${{ runner.os }}

- name: Build packages
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
Expand Down Expand Up @@ -232,7 +265,7 @@ jobs:
timeout-minutes: 15
runs-on: ubuntu-20.04
# Size Check will error out outside of the context of a PR
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
if: github.event_name == 'pull_request' || needs.job_get_metadata.outputs.is_master == 'true'
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v3
Expand All @@ -258,7 +291,7 @@ jobs:
- name: Check bundle sizes
uses: getsentry/size-limit-action@v5
# Don't run size check on release branches - at that point, we're already committed
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }}
if: needs.job_get_metadata.outputs.is_release == 'false'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_step: build
Expand Down Expand Up @@ -320,7 +353,7 @@ jobs:
needs: [job_get_metadata, job_build]
runs-on: ubuntu-20.04
# Build artifacts are only needed for releasing workflow.
if: startsWith(github.ref, 'refs/heads/release/')
if: needs.job_get_metadata.outputs.is_release == 'true'
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v3
Expand All @@ -339,7 +372,7 @@ jobs:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Pack
run: yarn build:npm
run: yarn build:tarball
- name: Archive artifacts
uses: actions/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion docs/new-sdk-release-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This page serves as a checklist of what to do when releasing a new SDK for the f
- [ ] Make sure that the `LICENSE` file exists and has the correct license (We default to the `MIT` license)
- [ ] Also check, that the same license is mentioned in `package.json`

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

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

Expand Down
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lerna": "3.4.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "7.30.0",
"packages": "packages/*",
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true
}
68 changes: 68 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": [
"build:bundle",
"build:transpile",
"build:tarball",
"build:types"
]
}
}
},
"targetDefaults": {
"build:bundle": {
"dependsOn": [
"^build:transpile",
"build:transpile",
"^build:types",
"build:types"
],
"outputs": [
"{projectRoot}/build/bundles"
]
},
"build:tarball": {
"dependsOn": [
"^build:transpile",
"build:transpile",
"^build:types",
"build:types"
],
"outputs": []
},
"build:transpile": {
"dependsOn": [
"^build:transpile:uncached",
"^build:transpile",
"build:transpile:uncached"
],
"outputs": [
"{projectRoot}/build/npm",
"{projectRoot}/build/esm",
"{projectRoot}/build/cjs"
]
},
"build:types": {
"dependsOn": [
"^build:types"
],
"outputs": [
"{projectRoot}/build/types",
"{projectRoot}/build/npm/types"
]
}
},
"targets": {
"@sentry/serverless": {
"build:bundle": {
"dependsOn": [],
Comment on lines +60 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: should this also depend on ^build:types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, I guess! I'll add it.

"outputs": [
"{projectRoot}/build/aws"
]
}
}
}
}
42 changes: 20 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
{
"private": true,
"scripts": {
"build": "node ./scripts/verify-packages-versions.js && yarn run-p build:rollup build:types build:bundle && yarn build:extras",
"build:bundle": "yarn ts-node scripts/ensure-bundle-deps.ts && yarn lerna run --parallel build:bundle",
"build:dev": "run-p build:types build:rollup",
"build:dev:filter": "lerna run --stream --concurrency 1 --sort build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
"build:extras": "lerna run --parallel build:extras",
"build:rollup": "lerna run --parallel build:rollup",
"build:types": "lerna run --stream build:types",
"build:watch": "lerna run --parallel build:watch",
"build:dev:watch": "lerna run --parallel build:dev:watch",
"build": "node ./scripts/verify-packages-versions.js && run-s build:types build:transpile build:bundle",
"build:bundle": "lerna run build:bundle",
"build:dev": "run-s build:types build:transpile",
"build:dev:filter": "lerna run build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
"build:transpile": "lerna run build:transpile",
"build:types": "lerna run build:types",
"build:watch": "lerna run build:watch",
"build:dev:watch": "lerna run build:dev:watch",
"build:types:watch": "ts-node scripts/build-types-watch.ts",
"build:npm": "lerna run --parallel build:npm",
"circularDepCheck": "lerna run --parallel circularDepCheck",
"build:tarball": "lerna run build:tarball",
"circularDepCheck": "lerna run circularDepCheck",
"clean": "run-p clean:build clean:caches",
"clean:build": "lerna run --parallel clean",
"clean:build": "lerna run clean",
"clean:caches": "yarn rimraf eslintcache && yarn jest --clearCache",
"clean:deps": "lerna clean --yes && rm -rf node_modules && yarn",
"clean:all": "run-p clean:build clean:caches clean:deps",
"codecov": "codecov",
"fix": "lerna run --parallel fix",
"link:yarn": "lerna exec --parallel yarn link",
"lint": "lerna run --parallel lint",
"lint:eslint": "lerna run --parallel lint:eslint",
"fix": "lerna run fix",
"link:yarn": "lerna exec yarn link",
"lint": "lerna run lint",
"lint:eslint": "lerna run lint:eslint",
"postpublish": "lerna run --stream --concurrency 1 postpublish",
"test": "lerna run --ignore @sentry-internal/browser-integration-tests --ignore @sentry-internal/node-integration-tests --stream --concurrency 1 --sort test",
"test-ci": "ts-node ./scripts/test.ts",
"test-ci-browser": "cross-env TESTS_SKIP=node ts-node ./scripts/test.ts",
"test-ci-node": "cross-env TESTS_SKIP=browser ts-node ./scripts/test.ts",
"test": "lerna run --ignore @sentry-internal/* test",
"test-ci-browser": "lerna run test --ignore \"@sentry/{node,opentelemetry-node,serverless,nextjs,remix,gatsby}\" --ignore @sentry-internal/*",
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
"postinstall": "patch-package"
},
"volta": {
Expand Down Expand Up @@ -87,7 +85,7 @@
"jsdom": "^19.0.0",
"karma-browserstack-launcher": "^1.5.1",
"karma-firefox-launcher": "^1.1.0",
"lerna": "3.13.4",
"lerna": "^6.0.3",
"madge": "4.0.2",
"magic-string": "^0.27.0",
"mocha": "^6.1.4",
Expand Down Expand Up @@ -116,5 +114,5 @@
"@types/express-serve-static-core": "4.17.30"
},
"version": "0.0.0",
"dependencies": {}
"name": "sentry-javascript"
}
11 changes: 5 additions & 6 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@
"zone.js": "^0.11.8"
},
"scripts": {
"build": "yarn build:ngc",
"build:ngc": "ng build --prod",
"build": "yarn build:transpile",
"build:transpile": "ng build --prod",
"build:dev": "run-s build",
"build:extras": "yarn build",
"build:watch": "run-p build:ngc:watch",
"build:ngc:watch": "ng build --prod --watch",
"build:npm": "npm pack ./build",
"build:watch": "run-p build:transpile:watch",
"build:transpile:watch": "ng build --prod --watch",
"build:tarball": "npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-angular-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
Expand Down
14 changes: 6 additions & 8 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@
"webpack": "^4.30.0"
},
"scripts": {
"build": "run-p build:rollup build:bundle build:types",
"build:bundle": "yarn ts-node ../../scripts/ensure-bundle-deps.ts && yarn rollup --config rollup.bundle.config.js",
"build:dev": "run-p build:rollup build:types",
"build:rollup": "rollup -c rollup.npm.config.js",
"build": "run-p build:transpile build:bundle build:types",
"build:bundle": "rollup --config rollup.bundle.config.js",
"build:transpile": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:rollup:watch build:bundle:watch build:types:watch",
"build:watch": "run-p build:transpile:watch build:bundle:watch build:types:watch",
"build:bundle:watch": "rollup --config rollup.bundle.config.js --watch",
"build:dev:watch": "run-p build:rollup:watch build:types:watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"build:tarball": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage .rpt2_cache sentry-browser-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"tslib": "^1.9.3"
},
"scripts": {
"build": "run-p build:rollup build:types",
"build": "run-p build:transpile build:types",
"build:dev": "run-s build",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:transpile": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:rollup:watch build:types:watch",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "run-s build:watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-core-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/publish-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';
const repositoryRoot = path.resolve(__dirname, '../..');

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

// Get absolute paths of all the packages we want to publish to the fake registry
const packageTarballPaths = glob.sync('packages/*/sentry-*.tgz', {
Expand Down
2 changes: 1 addition & 1 deletion packages/ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"build": "ember build --environment=production",
"build:npm": "ember ts:precompile && npm pack && ember ts:clean",
"build:tarball": "ember ts:precompile && npm pack && ember ts:clean",
"clean": "yarn rimraf sentry-ember-*.tgz",
"lint": "run-p lint:js lint:hbs lint:ts",
"lint:hbs": "ember-template-lint .",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"clean": "yarn rimraf sentry-internal-eslint-config-sdk-*.tgz",
"lint": "prettier --check \"**/*.js\"",
"fix": "prettier --write \"**/*.js\"",
"build:npm": "npm pack",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.js"
},
"volta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --check \"{src,test}/**/*.js\"",
"test": "mocha test --recursive",
"build:npm": "npm pack",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.js"
},
"volta": {
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
"react": "^18.0.0"
},
"scripts": {
"build": "run-p build:rollup build:types && yarn build:extras",
"build": "run-p build:transpile build:types",
"build:dev": "run-s build",
"build:extras": "yarn build:plugin",
"build:plugin": "tsc -p tsconfig.plugin.json",
"build:transpile": "run-p build:rollup build:plugin",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:rollup:watch build:types:watch",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "run-s build:watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage *.d.ts sentry-gatsby-*.tgz",
"fix": "run-s fix:eslint fix:prettier",
Expand Down
Loading