Unverified Commit 1849a0d0 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

[ci]: move stats & CI status comment to workflow (#93220)

- Add a workflow_run reporter that posts PR test/stats comments using
`GITHUB_TOKEN`.
- Upload PR metadata artifacts from `build-and-test` and `Generate
Stats` so the reporter can safely resolve the target PR
- Move stats/test comment posting out of the external webhook/PAT path
while preserving the existing comment format

This means the test comment won't incrementally update as tests fail,
it'll just post once at the end, but that's a reasonable tradeoff to not
having to worry about a webhook.
parent 7267ceee
......@@ -63,6 +63,50 @@ 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-native:
name: build-native
uses: ./.github/workflows/build_reusable.yml
......
name: PR CI Comment
on:
workflow_run:
workflows: ['build-and-test', 'Generate Stats']
types: [completed]
permissions:
actions: read
contents: read
issues: write
pull-requests: read
jobs:
comment:
name: Comment on PR
if: ${{ github.event.workflow_run.event == 'pull_request' && github.repository == 'vercel/next.js' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Download PR metadata
continue-on-error: true
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-ci-metadata
path: pr-ci-metadata
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
run: node scripts/pr-ci-comment.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
......@@ -34,6 +34,50 @@ env:
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:
uses: ./.github/workflows/build_reusable.yml
secrets: inherit
......@@ -74,7 +118,6 @@ jobs:
with:
bundler: ${{ matrix.bundler }}
env:
PR_STATS_COMMENT_TOKEN: ${{ secrets.PR_STATS_COMMENT_TOKEN }}
TURBO_TEAM: ${{ env.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_CACHE: ${{ env.TURBO_CACHE }}
......@@ -125,6 +168,5 @@ jobs:
working-directory: .github/actions/next-stats-action
run: node src/aggregate-results.js ${{ github.workspace }}/stats-results
env:
PR_STATS_COMMENT_TOKEN: ${{ secrets.PR_STATS_COMMENT_TOKEN }}
KV_REST_API_URL: ${{ secrets.KV_REST_API_URL }}
KV_REST_API_TOKEN: ${{ secrets.KV_REST_API_TOKEN }}
This diff is collapsed.
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