diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a430c311a16e..6753cc38941f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,8 +21,7 @@ env: ${{ github.workspace }}/packages/ember/*.d.ts ${{ github.workspace }}/packages/ember/instance-initializers ${{ github.workspace }}/packages/serverless/dist-awslambda-layer/*.zip - - BUILD_CACHE_KEY: ${{ github.sha }} + !**/node_modules/** jobs: job_install_deps: @@ -44,12 +43,12 @@ jobs: id: cache_dependencies with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} - key: ${{ steps.compute_lockfile_hash.outputs.hash }} + key: ${{ steps.compute_lockfile_hash.outputs.hash }}-linux - name: Install dependencies if: steps.cache_dependencies.outputs.cache-hit == '' run: yarn install --ignore-engines outputs: - dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }} + dependency_cache_key: ${{ steps.compute_lockfile_hash.outputs.hash }}-linux job_build: name: Build @@ -66,24 +65,17 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_install_deps.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 - id: cache_built_packages - with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} - 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 - # where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of - # this file) to a constant and skip rebuilding all of the packages each time CI runs. - if: steps.cache_built_packages.outputs.cache-hit == '' run: yarn build # We are performing a `prepublishOnly` step manually because build workflow is not responsible for publishing # the actual release. It only creates artifacts which then are uploaded and used by another workflow. # Because of that, any `prepublishOnly` script is skipped and files it produces are not included in the tarball. # We also cannot use `prepare` script which would be more suited, because it's run only before `pack` is called, # and it's done from a `release` workflow and not here. + - uses: actions/upload-artifact@v2 + with: + name: build-output + path: ${{ env.CACHED_BUILD_PATHS }} - name: Run prepublishOnly script if: startsWith(github.ref, 'refs/heads/release/') run: yarn prepublishOnly @@ -109,11 +101,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Check bundle sizes uses: getsentry/size-limit-action@v3 # Only run size check on master or pull requests @@ -139,11 +130,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run linter run: yarn lint @@ -162,16 +152,15 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run madge run: yarn circularDepCheck job_unit_test: - name: Test (Node ${{ matrix.node }}) + name: Test (Node ${{ matrix.node }} - Linux needs: job_build continue-on-error: true timeout-minutes: 30 @@ -191,18 +180,46 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run tests - env: - NODE_VERSION: ${{ matrix.node }} - run: ./scripts/test.sh + run: node ./scripts/test.js - name: Compute test coverage uses: codecov/codecov-action@v1 + job_unit_test_windows: + name: Test (Node ${{ matrix.node }} - Windows + needs: job_build + continue-on-error: true + timeout-minutes: 30 + runs-on: windows-latest + strategy: + matrix: + node: [6, 8, 10, 12, 14, 16] + steps: + - name: Check out current commit (${{ github.sha }}) + uses: actions/checkout@v2 + - name: Set up Node + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: Check dependency cache + if: matrix.os == 'windows-latest' + uses: actions/cache@v2 + with: + path: ${{ env.CACHED_DEPENDENCY_PATHS }} + key: ${{ needs.job_build_windows.outputs.dependency_cache_key }} + - uses: actions/download-artifact@v2 + with: + name: build-output + path: ${{ github.workspace }}/packages + - name: Install dependencies + run: yarn install + - name: Run tests + run: node ./scripts/test.js + job_nextjs_integration_test: name: Test @sentry/nextjs on (Node ${{ matrix.node }}) needs: job_build @@ -224,11 +241,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run tests env: NODE_VERSION: ${{ matrix.node }} @@ -266,11 +282,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run Ember tests run: yarn test --scope=@sentry/ember - name: Compute test coverage @@ -290,11 +305,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Pack run: yarn pack:changed - name: Archive artifacts @@ -341,11 +355,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run Playwright tests env: PW_BUNDLE: ${{ matrix.bundle }} @@ -377,11 +390,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run integration tests env: KARMA_BROWSER: ${{ matrix.browser }} @@ -406,11 +418,10 @@ jobs: with: path: ${{ env.CACHED_DEPENDENCY_PATHS }} key: ${{ needs.job_build.outputs.dependency_cache_key }} - - name: Check build cache - uses: actions/cache@v2 + - uses: actions/download-artifact@v2 with: - path: ${{ env.CACHED_BUILD_PATHS }} - key: ${{ env.BUILD_CACHE_KEY }} + name: build-output + path: ${{ github.workspace }}/packages - name: Run build tests run: | cd packages/browser diff --git a/scripts/test.js b/scripts/test.js new file mode 100644 index 000000000000..b2ae23995161 --- /dev/null +++ b/scripts/test.js @@ -0,0 +1,45 @@ +const { spawnSync } = require('child_process'); +const { join } = require('path'); + +const nodeVersion = parseInt(process.version.split('.')[0].replace('v', ''), 10); + +function run(cmd) { + console.log(cmd); + const result = spawnSync(cmd, { shell: true, stdio: 'inherit', cwd: join(__dirname, '..') }); + + if (result.status !== 0) { + process.exit(result.status); + } +} + +// control which packages we test on each version of node +if (nodeVersion <= 6) { + // install legacy versions of packages whose current versions don't support node 6 + // ignoring engines and scripts lets us get away with having incompatible things installed for packages we're not testing + run('cd packages/node && yarn add --dev --ignore-engines --ignore-scripts nock@10.x'); + run('cd packages/tracing && yarn add --dev --ignore-engines --ignore-scripts jsdom@11.x'); + run('cd packages/utils && yarn add --dev --ignore-engines --ignore-scripts jsdom@11.x'); + + // only test against @sentry/node and its dependencies - node 6 is too old for anything else to work + run( + 'yarn test --scope="@sentry/core" --scope="@sentry/hub" --scope="@sentry/minimal" --scope="@sentry/node" --scope="@sentry/utils" --scope="@sentry/tracing"' + ); +} else if (nodeVersion <= 8) { + // install legacy versions of packages whose current versions don't support node 8 + // ignoring engines and scripts lets us get away with having incompatible things installed for packages we're not testing + run('cd packages/tracing && yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x'); + run('cd packages/utils && yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x'); + + // ember tests happen separately, and the rest fail on node 8 for various syntax or dependency reasons + run( + 'yarn test --ignore="@sentry/ember" --ignore="@sentry-internal/eslint-plugin-sdk" --ignore="@sentry/react" --ignore="@sentry/wasm" --ignore="@sentry/gatsby" --ignore="@sentry/serverless" --ignore="@sentry/nextjs"' + ); +} else { + if (process.platform === 'win32') { + run('yarn test --ignore="@sentry/ember" --ignore="@sentry/nextjs"'); + } else { + run('yarn test --ignore="@sentry/ember"'); + } +} + +process.exit(0); diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 82ef3f3ac4fd..000000000000 --- a/scripts/test.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -e - -# control which packages we test on each version of node -if [[ "$(cut -d. -f1 <<<"$NODE_VERSION")" -le 6 ]]; then - - # install legacy versions of packages whose current versions don't support node 6 - # ignoring engines and scripts lets us get away with having incompatible things installed for packages we're not testing - cd packages/node - yarn add --dev --ignore-engines --ignore-scripts nock@10.x - cd ../.. - cd packages/tracing - yarn add --dev --ignore-engines --ignore-scripts jsdom@11.x - cd ../.. - cd packages/utils - yarn add --dev --ignore-engines --ignore-scripts jsdom@11.x - cd ../.. - - # only test against @sentry/node and its dependencies - node 6 is too old for anything else to work - yarn test --scope="@sentry/core" --scope="@sentry/hub" --scope="@sentry/minimal" --scope="@sentry/node" --scope="@sentry/utils" --scope="@sentry/tracing" - -elif [[ "$(cut -d. -f1 <<<"$NODE_VERSION")" -le 8 ]]; then - - # install legacy versions of packages whose current versions don't support node 8 - # ignoring engines and scripts lets us get away with having incompatible things installed for packages we're not testing - cd packages/tracing - yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x - cd ../.. - cd packages/utils - yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x - cd ../.. - - # ember tests happen separately, and the rest fail on node 8 for various syntax or dependency reasons - yarn test --ignore="@sentry/ember" --ignore="@sentry-internal/eslint-plugin-sdk" --ignore="@sentry/react" --ignore="@sentry/wasm" --ignore="@sentry/gatsby" --ignore="@sentry/serverless" --ignore="@sentry/nextjs" - -else - yarn test --ignore="@sentry/ember" - -fi