Unverified Commit 30a7204c authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

chore(Next.js sync): open draft PRs immediately (#82424)

Before:
Cron runs would open a Draft PR if they happened to run before
deployment tests finished. Once deployment tests completed, the system
would either open a PR and immediately close it (if tests failed) or
open it as ready for review (if tests passed).

After:
Both cron runs and new releases will open Draft PRs. Once deployment
tests run and pass, these PRs will be marked as ready for review. If
tests fail, the PRs remain as drafts.

Related PRS:
https://github.com/vercel/v0/pull/12992
https://github.com/vercel/front/pull/50036
parent 2ba4a854
...@@ -32,6 +32,8 @@ jobs: ...@@ -32,6 +32,8 @@ jobs:
setup: setup:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.repository_owner == 'vercel' if: github.repository_owner == 'vercel'
outputs:
next-version: ${{ steps.version.outputs.value }}
steps: steps:
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
...@@ -49,6 +51,19 @@ jobs: ...@@ -49,6 +51,19 @@ jobs:
with: with:
fetch-depth: 25 fetch-depth: 25
- id: nextPackageInfo
name: Get `next` package info
run: |
cd packages/next
{
echo 'value<<EOF'
cat package.json
echo EOF
} >> "$GITHUB_OUTPUT"
- id: version
name: Extract `next` version
run: echo 'value=${{ fromJson(steps.nextPackageInfo.outputs.value).version }}' >> "$GITHUB_OUTPUT"
- name: Setup test project - name: Setup test project
run: | run: |
pnpm install pnpm install
...@@ -56,7 +71,7 @@ jobs: ...@@ -56,7 +71,7 @@ jobs:
node scripts/run-e2e-test-project-reset.mjs node scripts/run-e2e-test-project-reset.mjs
test-deploy: test-deploy:
name: test deploy name: Run Deploy Tests
needs: setup needs: setup
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
secrets: inherit secrets: inherit
...@@ -77,7 +92,7 @@ jobs: ...@@ -77,7 +92,7 @@ jobs:
if: ${{ always() }} if: ${{ always() }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: report test results to datadog name: Report test results to datadog
steps: steps:
- name: Download test report artifacts - name: Download test report artifacts
id: download-test-reports id: download-test-reports
...@@ -93,9 +108,79 @@ jobs: ...@@ -93,9 +108,79 @@ jobs:
DD_ENV=ci npx @datadog/datadog-ci@2.23.1 junit upload --tags test.type:deploy --service nextjs ./test/test-junit-report DD_ENV=ci npx @datadog/datadog-ci@2.23.1 junit upload --tags test.type:deploy --service nextjs ./test/test-junit-report
fi fi
sync-repositories: create-draft-prs:
needs: test-deploy name: Immediately open draft prs
if: ${{ always() && github.repository_owner == 'vercel' && github.event_name == 'release' }} needs: setup
if: ${{ github.repository_owner == 'vercel' && github.event_name == 'release' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- repo: front
workflow_id: cron-update-next.yml
- repo: v0
workflow_id: update-next.yml
steps:
- name: Check token
run: gh auth status
env:
GITHUB_TOKEN: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
- uses: actions/github-script@v7
name: Check if target workflow is enabled
id: check-workflow-enabled
with:
retries: 3
retry-exempt-status-codes: 400,401,403,404,422
github-token: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
result-encoding: string
script: |
const response = await github.request(
"GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}",
{
owner: "vercel",
repo: "${{ matrix.repo }}",
workflow_id: "${{ matrix.workflow_id }}",
}
);
const isEnabled = response.data.state === 'active';
console.info(`Target workflow state: ${response.data.state}`);
console.info(`Target workflow enabled: ${isEnabled}`);
return isEnabled ? 'true' : 'false';
- uses: actions/github-script@v7
name: Create draft PR for vercel/${{ matrix.repo }}
id: create-draft-pr
if: steps.check-workflow-enabled.outputs.result == 'true'
with:
retries: 3
retry-exempt-status-codes: 400,401,404
github-token: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
result-encoding: string
script: |
const inputs = {
version: "${{ needs.setup.outputs.next-version }}"
};
await github.request(
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
{
owner: "vercel",
repo: "${{ matrix.repo }}",
workflow_id: "${{ matrix.workflow_id }}",
ref: "main",
inputs: inputs,
}
);
console.info(`Draft PR creation triggered for ${{ matrix.repo }}`);
console.info(`Workflow will create draft PR by default`);
update-prs:
name: Update prs as ready for review
needs: [test-deploy, create-draft-prs]
if: ${{ needs.test-deploy.result == 'success' && github.repository_owner == 'vercel' && github.event_name == 'release' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
...@@ -108,22 +193,6 @@ jobs: ...@@ -108,22 +193,6 @@ jobs:
workflow_id: update-next.yml workflow_id: update-next.yml
workflow_url: https://github.com/vercel/v0/actions/workflows/update-next.yml?query=event%3Aworkflow_dispatch workflow_url: https://github.com/vercel/v0/actions/workflows/update-next.yml?query=event%3Aworkflow_dispatch
steps: steps:
- uses: actions/checkout@v4
- id: nextPackageInfo
name: Get `next` package info
run: |
cd packages/next
{
echo 'value<<EOF'
cat package.json
echo EOF
} >> "$GITHUB_OUTPUT"
- id: version
name: Extract `next` version
run: echo 'value=${{ fromJson(steps.nextPackageInfo.outputs.value).version }}' >> "$GITHUB_OUTPUT"
- id: test-result
name: Set test result variable
run: echo 'immediately-close=${{ needs.test-deploy.result != 'success' && 'true' || 'false' }}' >> "$GITHUB_OUTPUT"
- name: Check token - name: Check token
run: gh auth status run: gh auth status
env: env:
...@@ -157,8 +226,8 @@ jobs: ...@@ -157,8 +226,8 @@ jobs:
return 'false'; return 'false';
} }
- uses: actions/github-script@v7 - uses: actions/github-script@v7
name: Trigger vercel/${{ matrix.repo }} sync name: Mark PR ready for review in vercel/${{ matrix.repo }}
id: trigger-sync id: mark-pr-ready
if: steps.check-workflow-enabled.outputs.result == 'true' if: steps.check-workflow-enabled.outputs.result == 'true'
with: with:
retries: 3 retries: 3
...@@ -169,15 +238,12 @@ jobs: ...@@ -169,15 +238,12 @@ jobs:
# Note `workflow_id` and `inputs` are contract between vercel/${{ matrix.repo }}, # Note `workflow_id` and `inputs` are contract between vercel/${{ matrix.repo }},
# if these need to be changed both side should be updated accordingly. # if these need to be changed both side should be updated accordingly.
script: | script: |
const immediatelyClose = '${{ steps.test-result.outputs.immediately-close }}';
const inputs = { const inputs = {
version: "${{ steps.version.outputs.value }}", version: "${{ needs.setup.outputs.next-version }}",
'make-ready-for-review': 'true',
force: 'true'
}; };
if (immediatelyClose === 'true') {
inputs['immediately-close'] = 'true';
}
await github.request( await github.request(
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches", "POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
{ {
...@@ -188,16 +254,8 @@ jobs: ...@@ -188,16 +254,8 @@ jobs:
inputs: inputs, inputs: inputs,
} }
); );
// Ideally we'd include a URL to this specific sync.
// However, creating a workflow_dispatch event does not produce an ID: https://github.com/orgs/community/discussions/9752 console.info("Tests passed - PR will be marked ready for review");
console.info(
"Sync started in ${{ matrix.workflow_url }}"
);
console.info( console.info(
"This may not start a new sync if one is already in progress. Check the logs of the workflow run." "PR ready-for-review triggered in ${{ matrix.workflow_url }}"
); );
if (immediatelyClose === 'true') {
console.info(
"Sync triggered with immediately-close=true due to test failure."
);
}
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