Unverified Commit f37c1d65 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

[16.3.x] ci: remove pull_request_stats workflow (#97975)

Backport https://github.com/vercel/next.js/pull/97792
parent a9a1cb78
......@@ -2,7 +2,7 @@ name: PR CI Comment
on:
workflow_run:
workflows: ['build-and-test', 'Generate Stats']
workflows: ['build-and-test']
types: [requested, completed]
permissions:
......
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- canary
name: Generate Stats
concurrency:
# Keep cancel-on-update behavior for PRs, but allow canary pushes to run independently.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
NAPI_CLI_VERSION: 2.18.4
TURBO_VERSION: 2.9.4
TEST_CONCURRENCY: 6
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
# Prefer shared remote cache across runs, but keep local cache enabled so jobs
# degrade gracefully if the remote cache or token is unavailable.
TURBO_CACHE: 'local:rw,remote:rw'
NEXT_TELEMETRY_DISABLED: 1
# Vercel KV Store for test timings
KV_REST_API_URL: ${{ secrets.KV_REST_API_URL }}
KV_REST_API_TOKEN: ${{ secrets.KV_REST_API_TOKEN }}
NEXT_TEST_JOB: 1
NEXT_DISABLE_SWC_WASM: 1
jobs:
pr-ci-metadata:
name: Upload PR CI metadata
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Write PR metadata
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
run: |
mkdir -p pr-ci-metadata
node <<'NODE'
const fs = require('fs')
fs.writeFileSync(
'pr-ci-metadata/pr.json',
JSON.stringify(
{
number: Number(process.env.PR_NUMBER),
headSha: process.env.PR_HEAD_SHA,
headRef: process.env.PR_HEAD_REF,
headRepo: process.env.PR_HEAD_REPO,
baseRef: process.env.PR_BASE_REF,
isFork: process.env.PR_IS_FORK === 'true',
},
null,
2
)
)
NODE
- name: Upload PR metadata
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-ci-metadata
path: pr-ci-metadata/pr.json
retention-days: 1
build:
permissions:
contents: read
id-token: write
uses: ./.github/workflows/build_reusable.yml
secrets: inherit
with:
stepName: 'generate-pull-request-stats'
uploadSwcArtifact: 'yes'
uploadAnalyzerArtifacts: 'yes'
stats:
name: Stats (${{ matrix.bundler }})
needs: build
# The webpack benchmark alone takes ~25 minutes, so anything at or below
# that cancels the job right as it finishes (seen on canary and PRs alike).
timeout-minutes: 35
strategy:
fail-fast: false
matrix:
# Keep in sync with STATS_EXPECTED_BUNDLERS
bundler: [webpack, turbopack]
runs-on: ubuntu-latest-16-core-arm-oss
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 25
persist-credentials: false
- name: Check non-docs only change
run: echo "DOCS_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.mjs --not --type docs --exec echo 'nope')" >> $GITHUB_OUTPUT; echo 'EOF' >> $GITHUB_OUTPUT
id: docs-change
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
name: next-swc-binary-${{ runner.os }}-${{ runner.arch }}
path: packages/next-swc/native
- run: cp -r packages/next-swc/native .github/actions/next-stats-action/native
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
- name: Set up Turborepo remote cache
if: ${{ vars.TURBO_TEAM != '' }}
continue-on-error: true
uses: vercel/setup-turborepo-remote-cache-action@135046f5efcadb17337d9b29b8d5b4035ae64b10 # v1.0.0
with:
team: ${{ vars.TURBO_TEAM }}
# `TURBO_TOKEN` reaches this Docker action through the job environment.
- uses: ./.github/actions/next-stats-action
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
bundler: ${{ matrix.bundler }}
env:
TURBO_TEAM: ${{ env.TURBO_TEAM }}
TURBO_CACHE: ${{ env.TURBO_CACHE }}
PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
- name: Upload stats results
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-stats-${{ matrix.bundler }}
path: pr-stats-${{ matrix.bundler }}.json
retention-days: 1
stats-aggregate:
name: Aggregate Stats
needs: stats
# Always run so we can recover partial results. A single bundler timing out
# cancels its job, which makes `cancelled()` true here and marks the whole
# run "cancelled" even though the other bundler finished, so `!cancelled()`
# would wrongly skip aggregation. Running unconditionally lets us aggregate
# whatever bundlers succeeded; the reason a bundler is missing is reported in
# the comment, and a truly cancelled run (no results at all) is handled by
# the cancelled fallback in scripts/pr-ci-comment.mjs.
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 25
persist-credentials: false
- name: Check non-docs only change
run: echo "DOCS_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.mjs --not --type docs --exec echo 'nope')" >> $GITHUB_OUTPUT; echo 'EOF' >> $GITHUB_OUTPUT
id: docs-change
- name: Download all stats artifacts
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: pr-stats-*
path: stats-results
merge-multiple: true
- name: Setup Node.js
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version
package-manager-cache: false
- name: Install dependencies
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
working-directory: .github/actions/next-stats-action
run: npm install
- name: Aggregate and post results
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
working-directory: .github/actions/next-stats-action
run: node src/aggregate-results.js ${{ github.workspace }}/stats-results
env:
KV_REST_API_URL: ${{ secrets.KV_REST_API_URL }}
KV_REST_API_TOKEN: ${{ secrets.KV_REST_API_TOKEN }}
# Keep in sync with the `stats` job matrix above. The aggregate uses it
# to detect and report bundlers whose job failed or was cancelled
# (their pr-stats-<bundler>.json artifact will be missing).
STATS_EXPECTED_BUNDLERS: 'webpack turbopack'
# Collapsed matrix result ('success' | 'failure' | 'cancelled' |
# 'skipped'). Used to decide, when no artifacts exist at all, whether
# the bundlers genuinely failed (post an "all failed" notice) or the
# run was cancelled/superseded (stay silent and let pr-ci-comment.mjs
# post the cancelled notice).
STATS_RESULT: ${{ needs.stats.result }}
......@@ -6,7 +6,6 @@ import path from 'node:path'
import { buildTestReport } from './test-report.js'
const TEST_COMMENT_MARKER = '<!-- __NEXT_TEST_REPORT_COMMENT__ -->'
const STATS_COMMENT_MARKER = '<!-- __NEXT_STATS_COMMENT__ -->'
const MAX_COMMENT_LENGTH = 62_000
const MAX_RESULT_MESSAGE_LENGTH = 12_000
......@@ -296,11 +295,6 @@ async function main() {
return
}
if (workflowRun.name === 'Generate Stats') {
await handleStatsWorkflow({ github, workflowRun, pr, phase })
return
}
if (workflowRun.name === 'build-and-test') {
await handleBuildAndTestWorkflow({
github,
......@@ -457,115 +451,6 @@ async function readPullRequestMetadataArtifact() {
}
}
async function handleStatsWorkflow({ github, workflowRun, pr, phase }) {
if (phase === 'requested') {
const sha = pr.headSha || workflowRun.head_sha
const body = [
STATS_COMMENT_MARKER,
'## Stats in progress',
'',
`Commit: ${sha}`,
`[View workflow run](${workflowRun.html_url})`,
'',
].join('\n')
await github.insertIssueCommentIfMissing(
pr.number,
STATS_COMMENT_MARKER,
body,
['## Stats from current PR']
)
return
}
// Look for a stats block before reacting to the run conclusion. A single
// bundler timing out cancels its job and marks the whole run "cancelled", but
// the aggregate still emits stats for the bundlers that finished. Treating a
// cancelled run as "no data" up front would discard that partial comment, so
// we post whatever the aggregate produced first and only fall back to a
// cancelled/skipped notice when there is genuinely no block.
const jobs = await github.listJobsForRunAttempt(
workflowRun.id,
workflowRun.run_attempt || 1
)
const candidates = jobs.filter((job) => /aggregate stats/i.test(job.name))
for (const job of candidates) {
let logs
try {
logs = await github.downloadJobLogs(job.id)
} catch (err) {
// A cancelled or skipped aggregate job may have no retrievable logs.
console.log(`Failed to download logs for job ${job.id}`, err)
continue
}
const stats = extractDelimitedBlock(
logs,
'--stats start--',
'--stats end--'
)
if (!stats) {
continue
}
let body = stats
.replace('âš ï¸', '\u26a0\ufe0f')
.replace('✓', '\u2713')
.trim()
if (!body.includes(STATS_COMMENT_MARKER)) {
body = `${STATS_COMMENT_MARKER}\n${body}`
}
body += `\n\nCommit: ${pr.headSha || workflowRun.head_sha}`
await github.upsertIssueComment(pr.number, STATS_COMMENT_MARKER, body, [
'## Stats from current PR',
])
return
}
const sha = pr.headSha || workflowRun.head_sha
// No stats block. A cancelled conclusion here means the whole run was
// cancelled (superseded, or every bundler cancelled) rather than an
// individual bundler, since a partial run would have produced a block above.
if (workflowRun.conclusion === 'cancelled') {
console.log('No stats block found and the run was cancelled.')
const body = [
STATS_COMMENT_MARKER,
'## Stats cancelled',
'',
`Commit: ${sha}`,
`[View workflow run](${workflowRun.html_url})`,
'',
].join('\n')
await github.upsertIssueComment(pr.number, STATS_COMMENT_MARKER, body, [
'## Stats from current PR',
])
return
}
console.log(
'No stats block found in the completed stats workflow. Assuming stats were skipped.'
)
const body = [
STATS_COMMENT_MARKER,
'## Stats skipped',
'',
`Commit: ${sha}`,
`[View workflow run](${workflowRun.html_url})`,
'',
].join('\n')
await github.upsertIssueComment(pr.number, STATS_COMMENT_MARKER, body, [
'## Stats from current PR',
])
}
async function handleBuildAndTestWorkflow({
github,
workflowRun,
......@@ -716,21 +601,6 @@ function extractJsonBlocks(logs) {
return blocks
}
function extractDelimitedBlock(logs, start, end) {
const startIndex = logs.indexOf(start)
if (startIndex === -1) {
return null
}
const contentStart = startIndex + start.length
const endIndex = logs.indexOf(end, contentStart)
if (endIndex === -1) {
return null
}
return logs.slice(contentStart, endIndex).trim()
}
function buildTestReportComment({
failedSuites,
otherFailures,
......
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