Skip to content

Commit

Permalink
Merge branch 'canary' into sokra/update-manifest-4
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored Oct 13, 2023
2 parents 924947b + e0cd065 commit 9327c3b
Show file tree
Hide file tree
Showing 65 changed files with 646 additions and 387 deletions.
39 changes: 25 additions & 14 deletions .github/actions/next-stats-action/src/add-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const shortenLabel = (itemKey) =>
: itemKey

const twoMB = 2 * 1024 * 1024
const ONE_HUNDRED_BYTES = 100
const ONE_HUNDRED_MS = 100

module.exports = async function addComment(
results = [],
Expand Down Expand Up @@ -82,24 +84,21 @@ module.exports = async function addComment(
// otherwise only show gzip values
else if (!isGzipItem && !groupKey.match(gzipIgnoreRegex)) return

if (
!itemKey.startsWith('buildDuration') ||
(isBenchmark && itemKey.match(/req\/sec/))
) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
if (typeof diffItemVal === 'number') diffRepoTotal += diffItemVal
}

// calculate the change
if (mainItemVal !== diffItemVal) {
if (
typeof mainItemVal === 'number' &&
typeof diffItemVal === 'number'
) {
change = round(diffItemVal - mainItemVal, 2)
const roundedValue = round(diffItemVal - mainItemVal, 2)

// check if there is still a change after rounding
if (change !== 0) {
if (
roundedValue !== 0 &&
((prettyType === 'ms' && roundedValue > ONE_HUNDRED_MS) ||
(prettyType === 'bytes' && roundedValue > ONE_HUNDRED_BYTES))
) {
change = roundedValue
const absChange = Math.abs(change)
const warnIfNegative = isBenchmark && itemKey.match(/req\/sec/)
const warn = warnIfNegative
Expand All @@ -112,12 +111,22 @@ module.exports = async function addComment(
change = `${warn}${change < 0 ? '-' : '+'}${
useRawValue ? absChange : prettify(absChange, prettyType)
}`
} else {
change = 'N/A'
}
} else {
change = 'N/A'
}
}

if (
(change !== 'N/A' && !itemKey.startsWith('buildDuration')) ||
(isBenchmark && itemKey.match(/req\/sec/))
) {
if (typeof mainItemVal === 'number') mainRepoTotal += mainItemVal
if (typeof diffItemVal === 'number') diffRepoTotal += diffItemVal
}

groupTable += `| ${
isBenchmark ? itemKey : shortenLabel(itemKey)
} | ${mainItemStr} | ${diffItemStr} | ${change} |\n`
Expand Down Expand Up @@ -169,8 +178,7 @@ module.exports = async function addComment(

// add diffs
if (result.diffs) {
const diffHeading = '#### Diffs\n'
let diffContent = diffHeading
let diffContent = ''

Object.keys(result.diffs).forEach((itemKey) => {
const curDiff = result.diffs[itemKey]
Expand All @@ -187,8 +195,11 @@ module.exports = async function addComment(
diffContent += `\n</details>\n`
})

if (diffContent !== diffHeading) {
if (diffContent.length > 0) {
resultContent += `<details>\n`
resultContent += `<summary><strong>Diff details</strong></summary>\n\n`
resultContent += diffContent
resultContent += `\n</details>\n\n`
}
}
let increaseDecreaseNote = ''
Expand All @@ -199,7 +210,7 @@ module.exports = async function addComment(
increaseDecreaseNote = ' (Decrease detected ✓)'
}

comment += `<details>\n`
comment += `<details open>\n`
comment += `<summary><strong>${result.title}</strong>${increaseDecreaseNote}</summary>\n\n<br/>\n\n`
comment += resultContent
comment += '</details>\n'
Expand Down
47 changes: 46 additions & 1 deletion .github/actions/next-stats-action/src/run/collect-diffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = async function collectDiffs(
`cd ${diffingDir} && git diff --minimal HEAD ${file}`
)
stdout = (stdout.split(file).pop() || '').trim()
if (stdout.length > 0) {
if (stdout.length > 0 && !isLikelyHashOrIDChange(stdout)) {
diffs[fileKey] = stdout
}
} catch (err) {
Expand All @@ -117,3 +117,48 @@ module.exports = async function collectDiffs(
}
return diffs
}

function isLikelyHashOrIDChange(diff) {
const lines = diff.split('\n')
let additions = []
let deletions = []

// Separate additions and deletions
for (const line of lines) {
if (line.startsWith('+')) {
additions.push(line.substring(1).split(/\b/))
} else if (line.startsWith('-')) {
deletions.push(line.substring(1).split(/\b/))
}
}

// If the number of additions and deletions is different, it's not a hash or ID change
if (additions.length !== deletions.length) {
return false
}

// Compare each addition with each deletion
for (let i = 0; i < additions.length; i++) {
const additionTokens = additions[i]
const deletionTokens = deletions[i]

// Identify differing tokens
const differingTokens = additionTokens.filter(
(token, index) => token !== deletionTokens[index]
)

// Analyze differing tokens
for (const token of differingTokens) {
const isLikelyHash = /^[a-f0-9]+$/.test(token)
const isLikelyID = /^[0-9]+$/.test(token)
// this is most likely noise because some path include the repo name, which can be main or diff
const isLikelyNoise = ['main', 'diff'].includes(token)

if (!isLikelyHash && !isLikelyID && !isLikelyNoise) {
return false
}
}
}

return true
}
48 changes: 0 additions & 48 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -463,54 +463,6 @@ jobs:
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
DEPLOY_ENVIRONMENT: production

testDeployE2E:
name: E2E (deploy)
runs-on: ubuntu-latest
needs: [publishRelease]
env:
NEXT_TELEMETRY_DISABLED: 1
VERCEL_TEST_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }}
VERCEL_TEST_TEAM: vtest314-next-e2e-tests
DATADOG_API_KEY: ${{ secrets.DATA_DOG_API_KEY }}
steps:
- uses: actions/cache@v3
timeout-minutes: 5
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}

- run: npm i -g vercel@latest

- uses: actions/download-artifact@v3
with:
name: next-swc-binaries
path: packages/next-swc/native

- run: RESET_VC_PROJECT=true node scripts/reset-vercel-project.mjs
name: Reset test project

- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.35.1-jammy /bin/bash -c "cd /work && NODE_VERSION=${{ env.NODE_LTS_VERSION }} ./scripts/setup-node.sh && corepack enable > /dev/null && DATADOG_TRACE_NEXTJS_TEST=TRUE DATADOG_API_KEY=${DATADOG_API_KEY} DD_ENV=ci VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_CONTINUE_ON_ERROR=1 xvfb-run node run-tests.js --type e2e >> /proc/1/fd/1"
name: Run test/e2e (deploy)

- name: Upload test trace
if: always()
uses: actions/upload-artifact@v3
with:
name: test-trace
if-no-files-found: ignore
retention-days: 2
path: |
test/traces
- name: Upload test trace to datadog
continue-on-error: true
run: |
ls -al ./test
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0 @aws-sdk/property-provider@3
jrm ./nextjs-test-result-junit.xml "test/test-junit-report/**/*.xml"
DD_ENV=ci datadog-ci junit upload --tags test.type:nextjs_deploy_e2e --service nextjs ./nextjs-test-result-junit.xml
releaseStats:
name: Release Stats
runs-on:
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/test_e2e_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: test-e2e-deploy

on:
schedule:
# run every day at midnight
- cron: '0 0 * * *'
# allow triggering manually as well
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
env:
VERCEL_TEST_TOKEN: ${{ secrets.VERCEL_TEST_TOKEN }}
VERCEL_TEST_TEAM: vtest314-next-e2e-tests
DATADOG_API_KEY: ${{ secrets.DATA_DOG_API_KEY }}
NAPI_CLI_VERSION: 2.16.2
TURBO_VERSION: 1.10.9
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
CARGO_PROFILE_RELEASE_LTO: 'true'
TURBO_TEAM: 'vercel'
TURBO_REMOTE_ONLY: 'true'
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_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

strategy:
fail-fast: false
matrix:
group: [1, 2]

steps:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_LTS_VERSION }}
check-latest: true
- run: corepack enable

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

- run: pnpm install

- run: pnpm run build

- run: npm i -g vercel@latest

- uses: actions/download-artifact@v3
with:
name: next-swc-binaries
path: packages/next-swc/native

- run: RESET_VC_PROJECT=true node scripts/reset-vercel-project.mjs
name: Reset test project

- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.35.1-jammy /bin/bash -c "cd /work && NODE_VERSION=${{ env.NODE_LTS_VERSION }} ./scripts/setup-node.sh && corepack enable > /dev/null && DATADOG_TRACE_NEXTJS_TEST=TRUE DATADOG_API_KEY=${DATADOG_API_KEY} DD_ENV=ci VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} NEXT_TEST_CONTINUE_ON_ERROR=1 xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2 -c 2 >> /proc/1/fd/1"
name: Run test/e2e (deploy)

- name: Upload test trace
if: always()
uses: actions/upload-artifact@v3
with:
name: test-trace
if-no-files-found: ignore
retention-days: 2
path: |
test/traces
- name: Upload test trace to datadog
continue-on-error: true
run: |
ls -al ./test
npm install -g junit-report-merger@6.0.2 @datadog/datadog-ci@2.14.0 @aws-sdk/property-provider@3
jrm ./nextjs-test-result-junit.xml "test/test-junit-report/**/*.xml"
DD_ENV=ci datadog-ci junit upload --tags test.type:nextjs_deploy_e2e --service nextjs ./nextjs-test-result-junit.xml
8 changes: 6 additions & 2 deletions .github/workflows/trigger_release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on:
schedule:
# run every day at 23:15
- cron: '15 23 * * *'

workflow_dispatch:
inputs:
releaseType:
Expand Down Expand Up @@ -38,7 +42,7 @@ jobs:
# canary next-swc binaries in the monorepo
NEXT_SKIP_NATIVE_POSTINSTALL: 1

environment: release-${{ github.event.inputs.releaseType }}
environment: release-${{ github.event.inputs.releaseType || 'canary' }}
steps:
- name: Setup node
uses: actions/setup-node@v3
Expand Down Expand Up @@ -73,6 +77,6 @@ jobs:

- run: pnpm run build

- run: node ./scripts/start-release.js --release-type ${{ github.event.inputs.releaseType }} --semver-type ${{ github.event.inputs.semverType }}
- run: node ./scripts/start-release.js --release-type ${{ github.event.inputs.releaseType || 'canary' }} --semver-type ${{ github.event.inputs.semverType }}
env:
RELEASE_BOT_GITHUB_TOKEN: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion contributing/repository/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you get errors, you can run the ESLint and Prettier auto-fix using:
pnpm lint-fix
```

Not all rules can be auto-fixed, those require manual changes.
Not all rules can be auto-fixed, some require manual changes.

If you get a warning by alex, follow the instructions to correct the language.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fetch('https://...', { next: { revalidate: 3600 } })

Alternatively, to revalidate all `fetch` requests in a route segment, you can use the [Segment Config Options](/docs/app/api-reference/file-conventions/route-segment-config).

```jsx filename="layout.js / page.js"
```jsx filename="layout.js | page.js"
export const revalidate = 3600 // revalidate at most every hour
```

Expand Down Expand Up @@ -250,7 +250,7 @@ If an error is thrown while attempting to revalidate data, the last successfully

To opt out of caching for individual `fetch` requests, you can set the `cache` option in `fetch` to `'no-store'`. This will fetch data dynamically, on every request.

```js filename="layout.js / page.js"
```js filename="layout.js | page.js"
fetch('https://...', { cache: 'no-store' })
```

Expand All @@ -262,7 +262,7 @@ If you have multiple `fetch` requests in a route segment (e.g. a Layout or Page)

For example, using `const dynamic = 'force-dynamic'` will cause all data to be fetched at request time, and the segment to be rendered dynamically.

```js filename="layout.js / page.js"
```js filename="layout.js | page.js"
// Add
export const dynamic = 'force-dynamic'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ With both these options, Next.js will automatically generate the relevant `<head

To define static metadata, export a [`Metadata` object](/docs/app/api-reference/functions/generate-metadata#metadata-object) from a `layout.js` or static `page.js` file.

```tsx filename="layout.tsx / page.tsx" switcher
```tsx filename="layout.tsx | page.tsx" switcher
import type { Metadata } from 'next'

export const metadata: Metadata = {
Expand All @@ -32,7 +32,7 @@ export const metadata: Metadata = {
export default function Page() {}
```

```jsx filename="layout.js / page.js" switcher
```jsx filename="layout.js | page.js" switcher
export const metadata = {
title: '...',
description: '...',
Expand Down
Loading

0 comments on commit 9327c3b

Please sign in to comment.