Skip to content

Commit

Permalink
Add new build and test workflow (#50436)
Browse files Browse the repository at this point in the history
This adds new `build and test` and `build and deploy` workflows in favor
of the existing massive `build, test, and deploy` workflow. Since the
new workflows will use `pull_request_target` this waits to remove the
existing workflow until the new one is tested.

While testing this new workflow flakey behavior in tests have also been
addressed. Along with the new workflow we will also be leveraging new
runners which allow us to run tests against the production binary of
`next-swc` so this avoids slight differences in tests we've seen due to
running against the dev binary.

Furthermore we will have a new flow for allowing workflow runs on PRs
from external forks which will either require a comment be checking a
box approving the run after each change or a label added by the team.

The new flow also no longer relies on `actions/cache` or similar which
have proven to be pretty unreliable.

Tests runs with the new workflow can be seen here
https://github.com/vercel/next.js/actions/runs/5100673508/jobs/9169416949
  • Loading branch information
ijjk committed May 28, 2023
1 parent fe6bb0a commit a3ab542
Show file tree
Hide file tree
Showing 54 changed files with 1,441 additions and 553 deletions.
430 changes: 430 additions & 0 deletions .github/workflows/build_and_deploy.yml.tmp

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: build-and-test

on:
push:
branches: ['canary']
pull_request_target:
types: [opened, synchronize]

concurrency:
group: ${{ github.ref }}-build-and-test
cancel-in-progress: true

env:
NAPI_CLI_VERSION: 2.14.7
TURBO_VERSION: 1.9.6
RUST_TOOLCHAIN: nightly-2023-03-09
PNPM_VERSION: 7.24.3
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
TEST_CONCURRENCY: 8
# TODO: remove after testing
# NEXT_TEST_CONTINUE_ON_ERROR: 'true'

TURBO_TEAM: 'vercel'
TURBO_REMOTE_ONLY: 'true'
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
NEXT_TELEMETRY_DISABLED: 1
# we build a dev binary for use in CI so skip downloading
# canary next-swc binaries in the monorepo
NEXT_SKIP_NATIVE_POSTINSTALL: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
NEXT_TEST_JOB: 1

jobs:
build:
name: build
uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
secrets: inherit

lint:
name: lint
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
afterBuild: pnpm lint-no-typescript && pnpm check-examples
secrets: inherit

check-types-precompiled:
name: types and precompiled
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
afterBuild: pnpm types-and-precompiled
skipForDocsOnly: 'yes'
secrets: inherit

test-cargo-unit:
name: test cargo unit
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
skipInstallBuild: 'yes'
afterBuild: turbo run test-cargo-unit
secrets: inherit

rust-check:
name: rust check
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
skipInstallBuild: 'yes'
afterBuild: turbo run rust-check
secrets: inherit

test-turbopack-dev:
name: test turbopack dev
needs: ['build']
uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: RUST_BACKTRACE=0 NEXT_EXTERNAL_TESTS_FILTERS="$(pwd)/packages/next-swc/crates/next-dev-tests/tests-manifest.js" __INTERNAL_NEXT_DEV_TEST_TURBO_DEV=TRUE __INTERNAL_CUSTOM_TURBOPACK_BINDINGS="$(pwd)/packages/next-swc/native/next-swc.linux-x64-gnu.node" __INTERNAL_NEXT_DEV_TEST_TURBO_GLOB_MATCH="*" NEXT_E2E_TEST_TIMEOUT=240000 NEXT_TEST_MODE=dev node run-tests.js --type development --timings -c ${TEST_CONCURRENCY}
secrets: inherit

test-next-swc-wasm:
name: test next-swc wasm
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: rustup target add wasm32-unknown-unknown && curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && node ./scripts/normalize-version-bump.js && turbo run build-wasm -- --target nodejs --features tracing/release_max_level_info && git checkout . && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-nodejs && node ./scripts/setup-wasm.mjs && NEXT_TEST_MODE=start TEST_WASM=true node run-tests.js test/integration/production/test/index.test.js test/e2e/streaming-ssr/index.test.ts
secrets: inherit

test-dev:
name: test dev
needs: ['build']
strategy:
fail-fast: false
matrix:
group: [1, 2, 3]

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: NEXT_TEST_MODE=dev node run-tests.js --timings -g ${{ matrix.group }}/3 -c ${TEST_CONCURRENCY} --test-pattern '^(development|e2e|unit)/.*\.test\.(js|jsx|ts|tsx)$'
secrets: inherit

test-prod:
name: test prod
needs: ['build']
strategy:
fail-fast: false
matrix:
group: [1, 2, 3]

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: NEXT_TEST_MODE=start node run-tests.js --timings -g ${{ matrix.group }}/3 -c ${TEST_CONCURRENCY} --test-pattern '^(production|e2e)/.*\.test\.(js|jsx|ts|tsx)$'
secrets: inherit

test-integration:
name: test integration
needs: ['build']
strategy:
fail-fast: false
matrix:
group: [1, 2, 3, 4, 5, 6]

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: node run-tests.js --timings -g ${{ matrix.group }}/6 -c ${TEST_CONCURRENCY} --test-pattern '^(integration)/.*\.test\.(js|jsx|ts|tsx)$'
secrets: inherit

test-firefox-safari:
name: test firefox and safari
needs: ['build']

uses: vercel/next.js/.github/workflows/build_reusable.yml@ijjk/update-ci-workflow
with:
skipForDocsOnly: 'yes'
afterBuild: pnpm playwright install && BROWSER_NAME=firefox node run-tests.js test/integration/production/test/index.test.js && BROWSER_NAME=safari NEXT_TEST_MODE=start node run-tests.js -c 1 test/integration/production/test/index.test.js test/e2e/basepath.test.ts && BROWSER_NAME=safari DEVICE_NAME='iPhone XR' node run-tests.js -c 1 test/production/prerender-prefetch/index.test.ts
secrets: inherit

tests-pass:
needs:
[
'build',
'lint',
'check-types-precompiled',
'test-dev',
'test-prod',
'test-integration',
'test-cargo-unit',
'rust-check',
'test-next-swc-wasm',
'test-turbopack-dev',
]
runs-on: [self-hosted, linux, x64]
name: thank you, next
steps:
- run: echo 'success'
117 changes: 117 additions & 0 deletions .github/workflows/build_reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Build Reusable

on:
workflow_call:
inputs:
afterBuild:
required: false
description: 'additional steps to run'
type: string
skipInstallBuild:
required: false
description: 'whether to skip pnpm install && pnpm build'
type: string
skipForDocsOnly:
required: false
description: 'skip for docs only changes'
type: string
nodeVersion:
required: false
description: 'version of Node.js to use'
type: string
needsNextest:
required: false
description: 'if nextest rust dep is needed'
type: string

env:
NAPI_CLI_VERSION: 2.14.7
TURBO_VERSION: 1.9.6
RUST_TOOLCHAIN: nightly-2023-03-09
PNPM_VERSION: 7.24.3
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
TEST_CONCURRENCY: 8
# TODO: remove after testing
# NEXT_TEST_CONTINUE_ON_ERROR: 'true'

TURBO_TEAM: 'vercel'
TURBO_REMOTE_ONLY: 'true'
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
NEXT_TELEMETRY_DISABLED: 1
# we build a dev binary for use in CI so skip downloading
# canary next-swc binaries in the monorepo
NEXT_SKIP_NATIVE_POSTINSTALL: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
NEXT_TEST_JOB: 1

jobs:
build:
runs-on: [self-hosted, linux, x64]

steps:
- run: fnm install ${{ inputs.nodeVersion || env.NODE_LTS_VERSION }}
- run: fnm use ${{ inputs.nodeVersion || env.NODE_LTS_VERSION }}
- run: node -v
- run: pwd

- name: Install
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.RUST_TOOLCHAIN }}
components: rustfmt, clippy

- name: Install nextest
if: ${{ inputs.needsNextest == 'yes' }}
uses: taiki-e/install-action@nextest

- run: rustc --version

- run: npm i -g yarn "pnpm@${PNPM_VERSION}" "turbo@${TURBO_VERSION}" "@napi-rs/cli@${NAPI_CLI_VERSION}"

- uses: actions/checkout@v3
with:
fetch-depth: 25

# clean up any previous artifacts to avoid hitting disk space limits
- run: git clean -xdf && rm -rf /tmp/next-repo-*; rm -rf /tmp/next-install-* /tmp/yarn-* /tmp/ncc-cache target && cargo clean

- run: echo "DOCS_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')" >> $GITHUB_OUTPUT; echo 'EOF' >> $GITHUB_OUTPUT
name: check docs only change
id: docs-change

# normalize versions before build-native for better cache hits
- run: node scripts/normalize-version-bump.js
name: normalize versions

- run: turbo run build-native-release --summarize true -- --target x86_64-unknown-linux-gnu

# undo normalize version changes for install/build
- run: git checkout .
if: ${{ inputs.skipInstallBuild != 'yes' }}

- run: pnpm store path

- run: pnpm install
if: ${{ inputs.skipInstallBuild != 'yes' }}

- run: pnpm build
if: ${{ inputs.skipInstallBuild != 'yes' }}

- run: pnpm playwright install-deps
if: ${{ inputs.skipInstallBuild != 'yes' }}

- run: pnpm playwright install chromium
if: ${{ inputs.skipInstallBuild != 'yes' }}

- run: turbo run get-test-timings -- --build ${{ github.sha }}

- run: /bin/bash -c "${{ inputs.afterBuild }}"
if: ${{inputs.skipForDocsOnly != 'yes' || steps.docs-change.outputs.DOCS_CHANGE == 'nope'}}

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: turbo run summary
path: .turbo/runs

0 comments on commit a3ab542

Please sign in to comment.