fix(patch workflow): Ensure that the environment is listed on patch comments (#12538)

This commit is contained in:
Richie Foreman
2025-11-06 18:30:20 -05:00
committed by GitHub
parent f05d937f39
commit 445a5eac33
3 changed files with 60 additions and 7 deletions

View File

@@ -118,6 +118,7 @@ jobs:
GITHUB_RUN_ID: '${{ github.run_id }}' GITHUB_RUN_ID: '${{ github.run_id }}'
LOG_CONTENT: '${{ env.LOG_CONTENT }}' LOG_CONTENT: '${{ env.LOG_CONTENT }}'
TARGET_REF: '${{ github.event.inputs.ref }}' TARGET_REF: '${{ github.event.inputs.ref }}'
ENVIRONMENT: '${{ github.event.inputs.environment }}'
continue-on-error: true continue-on-error: true
run: | run: |
git checkout "${TARGET_REF}" git checkout "${TARGET_REF}"

View File

@@ -46,6 +46,11 @@ async function main() {
description: 'The GitHub workflow run ID', description: 'The GitHub workflow run ID',
type: 'string', type: 'string',
}) })
.option('environment', {
choices: ['prod', 'dev'],
type: 'string',
default: process.env.ENVIRONMENT || 'prod',
})
.option('test', { .option('test', {
description: 'Test mode - validate logic without GitHub API calls', description: 'Test mode - validate logic without GitHub API calls',
type: 'boolean', type: 'boolean',
@@ -75,6 +80,7 @@ async function main() {
: parseInt(process.env.EXIT_CODE || '1'); : parseInt(process.env.EXIT_CODE || '1');
const commit = argv.commit || process.env.COMMIT; const commit = argv.commit || process.env.COMMIT;
const channel = argv.channel || process.env.CHANNEL; const channel = argv.channel || process.env.CHANNEL;
const environment = argv.environment;
const repository = const repository =
argv.repository || process.env.REPOSITORY || 'google-gemini/gemini-cli'; argv.repository || process.env.REPOSITORY || 'google-gemini/gemini-cli';
const runId = argv.runId || process.env.GITHUB_RUN_ID || '0'; 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!** commentBody = `🚀 **Patch PR Created!**
**📋 Patch Details:** **📋 Patch Details:**
- **Environment**: \`${environment}\`
- **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\` - **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\`
- **Commit**: \`${commit}\` - **Commit**: \`${commit}\`
- **Hotfix Branch**: [\`${branch}\`](https://github.com/${repository}/tree/${branch}) - **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!** commentBody = `🚀 **Patch PR Created!**
**📋 Patch Details:** **📋 Patch Details:**
- **Environment**: \`${environment}\`
- **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\` - **Channel**: \`${channel}\` → will publish to npm tag \`${npmTag}\`
- **Commit**: \`${commit}\` - **Commit**: \`${commit}\`
- **Hotfix Branch**: [\`${branch}\`](https://github.com/${repository}/tree/${branch}) - **Hotfix Branch**: [\`${branch}\`](https://github.com/${repository}/tree/${branch})

View File

@@ -18,7 +18,6 @@ function runPatchCreateComment(args, env = {}) {
); );
const fullEnv = { const fullEnv = {
...process.env, ...process.env,
TEST_MODE: 'true', // Always run in test mode to avoid GitHub API calls
...env, ...env,
}; };
@@ -39,18 +38,63 @@ function runPatchCreateComment(args, env = {}) {
} }
describe('patch-create-comment', () => { describe('patch-create-comment', () => {
let originalEnv;
beforeEach(() => { beforeEach(() => {
// Save original environment vi.stubEnv();
originalEnv = { ...process.env }; // Always run in test mode to avoid GitHub API calls
vi.stubEnv('TEST_MODE', 'true');
}); });
afterEach(() => { afterEach(() => {
// Restore original environment
process.env = originalEnv;
vi.clearAllMocks(); 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', () => { describe('Environment Variable vs File Reading', () => {
it('should prefer LOG_CONTENT environment variable over file', () => { it('should prefer LOG_CONTENT environment variable over file', () => {
const result = runPatchCreateComment( const result = runPatchCreateComment(