Skip to content

Commit d9ac7b7

Browse files
committed
Merge Commit '29852e9': patch e2e vnext (google-gemini#8767)
2 parents faa9788 + 29852e9 commit d9ac7b7

File tree

8 files changed

+905
-95
lines changed

8 files changed

+905
-95
lines changed

.github/workflows/release-patch-1-create-pr.yml

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -65,72 +65,26 @@ jobs:
6565
permission-pull-requests: 'write'
6666
permission-contents: 'write'
6767

68-
- name: 'Create Patch for Stable'
69-
id: 'create_patch_stable'
70-
if: "github.event.inputs.channel == 'stable'"
68+
- name: 'Create Patch'
69+
id: 'create_patch'
7170
env:
7271
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
7372
continue-on-error: true
7473
run: |
75-
node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=stable --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
76-
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
77-
cat patch_output.log
78-
79-
- name: 'Create Patch for Preview'
80-
id: 'create_patch_preview'
81-
if: "github.event.inputs.channel != 'stable'"
82-
env:
83-
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
84-
continue-on-error: true
85-
run: |
86-
node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
74+
node scripts/releasing/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }} > patch_output.log 2>&1
8775
echo "EXIT_CODE=$?" >> "$GITHUB_OUTPUT"
8876
cat patch_output.log
8977
9078
- name: 'Comment on Original PR'
9179
if: '!inputs.dry_run && inputs.original_pr'
9280
env:
9381
GH_TOKEN: '${{ steps.generate_token.outputs.token }}'
82+
ORIGINAL_PR: '${{ github.event.inputs.original_pr }}'
83+
EXIT_CODE: '${{ steps.create_patch.outputs.EXIT_CODE }}'
84+
OUTPUT_LOG: 'patch_output.log'
85+
COMMIT: '${{ github.event.inputs.commit }}'
86+
CHANNEL: '${{ github.event.inputs.channel }}'
87+
REPOSITORY: '${{ github.repository }}'
88+
GITHUB_RUN_ID: '${{ github.run_id }}'
9489
run: |
95-
# Determine which step ran based on channel
96-
if [ "${{ github.event.inputs.channel }}" = "stable" ]; then
97-
EXIT_CODE="${{ steps.create_patch_stable.outputs.EXIT_CODE }}"
98-
else
99-
EXIT_CODE="${{ steps.create_patch_preview.outputs.EXIT_CODE }}"
100-
fi
101-
102-
# Check if patch output exists and contains branch info
103-
if [ -f patch_output.log ]; then
104-
if grep -q "already has an open PR" patch_output.log; then
105-
# Branch exists with existing PR
106-
PR_NUMBER=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #\([0-9]*\).*/\1/')
107-
PR_URL=$(grep "Found existing PR" patch_output.log | sed 's/.*Found existing PR #[0-9]*: \(.*\)/\1/')
108-
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch PR already exists! A patch PR for this change already exists: [#$PR_NUMBER]($PR_URL). Please review and approve this existing patch PR. If it's incorrect, close it and run the patch command again."
109-
110-
elif grep -q "exists but has no open PR" patch_output.log; then
111-
# Branch exists but no PR
112-
BRANCH=$(grep "Hotfix branch" patch_output.log | grep "already exists" | sed 's/.*Hotfix branch \(.*\) already exists.*/\1/')
113-
gh pr comment ${{ github.event.inputs.original_pr }} --body "ℹ️ Patch branch exists but no PR found! A patch branch [\`$BRANCH\`](https://github.com/${{ github.repository }}/tree/$BRANCH) exists but has no open PR. This might indicate an incomplete patch process. Please delete the branch and run the patch command again."
114-
115-
elif [ "$EXIT_CODE" = "0" ]; then
116-
# Success - find the newly created PR
117-
BRANCH=$(grep "Creating hotfix branch" patch_output.log | sed 's/.*Creating hotfix branch \(.*\) from.*/\1/')
118-
119-
# Find the PR for the new branch
120-
PR_INFO=$(gh pr list --head "$BRANCH" --json number,url --jq '.[0] // empty')
121-
122-
if [ -n "$PR_INFO" ]; then
123-
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
124-
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
125-
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created! The patch release PR has been created: [#$PR_NUMBER]($PR_URL). Please review and approve this PR to complete the patch release."
126-
else
127-
# Fallback if we can't find the specific PR
128-
gh pr comment ${{ github.event.inputs.original_pr }} --body "🚀 Patch PR created! The patch release PR for this change has been created. Please review and approve it: [View all patch PRs](https://github.com/${{ github.repository }}/pulls?q=is%3Apr+is%3Aopen+label%3Apatch)"
129-
fi
130-
else
131-
# Other error
132-
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed! There was an error creating the patch. Please check the workflow logs for details: [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
133-
fi
134-
else
135-
gh pr comment ${{ github.event.inputs.original_pr }} --body "❌ Patch creation failed! No output was generated. Please check the workflow logs: [View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
136-
fi
90+
node scripts/releasing/patch-create-comment.js

.github/workflows/release-patch-2-trigger.yml

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
description: 'The head ref of the merged hotfix PR to trigger the release for (e.g. hotfix/v1.2.3/cherry-pick-abc).'
1111
required: true
1212
type: 'string'
13+
workflow_ref:
14+
description: 'The ref to checkout the workflow code from.'
15+
required: false
16+
type: 'string'
17+
default: 'main'
1318
workflow_id:
1419
description: 'The workflow to trigger. Defaults to patch-release.yml'
1520
required: false
@@ -28,41 +33,30 @@ jobs:
2833
permissions:
2934
actions: 'write'
3035
steps:
31-
- name: 'Trigger Patch Release'
32-
uses: 'actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325'
36+
- name: 'Checkout'
37+
uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8'
3338
with:
34-
script: |
35-
let body = '';
36-
let headRef = '';
37-
38-
if (context.eventName === 'pull_request') {
39-
body = context.payload.pull_request.body;
40-
headRef = context.payload.pull_request.head.ref;
41-
} else { // workflow_dispatch
42-
body = ${{ github.event.inputs.dry_run }} ? '[DRY RUN]' : '';
43-
headRef = '${{ github.event.inputs.ref }}';
44-
}
39+
ref: "${{ github.event.inputs.workflow_ref || 'main' }}"
40+
fetch-depth: 1
4541

46-
const isDryRun = body.includes('[DRY RUN]');
47-
48-
// Extract base version and channel from hotfix branch name
49-
// e.g., hotfix/v0.5.3/cherry-pick-abc -> v0.5.3
50-
const version = headRef.split('/')[1];
51-
const channel = version.includes('preview') ? 'preview' : 'stable';
52-
const releaseRef = `release/${version}`;
42+
- name: 'Setup Node.js'
43+
uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020'
44+
with:
45+
node-version-file: '.nvmrc'
46+
cache: 'npm'
5347

54-
const workflow_id = context.eventName === 'pull_request'
55-
? 'release-patch-3-release.yml'
56-
: '${{ github.event.inputs.workflow_id }}';
48+
- name: 'Install Dependencies'
49+
run: 'npm ci'
5750

58-
github.rest.actions.createWorkflowDispatch({
59-
owner: context.repo.owner,
60-
repo: context.repo.repo,
61-
workflow_id: workflow_id,
62-
ref: 'main',
63-
inputs: {
64-
type: channel,
65-
dry_run: isDryRun.toString(),
66-
release_ref: releaseRef
67-
}
68-
})
51+
- name: 'Trigger Patch Release'
52+
env:
53+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
54+
HEAD_REF: "${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.event.inputs.ref }}"
55+
PR_BODY: "${{ github.event_name == 'pull_request' && github.event.pull_request.body || '' }}"
56+
WORKFLOW_ID: '${{ github.event.inputs.workflow_id }}'
57+
GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
58+
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}'
59+
GITHUB_EVENT_NAME: '${{ github.event_name }}'
60+
GITHUB_EVENT_PAYLOAD: '${{ toJSON(github.event) }}'
61+
run: |
62+
node scripts/releasing/patch-trigger.js

.github/workflows/release-patch-3-release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ on:
2424
description: 'The branch, tag, or SHA to release from.'
2525
required: true
2626
type: 'string'
27+
original_pr:
28+
description: 'The original PR number to comment back on.'
29+
required: false
30+
type: 'string'
2731

2832
jobs:
2933
release:
@@ -82,6 +86,55 @@ jobs:
8286
echo "NPM_TAG=${NPM_TAG}" >> "${GITHUB_OUTPUT}"
8387
echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
8488
89+
- name: 'Verify Version Consistency'
90+
env:
91+
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
92+
CHANNEL: '${{ github.event.inputs.type }}'
93+
run: |
94+
echo "🔍 Verifying no concurrent patch releases have occurred..."
95+
96+
# Store original calculation for comparison
97+
ORIGINAL_RELEASE_VERSION="${{ steps.patch_version.outputs.RELEASE_VERSION }}"
98+
ORIGINAL_RELEASE_TAG="${{ steps.patch_version.outputs.RELEASE_TAG }}"
99+
ORIGINAL_PREVIOUS_TAG="${{ steps.patch_version.outputs.PREVIOUS_TAG }}"
100+
101+
echo "Original calculation:"
102+
echo " Release version: ${ORIGINAL_RELEASE_VERSION}"
103+
echo " Release tag: ${ORIGINAL_RELEASE_TAG}"
104+
echo " Previous tag: ${ORIGINAL_PREVIOUS_TAG}"
105+
106+
# Re-run the same version calculation script
107+
echo "Re-calculating version to check for changes..."
108+
CURRENT_PATCH_JSON=$(node scripts/get-release-version.js --type=patch --patch-from="${CHANNEL}")
109+
CURRENT_RELEASE_VERSION=$(echo "${CURRENT_PATCH_JSON}" | jq -r .releaseVersion)
110+
CURRENT_RELEASE_TAG=$(echo "${CURRENT_PATCH_JSON}" | jq -r .releaseTag)
111+
CURRENT_PREVIOUS_TAG=$(echo "${CURRENT_PATCH_JSON}" | jq -r .previousReleaseTag)
112+
113+
echo "Current calculation:"
114+
echo " Release version: ${CURRENT_RELEASE_VERSION}"
115+
echo " Release tag: ${CURRENT_RELEASE_TAG}"
116+
echo " Previous tag: ${CURRENT_PREVIOUS_TAG}"
117+
118+
# Compare calculations
119+
if [[ "${ORIGINAL_RELEASE_VERSION}" != "${CURRENT_RELEASE_VERSION}" ]] || \
120+
[[ "${ORIGINAL_RELEASE_TAG}" != "${CURRENT_RELEASE_TAG}" ]] || \
121+
[[ "${ORIGINAL_PREVIOUS_TAG}" != "${CURRENT_PREVIOUS_TAG}" ]]; then
122+
echo "❌ RACE CONDITION DETECTED: Version calculations have changed!"
123+
echo "This indicates another patch release completed while this one was in progress."
124+
echo ""
125+
echo "Originally planned: ${ORIGINAL_RELEASE_VERSION} (from ${ORIGINAL_PREVIOUS_TAG})"
126+
echo "Should now build: ${CURRENT_RELEASE_VERSION} (from ${CURRENT_PREVIOUS_TAG})"
127+
echo ""
128+
echo "# Setting outputs for failure comment"
129+
echo "CURRENT_RELEASE_VERSION=${CURRENT_RELEASE_VERSION}" >> "${GITHUB_ENV}"
130+
echo "CURRENT_RELEASE_TAG=${CURRENT_RELEASE_TAG}" >> "${GITHUB_ENV}"
131+
echo "CURRENT_PREVIOUS_TAG=${CURRENT_PREVIOUS_TAG}" >> "${GITHUB_ENV}"
132+
echo "The patch release must be restarted to use the correct version numbers."
133+
exit 1
134+
fi
135+
136+
echo "✅ Version calculations unchanged - proceeding with release"
137+
85138
- name: 'Print Calculated Version'
86139
run: |-
87140
echo "Patch Release Summary:"
@@ -121,3 +174,46 @@ jobs:
121174
--title 'Patch Release Failed for ${RELEASE_TAG} on $(date +'%Y-%m-%d')' \
122175
--body 'The patch-release workflow failed. See the full run for details: ${DETAILS_URL}' \
123176
--label 'kind/bug,release-failure,priority/p0'
177+
178+
- name: 'Comment Success on Original PR'
179+
if: '${{ success() && github.event.inputs.original_pr }}'
180+
env:
181+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
182+
ORIGINAL_PR: '${{ github.event.inputs.original_pr }}'
183+
SUCCESS: 'true'
184+
RELEASE_VERSION: '${{ steps.patch_version.outputs.RELEASE_VERSION }}'
185+
RELEASE_TAG: '${{ steps.patch_version.outputs.RELEASE_TAG }}'
186+
NPM_TAG: '${{ steps.patch_version.outputs.NPM_TAG }}'
187+
CHANNEL: '${{ github.event.inputs.type }}'
188+
DRY_RUN: '${{ github.event.inputs.dry_run }}'
189+
GITHUB_RUN_ID: '${{ github.run_id }}'
190+
GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
191+
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}'
192+
run: |
193+
node scripts/releasing/patch-comment.js
194+
195+
- name: 'Comment Failure on Original PR'
196+
if: '${{ failure() && github.event.inputs.original_pr }}'
197+
env:
198+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
199+
ORIGINAL_PR: '${{ github.event.inputs.original_pr }}'
200+
SUCCESS: 'false'
201+
RELEASE_VERSION: '${{ steps.patch_version.outputs.RELEASE_VERSION }}'
202+
RELEASE_TAG: '${{ steps.patch_version.outputs.RELEASE_TAG }}'
203+
NPM_TAG: '${{ steps.patch_version.outputs.NPM_TAG }}'
204+
CHANNEL: '${{ github.event.inputs.type }}'
205+
DRY_RUN: '${{ github.event.inputs.dry_run }}'
206+
GITHUB_RUN_ID: '${{ github.run_id }}'
207+
GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
208+
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}'
209+
# Pass current version info for race condition failures
210+
CURRENT_RELEASE_VERSION: '${{ env.CURRENT_RELEASE_VERSION }}'
211+
CURRENT_RELEASE_TAG: '${{ env.CURRENT_RELEASE_TAG }}'
212+
CURRENT_PREVIOUS_TAG: '${{ env.CURRENT_PREVIOUS_TAG }}'
213+
run: |
214+
# Check if this was a version consistency failure
215+
if [[ -n "${CURRENT_RELEASE_VERSION}" ]]; then
216+
echo "Detected version race condition failure - posting specific comment with current version info"
217+
export RACE_CONDITION_FAILURE=true
218+
fi
219+
node scripts/releasing/patch-comment.js

.github/workflows/release-patch-from-comment.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,44 @@ jobs:
5353
- name: 'Dispatch if Merged'
5454
if: "steps.pr_status.outputs.STATE == 'MERGED'"
5555
uses: 'actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325'
56+
env:
57+
COMMENT_BODY: '${{ github.event.comment.body }}'
5658
with:
5759
script: |
58-
const args = ${{ fromJSON(steps.slash_command.outputs.command-arguments || '{}') }};
60+
// Parse the comment body directly to extract channel
61+
const commentBody = process.env.COMMENT_BODY;
62+
console.log('Comment body:', commentBody);
63+
64+
let channel = 'stable'; // default
65+
66+
// Parse different formats:
67+
// /patch channel=preview
68+
// /patch --channel preview
69+
// /patch preview
70+
if (commentBody.includes('channel=preview')) {
71+
channel = 'preview';
72+
} else if (commentBody.includes('--channel preview')) {
73+
channel = 'preview';
74+
} else if (commentBody.trim() === '/patch preview') {
75+
channel = 'preview';
76+
}
77+
78+
// Validate channel
79+
if (channel !== 'stable' && channel !== 'preview') {
80+
throw new Error(`Invalid channel: ${channel}. Must be 'stable' or 'preview'.`);
81+
}
82+
83+
console.log('Detected channel:', channel);
84+
5985
github.rest.actions.createWorkflowDispatch({
6086
owner: context.repo.owner,
6187
repo: context.repo.repo,
6288
workflow_id: 'release-patch-1-create-pr.yml',
6389
ref: 'main',
6490
inputs: {
6591
commit: '${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}',
66-
channel: args.channel || 'stable',
67-
dry_run: args.dry_run || 'false',
92+
channel: channel,
93+
dry_run: 'false',
6894
original_pr: '${{ github.event.issue.number }}'
6995
}
7096
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function main() {
4646
console.log(`Found latest tag for ${channel}: ${latestTag}`);
4747

4848
const releaseBranch = `release/${latestTag}`;
49-
const hotfixBranch = `hotfix/${latestTag}/cherry-pick-${commit.substring(0, 7)}`;
49+
const hotfixBranch = `hotfix/${latestTag}/${channel}/cherry-pick-${commit.substring(0, 7)}`;
5050

5151
// Create the release branch from the tag if it doesn't exist.
5252
if (!branchExists(releaseBranch)) {

0 commit comments

Comments
 (0)