Wat #1656
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Run tests' | |
on: | |
pull_request: | |
branches: [main] | |
schedule: | |
- cron: '0 6 * * *' # Run every day at 6am UTC | |
workflow_dispatch: | |
inputs: | |
versions: | |
description: 'The versions of Next.js to test against (quoted and comma separated)' | |
required: false | |
default: 'latest' | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Check PR labels | |
if: github.event_name == 'pull_request' | |
id: check-labels | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { data: labels } = await github.rest.issues.listLabelsOnIssue({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.payload.pull_request.number, | |
}); | |
return labels.some(label => label.name === 'autorelease: pending' || label.name === 'test all versions'); | |
- name: Set Next.js versions to test | |
id: set-matrix | |
# If this is the nightly build or a release PR then run the full matrix of versions | |
run: | | |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
echo "matrix=${{ github.event.inputs.versions }}" >> $GITHUB_OUTPUT | |
elif [ "${{ github.event_name }}" = "schedule" ] || [ "${{ steps.check-labels.outputs.result }}" = "true" ]; then | |
echo "matrix=[\"latest\", \"canary\"]" >> $GITHUB_OUTPUT | |
else | |
echo "matrix=[\"latest\"]" >> $GITHUB_OUTPUT | |
fi | |
test: | |
needs: setup | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
shard: [6] | |
os: [ubuntu-latest, windows-latest] | |
version: ${{ fromJson(needs.setup.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: 'Install Node' | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
cache: 'npm' | |
cache-dependency-path: '**/package-lock.json' | |
- name: Prefer npm global on windows | |
if: runner.os == 'Windows' | |
# On Windows by default PATH prefers corepack bundled with Node.js | |
# This prepends npm global to PATH to ensure that npm installed global corepack is used instead | |
run: | | |
echo "$(npm config get prefix)" >> "$GITHUB_PATH" | |
shell: bash | |
- name: setup pnpm/yarn | |
run: | | |
# global corepack installation requires --force on Windows, otherwise EEXIST errors occur | |
npm install -g corepack --force | |
corepack enable | |
shell: bash | |
- name: Install Deno | |
uses: denoland/setup-deno@v1 | |
with: | |
# Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/edge-bundler/blob/e55f825bd985d3c92e21d1b765d71e70d5628fba/node/bridge.ts#L17 | |
deno-version: v1.44.4 | |
- name: 'Install dependencies' | |
run: npm ci | |
- name: 'Build' | |
run: npm run build | |
- name: Resolve Next.js version | |
id: resolve-next-version | |
shell: bash | |
run: | | |
RESOLVED_VERSION=$(npm view next@${{ matrix.version }} version) | |
echo "version=$RESOLVED_VERSION" >> $GITHUB_OUTPUT | |
echo "Resolved Next.js version for 'next@${{ matrix.version }}' is '$RESOLVED_VERSION'" | |
- name: Compute Fixtures Cache Key | |
id: fixture-cache-key | |
# Fixtures only need to be rebuilt if either fixture or support files change, | |
# so we're using a hash of the fixtures and support files as the cache key. | |
run: | |
echo "key=$(git ls-files -s tests/fixtures/ tests/utils/ tests/prepare.mjs | git hash-object --stdin)" | |
>> "$GITHUB_OUTPUT" | |
shell: bash | |
- name: Cache Fixtures | |
id: cache-fixtures | |
uses: actions/cache@v4 | |
with: | |
path: tests/fixtures | |
key: | |
integration-fixtures-${{ runner.os }}-${{steps.resolve-next-version.outputs.version}}-${{ | |
steps.fixture-cache-key.outputs.key }} | |
- name: 'Prepare Fixtures' | |
if: steps.cache-fixtures.outputs.cache-hit != 'true' | |
run: npm run pretest | |
env: | |
NEXT_VERSION: ${{ matrix.version }} | |
NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} | |
- name: 'Unit and integration tests' | |
run: npm run test:ci:unit-and-integration -- --shard=${{ matrix.shard }}/8 | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NEXT_VERSION: ${{ matrix.version }} | |
NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} | |
TEMP: ${{ github.workspace }}/.. | |