|
| 1 | +name: 'Run tests' |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: [main] |
| 5 | + schedule: |
| 6 | + - cron: '0 6 * * *' # Run every day at 6am UTC |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + versions: |
| 10 | + description: 'The versions of Next.js to test against (quoted and comma separated)' |
| 11 | + required: false |
| 12 | + default: 'latest' |
| 13 | + |
| 14 | +jobs: |
| 15 | + setup: |
| 16 | +
8000
runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 19 | + steps: |
| 20 | + - name: Check PR labels |
| 21 | + if: github.event_name == 'pull_request' |
| 22 | + id: check-labels |
| 23 | + uses: actions/github-script@v7 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + issue_number: context.payload.pull_request.number, |
| 30 | + }); |
| 31 | + return labels.some(label => label.name === 'autorelease: pending' || label.name === 'test all versions'); |
| 32 | + - name: Set Next.js versions to test |
| 33 | + id: set-matrix |
| 34 | + # If this is the nightly build or a release PR then run the full matrix of versions |
| 35 | + run: | |
| 36 | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 37 | + echo "matrix=${{ github.event.inputs.versions }}" >> $GITHUB_OUTPUT |
| 38 | + elif [ "${{ github.event_name }}" = "schedule" ] || [ "${{ steps.check-labels.outputs.result }}" = "true" ]; then |
| 39 | + echo "matrix=[\"latest\", \"canary\", \"14.2.15\", \"13.5.1\"]" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "matrix=[\"latest\"]" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | +
|
| 44 | + e2e: |
| 45 | + needs: setup |
| 46 | + runs-on: ubuntu-latest |
| 47 | + strategy: |
| 48 | + fail-fast: false |
| 49 | + matrix: |
| 50 | + version: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 51 | + shard: [1, 2, 3, 4, 5] |
| 52 | + |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v4 |
| 55 | + - name: 'Install Node' |
| 56 | + uses: actions/setup-node@v4 |
| 57 | + with: |
| 58 | + node-version: '18.x' |
| 59 | + cache: 'npm' |
| 60 | + cache-dependency-path: '**/package-lock.json' |
| 61 | + - uses: oven-sh/setup-bun@v2 |
| 62 | + - name: setup pnpm/yarn |
| 63 | + run: | |
| 64 | + npm install -g corepack |
| 65 | + corepack enable |
| 66 | + shell: bash |
| 67 | + - name: Install Deno |
| 68 | + uses: denoland/setup-deno@v1 |
| 69 | + with: |
| 70 | + # Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20 |
| 71 | + deno-version: v1.46.3 |
| 72 | + - name: 'Install dependencies' |
| 73 | + run: npm ci |
| 74 | + - name: 'Prepare Netlify CLI' |
| 75 | + env: |
| 76 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 77 | + run: | |
| 78 | + # Control netlify-cli as a regular dev dep but expose it globally for test fixtures to use |
| 79 | + npm install -g "netlify-cli@$(npm list --json --depth=0 netlify-cli | jq -r ".dependencies[\"netlify-cli\"].version")" |
| 80 | + npx netlify login |
| 81 | + - name: Get installed Playwright version |
| 82 | + id: playwright-version |
| 83 | + run: echo "version=$(npm view @playwright/test version)" >> $GITHUB_OUTPUT |
| 84 | + - uses: actions/cache@v4 |
| 85 | + id: playwright-cache |
| 86 | + with: |
| 87 | + path: '~/.cache/ms-playwright' |
| 88 | + key: '${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}' |
| 89 | + restore-keys: | |
| 90 | + ${{ runner.os }}-playwright- |
| 91 | + - name: Install Playwright Browsers |
| 92 | + if: steps.playwright-cache.outputs.cache-hit != 'true' |
| 93 | + run: npx playwright install --with-deps |
| 94 | + - name: Resolve Next.js version |
| 95 | + id: resolve-next-version |
| 96 | + shell: bash |
| 97 | + run: | |
| 98 | + RESOLVED_VERSION=$(npm view next@${{ matrix.version }} version) |
| 99 | + echo "version=$RESOLVED_VERSION" >> $GITHUB_OUTPUT |
| 100 | + echo "Resolved Next.js version for 'next@${{ matrix.version }}' is '$RESOLVED_VERSION'" |
| 101 | + - name: Run Playwright tests |
| 102 | + run: npm run test:ci:e2e -- --shard=${{ matrix.shard }}/5 |
| 103 | + env: |
| 104 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 105 | + NEXT_VERSION: ${{ matrix.version }} |
| 106 | + NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} |
| 107 | + - name: Upload blob report to GitHub Actions Artifacts |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + if: always() |
| 110 | + with: |
| 111 | + name: blob-report-${{matrix.version}}-${{ matrix.shard }} |
| 112 | + path: blob-report |
| 113 | + retention-days: 1 |
| 114 | + |
| 115 | + test: |
| 116 | + needs: setup |
| 117 | + strategy: |
| 118 | + fail-fast: false |
| 119 | + matrix: |
| 120 | + shard: [1, 2, 3, 4, 5, 6, 7, 8] |
| 121 | + os: [ubuntu-latest, windows-latest] |
| 122 | + version: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 123 | + exclude: |
| 124 | + - os: windows-latest |
| 125 | + version: '13.5.1' |
| 126 | + - os: windows-latest |
| 127 | + version: '14.2.15' |
| 128 | + runs-on: ${{ matrix.os }} |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + - name: 'Install Node' |
| 132 | + uses: actions/setup-node@v4 |
| 133 | + with: |
| 134 | + node-version: '18.x' |
| 135 | + cache: 'npm' |
| 136 | + cache-dependency-path: '**/package-lock.json' |
| 137 | + - name: Prefer npm global on windows |
| 138 | + if: runner.os == 'Windows' |
| 139 | + # On Windows by default PATH prefers corepack bundled with Node.js |
| 140 | + # This prepends npm global to PATH to ensure that npm installed global corepack is used instead |
| 141 | + run: | |
| 142 | + echo "$(npm config get prefix)" >> "$GITHUB_PATH" |
| 143 | + shell: bash |
| 144 | + - name: setup pnpm/yarn |
| 145 | + run: | |
| 146 | + # global corepack installation requires --force on Windows, otherwise EEXIST errors occur |
| 147 | + npm install -g corepack --force |
| 148 | + corepack enable |
| 149 | + shell: bash |
| 150 | + - name: Install Deno |
| 151 | + uses: denoland/setup-deno@v1 |
| 152 | + with: |
| 153 | + # Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/edge-bundler/blob/e55f825bd985d3c92e21d1b765d71e70d5628fba/node/bridge.ts#L17 |
| 154 | + deno-version: v1.46.3 |
| 155 | + - name: 'Install dependencies' |
| 156 | + run: npm ci |
| 157 | + - name: 'Build' |
| 158 | + run: npm run build |
| 159 | + - name: 'Vendor deno helpers for integration tests' |
| 160 | + run: node tools/vendor-deno-tools.js |
| 161 | + - name: Resolve Next.js version |
| 162 | + id: resolve-next-version |
| 163 | + shell: bash |
| 164 | + run: | |
| 165 | + RESOLVED_VERSION=$(npm view next@${{ matrix.version }} version) |
| 166 | + echo "version=$RESOLVED_VERSION" >> $GITHUB_OUTPUT |
| 167 | + echo "Resolved Next.js version for 'next@${{ matrix.version }}' is '$RESOLVED_VERSION'" |
| 168 | + - name: Compute Fixtures Cache Key |
| 169 | + id: fixture-cache-key |
| 170 | + # Fixtures only need to be rebuilt if either fixture or support files change, |
| 171 | + # so we're using a hash of the fixtures and support files as the cache key. |
| 172 | + run: |
| 173 | + echo "key=$(git ls-files -s tests/fixtures/ tests/utils/ tests/prepare.mjs | git hash-object --stdin)" |
| 174 | + >> "$GITHUB_OUTPUT" |
| 175 | + shell: bash |
| 176 | + - name: Cache Fixtures |
| 177 | + id: cache-fixtures |
| 178 | + uses: actions/cache@v4 |
| 179 | + with: |
| 180 | + path: tests/fixtures |
| 181 | + key: |
| 182 | + integration-fixtures-${{ runner.os }}-${{steps.resolve-next-version.outputs.version}}-${{ |
| 183 | + steps.fixture-cache-key.outputs.key }} |
| 184 | + - name: 'Prepare Fixtures' |
| 185 | + if: steps.cache-fixtures.outputs.cache-hit != 'true' |
| 186 | + run: npm run pretest |
| 187 | + env: |
| 188 | + NEXT_VERSION: ${{ matrix.version }} |
| 189 | + NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} |
| 190 | + - name: 'Unit and integration tests' |
| 191 | + run: npm run test:ci:unit-and-integration -- --shard=${{ matrix.shard }}/8 |
| 192 | + env: |
| 193 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 194 | + NEXT_VERSION: ${{ matrix.version }} |
| 195 | + NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} |
| 196 | + TEMP: ${{ github.workspace }}/.. |
| 197 | + |
| 198 | + smoke: |
| 199 | + if: always() |
| 200 | + needs: setup |
| 201 | + runs-on: ubuntu-latest |
| 202 | + strategy: |
| 203 | + fail-fast: false |
| 204 | + matrix: |
| 205 | + version: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 206 | + steps: |
| 207 | + - uses: actions/checkout@v4 |
| 208 | + - name: 'Install Node' |
| 209 | + uses: actions/setup-node@v4 |
| 210 | + with: |
| 211 | + node-version: '18.x' |
| 212 | + cache: 'npm' |
| 213 | + cache-dependency-path: '**/package-lock.json' |
| 214 | + - name: setup pnpm/yarn |
| 215 | + run: corepack enable |
| 216 | + shell: bash |
| 217 | + - name: Install Deno |
| 218 | + uses: denoland/setup-deno@v1 |
| 219 | + with: |
| 220 | + # Should match the `DENO_VERSION_RANGE` from https://github.com/netlify/build/blob/main/packages/edge-bundler/node/bridge.ts#L20 |
| 221 | + deno-version: v1.46.3 |
| 222 | + - name: 'Install dependencies' |
| 223 | + run: npm ci |
| 224 | + - name: 'Build' |
| 225 | + run: npm run build |
| 226 | + - name: 'Prepare Netlify CLI' |
| 227 | + env: |
| 228 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 229 | + run: | |
| 230 | + # Control netlify-cli as a regular dev dep but expose it globally for test fixtures to use |
| 231 | + npm install -g "netlify-cli@$(npm list --json --depth=0 netlify-cli | jq -r ".dependencies[\"netlify-cli\"].version")" |
| 232 | + npx netlify login |
| 233 | + - name: Resolve Next.js version |
| 234 | + id: resolve-next-version |
| 235 | + shell: bash |
| 236 | + run: | |
| 237 | + RESOLVED_VERSION=$(npm view next@${{ matrix.version }} version) |
| 238 | + echo "version=$RESOLVED_VERSION" >> $GITHUB_OUTPUT |
| 239 | + echo "Resolved Next.js version for 'next@${{ matrix.version }}' is '$RESOLVED_VERSION'" |
| 240 | + - name: 'Smoke tests' |
| 241 | + run: npm run test:ci:smoke |
| 242 | + env: |
| 243 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 244 | + NEXT_VERSION: ${{ matrix.version }} |
| 245 | + NEXT_RESOLVED_VERSION: ${{ steps.resolve-next-version.outputs.version }} |
| 246 | + |
| 247 | + merge-reports: |
| 248 | + if: always() |
| 249 | + needs: [setup,e2e] |
| 250 | + strategy: |
| 251 | + fail-fast: false |
| 252 | + matrix: |
| 253 | + version: ${{ fromJson(needs.setup.outputs.matrix) }} |
| 254 | + |
| 255 | + runs-on: ubuntu-latest |
| 256 | + steps: |
| 257 | + - uses: actions/checkout@v4 |
| 258 | + - uses: actions/setup-node@v4 |
| 259 | + with: |
| 260 | + node-version: 18 |
| 261 | + - name: Install dependencies |
| 262 | + run: npm ci |
| 263 | + |
| 264 | + - name: Download blob reports from GitHub Actions Artifacts |
| 265 | + uses: actions/download-artifact@v4 |
| 266 | + with: |
| 267 | + path: all-blob-reports |
| 268 | + pattern: blob-report-${{ matrix.version }}-* |
| 269 | + merge-multiple: true |
| 270 | + |
| 271 | + - name: Merge reports |
| 272 | + run: | |
| 273 | + npx playwright merge-reports --reporter html ./all-blob-reports |
| 274 | + npx playwright merge-reports --reporter json ./all-blob-reports > merged_reports.json |
| 275 | +
|
| 276 | + - name: Upload HTML report |
| 277 | + uses: actions/upload-artifact@v4 |
| 278 | + with: |
| 279 | + name: html-report-${{ matrix.version }}-attempt-${{ github.run_attempt }} |
| 280 | + path: playwright-report |
| 281 | + retention-days: 14 |
0 commit comments