diff --git a/.github/workflows/release-patch-1-create-pr.yml b/.github/workflows/release-patch-1-create-pr.yml index b18891bfa1..d19fc8e8b4 100644 --- a/.github/workflows/release-patch-1-create-pr.yml +++ b/.github/workflows/release-patch-1-create-pr.yml @@ -118,6 +118,7 @@ jobs: GITHUB_RUN_ID: '${{ github.run_id }}' LOG_CONTENT: '${{ env.LOG_CONTENT }}' TARGET_REF: '${{ github.event.inputs.ref }}' + ENVIRONMENT: '${{ github.event.inputs.environment }}' continue-on-error: true run: | git checkout "${TARGET_REF}" diff --git a/scripts/releasing/patch-create-comment.js b/scripts/releasing/patch-create-comment.js index 2001d3e0e0..c7b8422c6b 100644 --- a/scripts/releasing/patch-create-comment.js +++ b/scripts/releasing/patch-create-comment.js @@ -46,6 +46,11 @@ async function main() { description: 'The GitHub workflow run ID', type: 'string', }) + .option('environment', { + choices: ['prod', 'dev'], + type: 'string', + default: process.env.ENVIRONMENT || 'prod', + }) .option('test', { description: 'Test mode - validate logic without GitHub API calls', type: 'boolean', @@ -75,6 +80,7 @@ async function main() { : parseInt(process.env.EXIT_CODE || '1'); const commit = argv.commit || process.env.COMMIT; const channel = argv.channel || process.env.CHANNEL; + const environment = argv.environment; const repository = argv.repository || process.env.REPOSITORY || 'google-gemini/gemini-cli'; const runId = argv.runId || process.env.GITHUB_RUN_ID || '0'; @@ -210,6 +216,7 @@ A patch branch [\`${branch}\`](https://github.com/${repository}/tree/${branch}) commentBody = `🚀 **Patch PR Created!** **📋 Patch Details:** +- **Environment**: \`${environment}\` - **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\` - **Commit**: \`${commit}\` - **Hotfix Branch**: [\`${branch}\`](https://github.com/${repository}/tree/${branch}) @@ -265,6 +272,7 @@ ${hasConflicts ? '4' : '3'}. You'll receive updates here when the release comple commentBody = `🚀 **Patch PR Created!** **📋 Patch Details:** +- **Environment**: \`${environment}\` - **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\` - **Commit**: \`${commit}\` - **Hotfix Branch**: [\`${branch}\`](https://github.com/${repository}/tree/${branch}) diff --git a/scripts/tests/patch-create-comment.test.js b/scripts/tests/patch-create-comment.test.js index 402e03b2c5..e38cd4ed10 100644 --- a/scripts/tests/patch-create-comment.test.js +++ b/scripts/tests/patch-create-comment.test.js @@ -18,7 +18,6 @@ function runPatchCreateComment(args, env = {}) { ); const fullEnv = { ...process.env, - TEST_MODE: 'true', // Always run in test mode to avoid GitHub API calls ...env, }; @@ -39,18 +38,63 @@ function runPatchCreateComment(args, env = {}) { } describe('patch-create-comment', () => { - let originalEnv; - beforeEach(() => { - // Save original environment - originalEnv = { ...process.env }; + vi.stubEnv(); + // Always run in test mode to avoid GitHub API calls + vi.stubEnv('TEST_MODE', 'true'); }); afterEach(() => { - // Restore original environment - process.env = originalEnv; vi.clearAllMocks(); + vi.unstubAllEnvs(); }); + + describe('Environment flag', () => { + it('can be overridden with a flag', () => { + vi.stubEnv('ENVIRONMENT', 'dev'); + const result = runPatchCreateComment( + '--original-pr 8655 --exit-code 0 --environment prod --commit abc1234 --channel preview --repository google-gemini/gemini-cli --test', + ); + + expect(result.success).toBe(true); + expect(result.stdout).toContain('🚀 **Patch PR Created!**'); + expect(result.stdout).toContain('Environment**: `prod`'); + }); + + it('reads from the ENVIRONMENT env variable', () => { + vi.stubEnv('ENVIRONMENT', 'dev'); + const result = runPatchCreateComment( + '--original-pr 8655 --exit-code 0 --commit abc1234 --channel preview --repository google-gemini/gemini-cli --test', + ); + + expect(result.success).toBe(true); + expect(result.stdout).toContain('🚀 **Patch PR Created!**'); + expect(result.stdout).toContain('Environment**: `dev`'); + }); + + it('fails if the ENVIRONMENT is bogus', () => { + vi.stubEnv('ENVIRONMENT', 'totally-bogus'); + const result = runPatchCreateComment( + '--original-pr 8655 --exit-code 0 --commit abc1234 --channel preview --repository google-gemini/gemini-cli --test', + ); + + expect(result.success).toBe(false); + expect(result.stderr).toContain( + 'Argument: environment, Given: "totally-bogus", Choices: "prod", "dev"', + ); + }); + + it('defaults to prod if not specified', () => { + const result = runPatchCreateComment( + '--original-pr 8655 --exit-code 0 --commit abc1234 --channel preview --repository google-gemini/gemini-cli --test', + ); + + expect(result.success).toBe(true); + expect(result.stdout).toContain('🚀 **Patch PR Created!**'); + expect(result.stdout).toContain('Environment**: `prod`'); + }); + }); + describe('Environment Variable vs File Reading', () => { it('should prefer LOG_CONTENT environment variable over file', () => { const result = runPatchCreateComment(