Unverified Commit 14f9c1ac authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[16.3.x][ci] Run flake detection and new deploy tests when merged and on backport branches (#98018)

Backports https://github.com/vercel/next.js/pull/97991
parent 299180d3
...@@ -54,7 +54,11 @@ jobs: ...@@ -54,7 +54,11 @@ jobs:
steps: steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with: with:
fetch-depth: 1 # Changing the checked out ref has wide implications:
# Be aware that all git-diff operations in the repo rely on the
# default behavior of GitHub actions (ref on push, merge-commit on PR).
# 2 last commits so that we can create a diff with HEAD~1
fetch-depth: 2
persist-credentials: false persist-credentials: false
- run: echo "${{ github.event.after }}" - run: echo "${{ github.event.after }}"
- name: Setup node - name: Setup node
......
...@@ -734,9 +734,7 @@ jobs: ...@@ -734,9 +734,7 @@ jobs:
test-new-tests-dev: test-new-tests-dev:
name: Test new and changed tests for flakes (dev) name: Test new and changed tests for flakes (dev)
needs: ['optimize-ci', 'changes', 'build-native', 'build-next'] needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
# test-new-tests-if if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
if: false
# test-new-tests-end-if
strategy: strategy:
fail-fast: false fail-fast: false
...@@ -764,9 +762,7 @@ jobs: ...@@ -764,9 +762,7 @@ jobs:
test-new-tests-start: test-new-tests-start:
name: Test new and changed tests for flakes (prod) name: Test new and changed tests for flakes (prod)
needs: ['optimize-ci', 'changes', 'build-native', 'build-next'] needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
# test-new-tests-if if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
if: false
# test-new-tests-end-if
strategy: strategy:
fail-fast: false fail-fast: false
...@@ -803,9 +799,7 @@ jobs: ...@@ -803,9 +799,7 @@ jobs:
needs: ['optimize-ci', 'changes'] needs: ['optimize-ci', 'changes']
# `docs-only` and `is-release` mirror the cases where `build-and-deploy` # `docs-only` and `is-release` mirror the cases where `build-and-deploy`
# resolves its deploy target to `skipped` and never publishes a tarball. # resolves its deploy target to `skipped` and never publishes a tarball.
# test-new-tests-if if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' && needs.changes.outputs.is-release == 'false' }}
if: false
# test-new-tests-end-if
runs-on: ubuntu-latest runs-on: ubuntu-latest
# Outer bound only. The script gives up first, so a tarball that never # Outer bound only. The script gives up first, so a tarball that never
# arrives is reported by it rather than by the runner killing the job. # arrives is reported by it rather than by the runner killing the job.
...@@ -839,9 +833,7 @@ jobs: ...@@ -839,9 +833,7 @@ jobs:
test-new-tests-deploy: test-new-tests-deploy:
name: Test new and changed tests when deployed name: Test new and changed tests when deployed
needs: ['optimize-ci', 'changes', 'wait-for-preview-tarball'] needs: ['optimize-ci', 'changes', 'wait-for-preview-tarball']
# test-new-tests-if if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
if: false
# test-new-tests-end-if
strategy: strategy:
fail-fast: false fail-fast: false
...@@ -873,9 +865,7 @@ jobs: ...@@ -873,9 +865,7 @@ jobs:
test-new-tests-deploy-cache-components: test-new-tests-deploy-cache-components:
name: Test new and changed tests when deployed (cache components) name: Test new and changed tests when deployed (cache components)
needs: ['optimize-ci', 'changes', 'wait-for-preview-tarball'] needs: ['optimize-ci', 'changes', 'wait-for-preview-tarball']
# test-new-tests-if if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
if: false
# test-new-tests-end-if
strategy: strategy:
fail-fast: false fail-fast: false
......
...@@ -176,6 +176,9 @@ jobs: ...@@ -176,6 +176,9 @@ jobs:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with: with:
# Changing the checked out ref has wide implications:
# Be aware that all git-diff operations in the repo rely on the
# default behavior of GitHub actions (ref on push, merge-commit on PR).
fetch-depth: 25 fetch-depth: 25
persist-credentials: false persist-credentials: false
......
...@@ -81,12 +81,6 @@ async function main() { ...@@ -81,12 +81,6 @@ async function main() {
.replace(`['canary']`, `['${branchName}']`) .replace(`['canary']`, `['${branchName}']`)
.replace(/[\s]{1,}('test-new-tests-.+',)/g, '') .replace(/[\s]{1,}('test-new-tests-.+',)/g, '')
buildAndTest = buildAndTest.replace(
/(^[ \t]*)# test-new-tests-if\n(^[ \t]*)if:.*\n(^[ \t]*)# test-new-tests-end-if/gm,
(_, indent1, indent2, indent3) =>
`${indent1}# test-new-tests-if\n${indent2}if: false\n${indent3}# test-new-tests-end-if`
)
await fs.promises.writeFile(buildAndTestPath, buildAndTest) await fs.promises.writeFile(buildAndTestPath, buildAndTest)
await execa(`git add .`, { await execa(`git add .`, {
......
...@@ -110,7 +110,7 @@ export function getDeployManifestChangedTests( ...@@ -110,7 +110,7 @@ export function getDeployManifestChangedTests(
} }
/** /**
* Detects changed tests files by comparing the current branch with `origin/canary` * Detects changed (see {@link getDiffRevision}) tests files.
* Returns tests separated by test mode (dev/prod), as well as the corresponding commit hash * Returns tests separated by test mode (dev/prod), as well as the corresponding commit hash
* that the current branch is pointing to * that the current branch is pointing to
*/ */
...@@ -118,12 +118,7 @@ export default async function getChangedTests() { ...@@ -118,12 +118,7 @@ export default async function getChangedTests() {
/** @type import('execa').Options */ /** @type import('execa').Options */
const EXECA_OPTS = { shell: true } const EXECA_OPTS = { shell: true }
const { branchName, remoteUrl, commitSha, isCanary } = await getGitInfo() const { branchName, remoteUrl, commitSha } = await getGitInfo()
if (isCanary) {
console.log(`Skipping flake detection for canary`)
return { devTests: [], prodTests: [], deployTests: [], commitSha }
}
const diffRevision = await getDiffRevision() const diffRevision = await getDiffRevision()
...@@ -138,7 +133,6 @@ export default async function getChangedTests() { ...@@ -138,7 +133,6 @@ export default async function getChangedTests() {
{ {
branchName, branchName,
remoteUrl, remoteUrl,
isCanary,
commitSha, commitSha,
}, },
`\ngit diff:\n${changesResult.stderr}\n${changesResult.stdout}` `\ngit diff:\n${changesResult.stderr}\n${changesResult.stdout}`
......
...@@ -7,7 +7,7 @@ const exec = promisify(execOrig) ...@@ -7,7 +7,7 @@ const exec = promisify(execOrig)
/** /**
* Gets git repository information from the environment * Gets git repository information from the environment
* @returns {Promise<{branchName: string, remoteUrl: string, commitSha: string, isCanary: boolean}>} * @returns {Promise<{branchName: string, remoteUrl: string, commitSha: string}>}
*/ */
export async function getGitInfo() { export async function getGitInfo() {
let eventData = {} let eventData = {}
...@@ -34,10 +34,7 @@ export async function getGitInfo() { ...@@ -34,10 +34,7 @@ export async function getGitInfo() {
process.env.GITHUB_SHA || process.env.GITHUB_SHA ||
(await exec('git rev-parse HEAD')).stdout.trim() (await exec('git rev-parse HEAD')).stdout.trim()
const isCanary = return { branchName, remoteUrl, commitSha }
branchName === 'canary' && remoteUrl.includes('vercel/next.js')
return { branchName, remoteUrl, commitSha, isCanary }
} }
/** /**
...@@ -45,19 +42,23 @@ export async function getGitInfo() { ...@@ -45,19 +42,23 @@ export async function getGitInfo() {
* @returns {Promise<string>} The git revision to diff against * @returns {Promise<string>} The git revision to diff against
*/ */
export async function getDiffRevision() { export async function getDiffRevision() {
if ( if (process.env.GITHUB_ACTIONS === 'true') {
process.env.GITHUB_ACTIONS === 'true' && const eventName = process.env.GITHUB_EVENT_NAME
process.env.GITHUB_EVENT_NAME === 'pull_request' switch (eventName) {
) { // GH Actions for `pull_request` run on the merge commit by default so HEAD~1:
// GH Actions for `pull_request` run on the merge commit so HEAD~1: // 1. includes all changes in the PR
// 1. includes all changes in the PR // e.g. in
// e.g. in // A-B-C-main - F
// A-B-C-main - F // \ /
// \ / // D-E-branch
// D-E-branch // GH actions for `branch` runs on F, so a diff for HEAD~1 includes the diff of D and E combined
// GH actions for `branch` runs on F, so a diff for HEAD~1 includes the diff of D and E combined // 2. Includes all changes of the commit for pushes (assuming the push event is from a squash merge)
// 2. Includes all changes of the commit for pushes case 'pull_request':
return 'HEAD~1' case 'push':
return 'HEAD~1'
default:
throw new Error(`Unsupported GITHUB_EVENT_NAME: ${eventName}`)
}
} else { } else {
try { try {
await exec('git remote set-branches --add origin canary') await exec('git remote set-branches --add origin canary')
......
...@@ -58,7 +58,7 @@ const CHANGE_ITEM_GROUPS = { ...@@ -58,7 +58,7 @@ const CHANGE_ITEM_GROUPS = {
} }
async function main() { async function main() {
const { branchName, remoteUrl, isCanary } = await getGitInfo() const { branchName, remoteUrl } = await getGitInfo()
const diffRevision = await getDiffRevision() const diffRevision = await getDiffRevision()
const changesResult = await exec( const changesResult = await exec(
...@@ -68,7 +68,7 @@ async function main() { ...@@ -68,7 +68,7 @@ async function main() {
return { stdout: '' } return { stdout: '' }
}) })
console.error({ branchName, remoteUrl, isCanary, changesResult }) console.error({ branchName, remoteUrl, changesResult })
const changedFilesOutput = changesResult.stdout const changedFilesOutput = changesResult.stdout
const typeIndex = process.argv.indexOf('--type') const typeIndex = process.argv.indexOf('--type')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment