-
Notifications
You must be signed in to change notification settings - Fork 13.1k
feat(release): automate patch creation and release process #8202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b581382
feat(release): automate patch creation and release process
mattKorwel c2b9525
feat(release): allow triggering patch process from comments
mattKorwel 986af5c
docs(release): add note about branch protection
mattKorwel 0d49d5b
fix(security): pin slash-command-dispatch action to commit SHA
mattKorwel bab2378
feat(release): improve patch command DX and security
mattKorwel 3c18d56
fix(security): pin actions in new workflows
mattKorwel e5332cd
feat(release): add dry-run capability to patch command
mattKorwel 1349759
fix(release): address feedback on patch creation script
mattKorwel 17a1b07
fix(lint): address linting and formatting issues
mattKorwel 30ba68d
fix(lint): correct yaml linting errors
mattKorwel da0b023
Merge branch 'main' into feature/automate-patch-process
mattKorwel 59a5e0f
fix(lint): correct shellcheck errors in patch-from-comment workflow
mattKorwel 3b6ebfb
fix(lint): correct all yaml linting errors
mattKorwel 4c53877
fix(lint): correct final yaml linting error
mattKorwel 81056dc
Merge branch 'main' into feature/automate-patch-process
mattKorwel e28c5a0
Merge branch 'main' into feature/automate-patch-process
mattKorwel 2dc9e03
Merge branch 'main' into feature/automate-patch-process
mattKorwel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: 'Create Patch PR' | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| commit: | ||
| description: 'The commit SHA to cherry-pick for the patch.' | ||
| required: true | ||
| type: 'string' | ||
| channel: | ||
| description: 'The release channel to patch.' | ||
| required: true | ||
| type: 'choice' | ||
| options: | ||
| - 'stable' | ||
| - 'preview' | ||
| dry_run: | ||
| description: 'Whether to run in dry-run mode.' | ||
| required: false | ||
| type: 'boolean' | ||
| default: false | ||
|
|
||
| jobs: | ||
| create-patch: | ||
| runs-on: 'ubuntu-latest' | ||
| permissions: | ||
| contents: 'write' | ||
| pull-requests: 'write' | ||
| steps: | ||
| - name: 'Checkout' | ||
| uses: 'actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8' # ratchet:actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: 'Setup Node.js' | ||
| uses: 'actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020' # ratchet:actions/setup-node@v4 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: 'npm' | ||
|
|
||
| - name: 'Install Dependencies' | ||
| run: 'npm ci' | ||
|
|
||
| - name: 'Configure Git User' | ||
| run: |- | ||
| git config user.name "gemini-cli-robot" | ||
| git config user.email "gemini-cli-robot@google.com" | ||
|
|
||
| - name: 'Create Patch for Stable' | ||
| if: "github.event.inputs.channel == 'stable'" | ||
| env: | ||
| GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | ||
| run: 'node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=stable --dry-run=${{ github.event.inputs.dry_run }}' | ||
|
|
||
| - name: 'Create Patch for Preview' | ||
| env: | ||
| GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | ||
| run: 'node scripts/create-patch-pr.js --commit=${{ github.event.inputs.commit }} --channel=${{ github.event.inputs.channel }} --dry-run=${{ github.event.inputs.dry_run }}' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: 'Patch from Comment' | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: ['created'] | ||
|
|
||
| jobs: | ||
| slash-command: | ||
| runs-on: 'ubuntu-latest' | ||
| steps: | ||
| - name: 'Slash Command Dispatch' | ||
| id: 'slash_command' | ||
| uses: 'peter-evans/slash-command-dispatch@40877f718dce0101edfc7aea2b3800cc192f9ed5' | ||
| with: | ||
| token: '${{ secrets.GITHUB_TOKEN }}' | ||
| commands: 'patch' | ||
| permission: 'write' | ||
| issue-type: 'pull-request' | ||
| static-args: | | ||
| dry_run=false | ||
|
|
||
| - name: 'Get PR Status' | ||
| id: 'pr_status' | ||
| if: "steps.slash_command.outputs.dispatched == 'true'" | ||
| env: | ||
| GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | ||
| run: | | ||
| gh pr view "${{ github.event.issue.number }}" --json mergeCommit,state > pr_status.json | ||
| echo "MERGE_COMMIT_SHA=$(jq -r .mergeCommit.oid pr_status.json)" >> "$GITHUB_OUTPUT" | ||
| echo "STATE=$(jq -r .state pr_status.json)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: 'Dispatch if Merged' | ||
| if: "steps.pr_status.outputs.STATE == 'MERGED'" | ||
| uses: 'actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325' | ||
| with: | ||
| script: | | ||
| const args = JSON.parse('${{ steps.slash_command.outputs.command-arguments }}'); | ||
| github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: 'create-patch-pr.yml', | ||
| ref: 'main', | ||
| inputs: { | ||
| commit: '${{ steps.pr_status.outputs.MERGE_COMMIT_SHA }}', | ||
| channel: args.channel, | ||
| dry_run: args.dry_run | ||
| } | ||
| }) | ||
|
|
||
| - name: 'Comment on Failure' | ||
| if: "steps.pr_status.outputs.STATE != 'MERGED'" | ||
| uses: 'peter-evans/create-or-update-comment@67dcc547d311b736a8e6c5c236542148a47adc3d' | ||
| with: | ||
| issue-number: '${{ github.event.issue.number }}' | ||
| body: | | ||
| :x: The `/patch` command failed. This pull request must be merged before a patch can be created. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: 'Trigger Patch Release' | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - 'closed' | ||
|
|
||
| jobs: | ||
| trigger-patch-release: | ||
| if: "github.event.pull_request.merged == true && startsWith(github.head_ref, 'hotfix/')" | ||
| runs-on: 'ubuntu-latest' | ||
| steps: | ||
| - name: 'Trigger Patch Release' | ||
| uses: 'actions/github-script@00f12e3e20659f42342b1c0226afda7f7c042325' | ||
| with: | ||
| script: | | ||
| const body = context.payload.pull_request.body; | ||
| const isDryRun = body.includes('[DRY RUN]'); | ||
| const ref = context.payload.pull_request.base.ref; | ||
| const channel = ref.includes('preview') ? 'preview' : 'stable'; | ||
| github.rest.actions.createWorkflowDispatch({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| workflow_id: 'patch-release.yml', | ||
| ref: ref, | ||
| inputs: { | ||
| type: channel, | ||
| dry_run: isDryRun.toString() | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { execSync } from 'node:child_process'; | ||
| import yargs from 'yargs'; | ||
| import { hideBin } from 'yargs/helpers'; | ||
|
|
||
| async function main() { | ||
| const argv = await yargs(hideBin(process.argv)) | ||
| .option('commit', { | ||
| alias: 'c', | ||
| description: 'The commit SHA to cherry-pick for the patch.', | ||
| type: 'string', | ||
| demandOption: true, | ||
| }) | ||
| .option('channel', { | ||
| alias: 'ch', | ||
| description: 'The release channel to patch.', | ||
| choices: ['stable', 'preview'], | ||
| demandOption: true, | ||
| }) | ||
| .option('dry-run', { | ||
| description: 'Whether to run in dry-run mode.', | ||
| type: 'boolean', | ||
| default: false, | ||
| }) | ||
| .help() | ||
| .alias('help', 'h').argv; | ||
|
|
||
| const { commit, channel, dryRun } = argv; | ||
|
|
||
| console.log(`Starting patch process for commit: ${commit}`); | ||
| console.log(`Targeting channel: ${channel}`); | ||
| if (dryRun) { | ||
| console.log('Running in dry-run mode.'); | ||
| } | ||
|
|
||
| run('git fetch --all --tags --prune', dryRun); | ||
|
|
||
| const latestTag = getLatestTag(channel); | ||
| console.log(`Found latest tag for ${channel}: ${latestTag}`); | ||
|
|
||
| const releaseBranch = `release/${latestTag}`; | ||
| const hotfixBranch = `hotfix/${latestTag}/cherry-pick-${commit.substring(0, 7)}`; | ||
|
|
||
| // Create the release branch from the tag if it doesn't exist. | ||
| if (!branchExists(releaseBranch)) { | ||
| console.log( | ||
| `Release branch ${releaseBranch} does not exist. Creating it from tag ${latestTag}...`, | ||
| ); | ||
| run(`git checkout -b ${releaseBranch} ${latestTag}`, dryRun); | ||
| run(`git push origin ${releaseBranch}`, dryRun); | ||
| } else { | ||
| console.log(`Release branch ${releaseBranch} already exists.`); | ||
| } | ||
|
|
||
| // Create the hotfix branch from the release branch. | ||
| console.log( | ||
| `Creating hotfix branch ${hotfixBranch} from ${releaseBranch}...`, | ||
| ); | ||
| run(`git checkout -b ${hotfixBranch} origin/${releaseBranch}`, dryRun); | ||
|
|
||
| // Cherry-pick the commit. | ||
| console.log(`Cherry-picking commit ${commit} into ${hotfixBranch}...`); | ||
| run(`git cherry-pick ${commit}`, dryRun); | ||
|
|
||
| // Push the hotfix branch. | ||
| console.log(`Pushing hotfix branch ${hotfixBranch} to origin...`); | ||
| run(`git push --set-upstream origin ${hotfixBranch}`, dryRun); | ||
|
|
||
| // Create the pull request. | ||
| console.log( | ||
| `Creating pull request from ${hotfixBranch} to ${releaseBranch}...`, | ||
| ); | ||
| const prTitle = `fix(patch): cherry-pick ${commit.substring(0, 7)} to ${releaseBranch}`; | ||
| let prBody = `This PR automatically cherry-picks commit ${commit} to patch the ${channel} release.`; | ||
| if (dryRun) { | ||
| prBody += '\n\n**[DRY RUN]**'; | ||
| } | ||
| run( | ||
| `gh pr create --base ${releaseBranch} --head ${hotfixBranch} --title "${prTitle}" --body "${prBody}"`, | ||
| dryRun, | ||
| ); | ||
|
|
||
| console.log('Patch process completed successfully!'); | ||
| } | ||
|
|
||
| function run(command, dryRun = false) { | ||
| console.log(`> ${command}`); | ||
| if (dryRun) { | ||
| return; | ||
| } | ||
| try { | ||
| return execSync(command).toString().trim(); | ||
| } catch (err) { | ||
| console.error(`Command failed: ${command}`); | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| function branchExists(branchName) { | ||
| try { | ||
| execSync(`git ls-remote --exit-code --heads origin ${branchName}`); | ||
| return true; | ||
| } catch (_e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function getLatestTag(channel) { | ||
| console.log(`Fetching latest tag for channel: ${channel}...`); | ||
| const pattern = | ||
| channel === 'stable' | ||
| ? '\'(contains("nightly") or contains("preview")) | not\'' | ||
| : '\'(contains("preview"))\''; | ||
| const command = `gh release list --limit 30 --json tagName | jq -r '[.[] | select(.tagName | ${pattern})] | .[0].tagName'`; | ||
| try { | ||
| return execSync(command).toString().trim(); | ||
| } catch (err) { | ||
| console.error(`Failed to get latest tag for channel: ${channel}`); | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nit (for consistency): consider updating this from
'boolean'toboolean