Skip to content

Commit 30a7204

Browse files
authored
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: vercel/v0#12992 vercel/front#50036
1 parent 2ba4a85 commit 30a7204

File tree

1 file changed

+98
-40
lines changed

1 file changed

+98
-40
lines changed

.github/workflows/test_e2e_deploy_release.yml

Lines changed: 98 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
setup:
3333
runs-on: ubuntu-latest
3434
if: github.repository_owner == 'vercel'
35+
outputs:
36+
next-version: ${{ steps.version.outputs.value }}
3537
steps:
3638
- name: Setup Node.js
3739
uses: actions/setup-node@v4
@@ -49,14 +51,27 @@ jobs:
4951
with:
5052
fetch-depth: 25
5153

54+
- id: nextPackageInfo
55+
name: Get `next` package info
56+
run: |
57+
cd packages/next
58+
{
59+
echo 'value<<EOF'
60+
cat package.json
61+
echo EOF
62+
} >> "$GITHUB_OUTPUT"
63+
- id: version
64+
name: Extract `next` version
65+
run: echo 'value=${{ fromJson(steps.nextPackageInfo.outputs.value).version }}' >> "$GITHUB_OUTPUT"
66+
5267
- name: Setup test project
5368
run: |
5469
pnpm install
5570
pnpm run build
5671
node scripts/run-e2e-test-project-reset.mjs
5772
5873
test-deploy:
59-
name: test deploy
74+
name: Run Deploy Tests
6075
needs: setup
6176
uses: ./.github/workflows/build_reusable.yml
6277
secrets: inherit
@@ -77,7 +92,7 @@ jobs:
7792
if: ${{ always() }}
7893

7994
runs-on: ubuntu-latest
80-
name: report test results to datadog
95+
name: Report test results to datadog
8196
steps:
8297
- name: Download test report artifacts
8398
id: download-test-reports
@@ -93,9 +108,79 @@ jobs:
93108
DD_ENV=ci npx @datadog/datadog-ci@2.23.1 junit upload --tags test.type:deploy --service nextjs ./test/test-junit-report
94109
fi
95110
96-
sync-repositories:
97-
needs: test-deploy
98-
if: ${{ always() && github.repository_owner == 'vercel' && github.event_name == 'release' }}
111+
create-draft-prs:
112+
name: Immediately open draft prs
113+
needs: setup
114+
if: ${{ github.repository_owner == 'vercel' && github.event_name == 'release' }}
115+
runs-on: ubuntu-latest
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
include:
120+
- repo: front
121+
workflow_id: cron-update-next.yml
122+
- repo: v0
123+
workflow_id: update-next.yml
124+
steps:
125+
- name: Check token
126+
run: gh auth status
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
129+
- uses: actions/github-script@v7
130+
name: Check if target workflow is enabled
131+
id: check-workflow-enabled
132+
with:
133+
retries: 3
134+
retry-exempt-status-codes: 400,401,403,404,422
135+
github-token: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
136+
result-encoding: string
137+
script: |
138+
const response = await github.request(
139+
"GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}",
140+
{
141+
owner: "vercel",
142+
repo: "${{ matrix.repo }}",
143+
workflow_id: "${{ matrix.workflow_id }}",
144+
}
145+
);
146+
147+
const isEnabled = response.data.state === 'active';
148+
console.info(`Target workflow state: ${response.data.state}`);
149+
console.info(`Target workflow enabled: ${isEnabled}`);
150+
151+
return isEnabled ? 'true' : 'false';
152+
- uses: actions/github-script@v7
153+
name: Create draft PR for vercel/${{ matrix.repo }}
154+
id: create-draft-pr
155+
if: steps.check-workflow-enabled.outputs.result == 'true'
156+
with:
157+
retries: 3
158+
retry-exempt-status-codes: 400,401,404
159+
github-token: ${{ secrets.GH_UPDATE_NEXT_WORKFLOW_TRIGGER }}
160+
result-encoding: string
161+
script: |
162+
const inputs = {
163+
version: "${{ needs.setup.outputs.next-version }}"
164+
};
165+
166+
await github.request(
167+
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
168+
{
169+
owner: "vercel",
170+
repo: "${{ matrix.repo }}",
171+
workflow_id: "${{ matrix.workflow_id }}",
172+
ref: "main",
173+
inputs: inputs,
174+
}
175+
);
176+
177+
console.info(`Draft PR creation triggered for ${{ matrix.repo }}`);
178+
console.info(`Workflow will create draft PR by default`);
179+
180+
update-prs:
181+
name: Update prs as ready for review
182+
needs: [test-deploy, create-draft-prs]
183+
if: ${{ needs.test-deploy.result == 'success' && github.repository_owner == 'vercel' && github.event_name == 'release' }}
99184
runs-on: ubuntu-latest
100185
strategy:
101186
fail-fast: false
@@ -108,22 +193,6 @@ jobs:
108193
workflow_id: update-next.yml
109194
workflow_url: https://github.com/vercel/v0/actions/workflows/update-next.yml?query=event%3Aworkflow_dispatch
110195
steps:
111-
- uses: actions/checkout@v4
112-
- id: nextPackageInfo
113-
name: Get `next` package info
114-
run: |
115-
cd packages/next
116-
{
117-
echo 'value<<EOF'
118-
cat package.json
119-
echo EOF
120-
} >> "$GITHUB_OUTPUT"
121-
- id: version
122-
name: Extract `next` version
123-
run: echo 'value=${{ fromJson(steps.nextPackageInfo.outputs.value).version }}' >> "$GITHUB_OUTPUT"
124-
- id: test-result
125-
name: Set test result variable
126-
run: echo 'immediately-close=${{ needs.test-deploy.result != 'success' && 'true' || 'false' }}' >> "$GITHUB_OUTPUT"
127196
- name: Check token
128197
run: gh auth status
129198
env:
@@ -157,8 +226,8 @@ jobs:
157226
return 'false';
158227
}
159228
- uses: actions/github-script@v7
160-
name: Trigger vercel/${{ matrix.repo }} sync
161-
id: trigger-sync
229+
name: Mark PR ready for review in vercel/${{ matrix.repo }}
230+
id: mark-pr-ready
162231
if: steps.check-workflow-enabled.outputs.result == 'true'
163232
with:
164233
retries: 3
@@ -169,15 +238,12 @@ jobs:
169238
# Note `workflow_id` and `inputs` are contract between vercel/${{ matrix.repo }},
170239
# if these need to be changed both side should be updated accordingly.
171240
script: |
172-
const immediatelyClose = '${{ steps.test-result.outputs.immediately-close }}';
173241
const inputs = {
174-
version: "${{ steps.version.outputs.value }}",
242+
version: "${{ needs.setup.outputs.next-version }}",
243+
'make-ready-for-review': 'true',
244+
force: 'true'
175245
};
176246
177-
if (immediatelyClose === 'true') {
178-
inputs['immediately-close'] = 'true';
179-
}
180-
181247
await github.request(
182248
"POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",
183249
{
@@ -188,16 +254,8 @@ jobs:
188254
inputs: inputs,
189255
}
190256
);
191-
// Ideally we'd include a URL to this specific sync.
192-
// However, creating a workflow_dispatch event does not produce an ID: https://github.com/orgs/community/discussions/9752
193-
console.info(
194-
"Sync started in ${{ matrix.workflow_url }}"
195-
);
257+
258+
console.info("Tests passed - PR will be marked ready for review");
196259
console.info(
197-
"This may not start a new sync if one is already in progress. Check the logs of the workflow run."
260+
"PR ready-for-review triggered in ${{ matrix.workflow_url }}"
198261
);
199-
if (immediatelyClose === 'true') {
200-
console.info(
201-
"Sync triggered with immediately-close=true due to test failure."
202-
);
203-
}

0 commit comments

Comments
 (0)