feat(release): update release process for nightly and preview builds (#6643)
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
parent
acedcfb8f7
commit
0e24805806
|
@ -4,6 +4,8 @@ on:
|
||||||
schedule:
|
schedule:
|
||||||
# Runs every day at midnight UTC for the nightly release.
|
# Runs every day at midnight UTC for the nightly release.
|
||||||
- cron: '0 0 * * *'
|
- cron: '0 0 * * *'
|
||||||
|
# Runs every Tuesday at 23:59 UTC for the preview release.
|
||||||
|
- cron: '59 23 * * 2'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
|
@ -25,6 +27,11 @@ on:
|
||||||
required: false
|
required: false
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
default: false
|
default: false
|
||||||
|
create_preview_release:
|
||||||
|
description: 'Auto apply the preview release tag, input version is ignored.'
|
||||||
|
required: false
|
||||||
|
type: 'boolean'
|
||||||
|
default: false
|
||||||
force_skip_tests:
|
force_skip_tests:
|
||||||
description: 'Select to skip the "Run Tests" step in testing. Prod releases should run tests'
|
description: 'Select to skip the "Run Tests" step in testing. Prod releases should run tests'
|
||||||
required: false
|
required: false
|
||||||
|
@ -57,16 +64,24 @@ jobs:
|
||||||
- name: 'Set booleans for simplified logic'
|
- name: 'Set booleans for simplified logic'
|
||||||
env:
|
env:
|
||||||
CREATE_NIGHTLY_RELEASE: '${{ github.event.inputs.create_nightly_release }}'
|
CREATE_NIGHTLY_RELEASE: '${{ github.event.inputs.create_nightly_release }}'
|
||||||
|
CREATE_PREVIEW_RELEASE: '${{ github.event.inputs.create_preview_release }}'
|
||||||
EVENT_NAME: '${{ github.event_name }}'
|
EVENT_NAME: '${{ github.event_name }}'
|
||||||
|
CRON: '${{ github.event.schedule }}'
|
||||||
DRY_RUN_INPUT: '${{ github.event.inputs.dry_run }}'
|
DRY_RUN_INPUT: '${{ github.event.inputs.dry_run }}'
|
||||||
id: 'vars'
|
id: 'vars'
|
||||||
run: |-
|
run: |-
|
||||||
is_nightly="false"
|
is_nightly="false"
|
||||||
if [[ "${EVENT_NAME}" == "schedule" || "${CREATE_NIGHTLY_RELEASE}" == "true" ]]; then
|
if [[ "${CRON}" == "0 0 * * *" || "${CREATE_NIGHTLY_RELEASE}" == "true" ]]; then
|
||||||
is_nightly="true"
|
is_nightly="true"
|
||||||
fi
|
fi
|
||||||
echo "is_nightly=${is_nightly}" >> "${GITHUB_OUTPUT}"
|
echo "is_nightly=${is_nightly}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
|
is_preview="false"
|
||||||
|
if [[ "${CRON}" == "59 23 * * 2" || "${CREATE_PREVIEW_RELEASE}" == "true" ]]; then
|
||||||
|
is_preview="true"
|
||||||
|
fi
|
||||||
|
echo "is_preview=${is_preview}" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
is_dry_run="false"
|
is_dry_run="false"
|
||||||
if [[ "${DRY_RUN_INPUT}" == "true" ]]; then
|
if [[ "${DRY_RUN_INPUT}" == "true" ]]; then
|
||||||
is_dry_run="true"
|
is_dry_run="true"
|
||||||
|
@ -86,13 +101,16 @@ jobs:
|
||||||
- name: 'Get the version'
|
- name: 'Get the version'
|
||||||
id: 'version'
|
id: 'version'
|
||||||
env:
|
env:
|
||||||
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
IS_NIGHTLY: '${{ steps.vars.outputs.is_nightly }}'
|
IS_NIGHTLY: '${{ steps.vars.outputs.is_nightly }}'
|
||||||
|
IS_PREVIEW: '${{ steps.vars.outputs.is_preview }}'
|
||||||
MANUAL_VERSION: '${{ inputs.version }}'
|
MANUAL_VERSION: '${{ inputs.version }}'
|
||||||
run: |-
|
run: |-
|
||||||
VERSION_JSON="$(node scripts/get-release-version.js)"
|
VERSION_JSON="$(node scripts/get-release-version.js)"
|
||||||
echo "RELEASE_TAG=$(echo "${VERSION_JSON}" | jq -r .releaseTag)" >> "${GITHUB_OUTPUT}"
|
echo "RELEASE_TAG=$(echo "${VERSION_JSON}" | jq -r .releaseTag)" >> "${GITHUB_OUTPUT}"
|
||||||
echo "RELEASE_VERSION=$(echo "${VERSION_JSON}" | jq -r .releaseVersion)" >> "${GITHUB_OUTPUT}"
|
echo "RELEASE_VERSION=$(echo "${VERSION_JSON}" | jq -r .releaseVersion)" >> "${GITHUB_OUTPUT}"
|
||||||
echo "NPM_TAG=$(echo "${VERSION_JSON}" | jq -r .npmTag)" >> "${GITHUB_OUTPUT}"
|
echo "NPM_TAG=$(echo "${VERSION_JSON}" | jq -r .npmTag)" >> "${GITHUB_OUTPUT}"
|
||||||
|
echo "PREVIOUS_TAG=$(echo "${VERSION_JSON}" | jq -r .previousReleaseTag)" >> "${GITHUB_OUTPUT}"
|
||||||
|
|
||||||
- name: 'Run Tests'
|
- name: 'Run Tests'
|
||||||
if: |-
|
if: |-
|
||||||
|
@ -183,23 +201,6 @@ jobs:
|
||||||
--workspace="@google/gemini-cli" \
|
--workspace="@google/gemini-cli" \
|
||||||
--tag="${NPM_TAG}"
|
--tag="${NPM_TAG}"
|
||||||
|
|
||||||
- name: 'Get previous release tag'
|
|
||||||
id: 'previous_release'
|
|
||||||
if: |-
|
|
||||||
${{ steps.vars.outputs.is_dry_run == 'false' }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
|
||||||
IS_NIGHTLY: '${{ steps.vars.outputs.is_nightly }}'
|
|
||||||
run: |-
|
|
||||||
if [[ "${IS_NIGHTLY}" == "true" ]]; then
|
|
||||||
echo "Finding latest nightly release..."
|
|
||||||
PREVIOUS_TAG=$(gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | contains("nightly"))] | .[0].tagName')
|
|
||||||
else
|
|
||||||
echo "Finding latest STABLE release (excluding pre-releases)..."
|
|
||||||
PREVIOUS_TAG=$(gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | contains("nightly") | not)] | .[0].tagName')
|
|
||||||
fi
|
|
||||||
echo "PREVIOUS_TAG=${PREVIOUS_TAG}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: 'Create GitHub Release and Tag'
|
- name: 'Create GitHub Release and Tag'
|
||||||
if: |-
|
if: |-
|
||||||
${{ steps.vars.outputs.is_dry_run == 'false' }}
|
${{ steps.vars.outputs.is_dry_run == 'false' }}
|
||||||
|
@ -207,7 +208,7 @@ jobs:
|
||||||
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
RELEASE_BRANCH: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
|
RELEASE_BRANCH: '${{ steps.release_branch.outputs.BRANCH_NAME }}'
|
||||||
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
|
RELEASE_TAG: '${{ steps.version.outputs.RELEASE_TAG }}'
|
||||||
PREVIOUS_TAG: '${{ steps.previous_release.outputs.PREVIOUS_TAG }}'
|
PREVIOUS_TAG: '${{ steps.version.outputs.PREVIOUS_TAG }}'
|
||||||
run: |-
|
run: |-
|
||||||
gh release create "${RELEASE_TAG}" \
|
gh release create "${RELEASE_TAG}" \
|
||||||
bundle/gemini.js \
|
bundle/gemini.js \
|
||||||
|
|
|
@ -5,23 +5,36 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
function getPackageVersion() {
|
function getLatestStableTag() {
|
||||||
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
|
// Fetches all tags, then filters for the latest stable (non-prerelease) tag.
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const tags = execSync('git tag --list "v*.*.*" --sort=-v:refname')
|
||||||
return packageJson.version;
|
.toString()
|
||||||
|
.split('\n');
|
||||||
|
const latestStableTag = tags.find((tag) =>
|
||||||
|
tag.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/),
|
||||||
|
);
|
||||||
|
if (!latestStableTag) {
|
||||||
|
throw new Error('Could not find a stable tag.');
|
||||||
|
}
|
||||||
|
return latestStableTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getShortSha() {
|
function getShortSha() {
|
||||||
return execSync('git rev-parse --short HEAD').toString().trim();
|
return execSync('git rev-parse --short HEAD').toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNightlyTagName() {
|
function getNextVersionString(stableVersion, minorIncrement) {
|
||||||
const version = getPackageVersion();
|
const [major, minor] = stableVersion.substring(1).split('.');
|
||||||
|
const nextMinorVersion = parseInt(minor, 10) + minorIncrement;
|
||||||
|
return `${major}.${nextMinorVersion}.0`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNightlyTagName(stableVersion) {
|
||||||
|
const version = getNextVersionString(stableVersion, 2);
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const year = now.getUTCFullYear().toString().slice(-2);
|
const year = now.getUTCFullYear().toString();
|
||||||
const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');
|
const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');
|
||||||
const day = now.getUTCDate().toString().padStart(2, '0');
|
const day = now.getUTCDate().toString().padStart(2, '0');
|
||||||
const date = `${year}${month}${day}`;
|
const date = `${year}${month}${day}`;
|
||||||
|
@ -30,21 +43,50 @@ export function getNightlyTagName() {
|
||||||
return `v${version}-nightly.${date}.${sha}`;
|
return `v${version}-nightly.${date}.${sha}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPreviewTagName(stableVersion) {
|
||||||
|
const version = getNextVersionString(stableVersion, 1);
|
||||||
|
return `v${version}-preview`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPreviousReleaseTag(isNightly) {
|
||||||
|
if (isNightly) {
|
||||||
|
console.error('Finding latest nightly release...');
|
||||||
|
return execSync(
|
||||||
|
`gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | contains("nightly"))] | .[0].tagName'`,
|
||||||
|
)
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
} else {
|
||||||
|
console.error('Finding latest STABLE release (excluding pre-releases)...');
|
||||||
|
return execSync(
|
||||||
|
`gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | (contains("nightly") or contains("preview")) | not)] | .[0].tagName'`,
|
||||||
|
)
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getReleaseVersion() {
|
export function getReleaseVersion() {
|
||||||
const isNightly = process.env.IS_NIGHTLY === 'true';
|
const isNightly = process.env.IS_NIGHTLY === 'true';
|
||||||
|
const isPreview = process.env.IS_PREVIEW === 'true';
|
||||||
const manualVersion = process.env.MANUAL_VERSION;
|
const manualVersion = process.env.MANUAL_VERSION;
|
||||||
|
|
||||||
let releaseTag;
|
let releaseTag;
|
||||||
|
|
||||||
if (isNightly) {
|
if (isNightly) {
|
||||||
console.error('Calculating next nightly version...');
|
console.error('Calculating next nightly version...');
|
||||||
releaseTag = getNightlyTagName();
|
const stableVersion = getLatestStableTag();
|
||||||
|
releaseTag = getNightlyTagName(stableVersion);
|
||||||
|
} else if (isPreview) {
|
||||||
|
console.error('Calculating next preview version...');
|
||||||
|
const stableVersion = getLatestStableTag();
|
||||||
|
releaseTag = getPreviewTagName(stableVersion);
|
||||||
} else if (manualVersion) {
|
} else if (manualVersion) {
|
||||||
console.error(`Using manual version: ${manualVersion}`);
|
console.error(`Using manual version: ${manualVersion}`);
|
||||||
releaseTag = manualVersion;
|
releaseTag = manualVersion;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Error: No version specified and this is not a nightly release.',
|
'Error: No version specified and this is not a nightly or preview release.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +117,9 @@ export function getReleaseVersion() {
|
||||||
npmTag = releaseVersion.split('-')[1].split('.')[0];
|
npmTag = releaseVersion.split('-')[1].split('.')[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return { releaseTag, releaseVersion, npmTag };
|
const previousReleaseTag = getPreviousReleaseTag(isNightly);
|
||||||
|
|
||||||
|
return { releaseTag, releaseVersion, npmTag, previousReleaseTag };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
||||||
|
|
|
@ -6,59 +6,98 @@
|
||||||
|
|
||||||
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||||
import { getReleaseVersion } from '../get-release-version';
|
import { getReleaseVersion } from '../get-release-version';
|
||||||
import { execSync } from 'child_process';
|
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
|
// Mock child_process so we can spy on execSync
|
||||||
vi.mock('child_process', () => ({
|
vi.mock('child_process', () => ({
|
||||||
execSync: vi.fn(),
|
execSync: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('fs', async (importOriginal) => {
|
describe('getReleaseVersion', async () => {
|
||||||
const mod = await importOriginal();
|
// Dynamically import execSync after mocking
|
||||||
return {
|
const { execSync } = await import('child_process');
|
||||||
...mod,
|
|
||||||
default: {
|
|
||||||
...mod.default,
|
|
||||||
readFileSync: vi.fn(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getReleaseVersion', () => {
|
|
||||||
const originalEnv = { ...process.env };
|
const originalEnv = { ...process.env };
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetModules();
|
vi.resetAllMocks();
|
||||||
process.env = { ...originalEnv };
|
process.env = { ...originalEnv };
|
||||||
vi.useFakeTimers();
|
// Mock date to be consistent
|
||||||
|
vi.setSystemTime(new Date('2025-08-20T00:00:00.000Z'));
|
||||||
|
// Provide a default mock for execSync to avoid toString() on undefined
|
||||||
|
vi.mocked(execSync).mockReturnValue('');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env = originalEnv;
|
process.env = originalEnv;
|
||||||
vi.clearAllMocks();
|
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should calculate nightly version when IS_NIGHTLY is true', () => {
|
it('should generate a nightly version and get previous tag', () => {
|
||||||
process.env.IS_NIGHTLY = 'true';
|
process.env.IS_NIGHTLY = 'true';
|
||||||
const knownDate = new Date('2025-07-20T10:00:00.000Z');
|
|
||||||
vi.setSystemTime(knownDate);
|
vi.mocked(execSync).mockImplementation((command) => {
|
||||||
vi.mocked(fs.default.readFileSync).mockReturnValue(
|
if (command.includes('git tag')) {
|
||||||
JSON.stringify({ version: '0.1.0' }),
|
return 'v0.1.0\nv0.0.1';
|
||||||
);
|
}
|
||||||
vi.mocked(execSync).mockReturnValue('abcdef');
|
if (command.includes('git rev-parse')) {
|
||||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
return 'abcdef';
|
||||||
expect(releaseTag).toBe('v0.1.0-nightly.250720.abcdef');
|
}
|
||||||
expect(releaseVersion).toBe('0.1.0-nightly.250720.abcdef');
|
if (command.includes('gh release list')) {
|
||||||
expect(npmTag).toBe('nightly');
|
return 'v0.3.0-nightly.20250819.abcdef';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use manual version when provided', () => {
|
const result = getReleaseVersion();
|
||||||
process.env.MANUAL_VERSION = '1.2.3';
|
|
||||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
expect(result).toEqual({
|
||||||
expect(releaseTag).toBe('v1.2.3');
|
releaseTag: 'v0.3.0-nightly.20250820.abcdef',
|
||||||
expect(releaseVersion).toBe('1.2.3');
|
releaseVersion: '0.3.0-nightly.20250820.abcdef',
|
||||||
expect(npmTag).toBe('latest');
|
npmTag: 'nightly',
|
||||||
|
previousReleaseTag: 'v0.3.0-nightly.20250819.abcdef',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a preview version and get previous tag', () => {
|
||||||
|
process.env.IS_PREVIEW = 'true';
|
||||||
|
|
||||||
|
vi.mocked(execSync).mockImplementation((command) => {
|
||||||
|
if (command.includes('git tag')) {
|
||||||
|
return 'v0.1.0\nv0.0.1';
|
||||||
|
}
|
||||||
|
if (command.includes('gh release list')) {
|
||||||
|
return 'v0.1.0'; // Previous stable release
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = getReleaseVersion();
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
releaseTag: 'v0.2.0-preview',
|
||||||
|
releaseVersion: '0.2.0-preview',
|
||||||
|
npmTag: 'preview',
|
||||||
|
previousReleaseTag: 'v0.1.0',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the manual version and get previous tag', () => {
|
||||||
|
process.env.MANUAL_VERSION = 'v0.1.1';
|
||||||
|
|
||||||
|
vi.mocked(execSync).mockImplementation((command) => {
|
||||||
|
if (command.includes('gh release list')) {
|
||||||
|
return 'v0.1.0'; // Previous stable release
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = getReleaseVersion();
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
releaseTag: 'v0.1.1',
|
||||||
|
releaseVersion: '0.1.1',
|
||||||
|
npmTag: 'latest',
|
||||||
|
previousReleaseTag: 'v0.1.0',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should prepend v to manual version if missing', () => {
|
it('should prepend v to manual version if missing', () => {
|
||||||
|
@ -82,9 +121,9 @@ describe('getReleaseVersion', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if no version is provided for non-nightly release', () => {
|
it('should throw an error if no version is provided for non-nightly/preview release', () => {
|
||||||
expect(() => getReleaseVersion()).toThrow(
|
expect(() => getReleaseVersion()).toThrow(
|
||||||
'Error: No version specified and this is not a nightly release.',
|
'Error: No version specified and this is not a nightly or preview release.',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,18 +133,22 @@ describe('getReleaseVersion', () => {
|
||||||
'Error: Versions with build metadata (+) are not supported for releases.',
|
'Error: Versions with build metadata (+) are not supported for releases.',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('get-release-version script', () => {
|
it('should correctly calculate the next version from a patch release', () => {
|
||||||
it('should print version JSON to stdout when executed directly', () => {
|
process.env.IS_PREVIEW = 'true';
|
||||||
const expectedJson = {
|
|
||||||
releaseTag: 'v0.1.0-nightly.20250705',
|
|
||||||
releaseVersion: '0.1.0-nightly.20250705',
|
|
||||||
npmTag: 'nightly',
|
|
||||||
};
|
|
||||||
execSync.mockReturnValue(JSON.stringify(expectedJson));
|
|
||||||
|
|
||||||
const result = execSync('node scripts/get-release-version.js').toString();
|
vi.mocked(execSync).mockImplementation((command) => {
|
||||||
expect(JSON.parse(result)).toEqual(expectedJson);
|
if (command.includes('git tag')) {
|
||||||
|
return 'v1.1.3\nv1.1.2\nv1.1.1\nv1.1.0\nv1.0.0';
|
||||||
|
}
|
||||||
|
if (command.includes('gh release list')) {
|
||||||
|
return 'v1.1.3';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = getReleaseVersion();
|
||||||
|
|
||||||
|
expect(result.releaseTag).toBe('v1.2.0-preview');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue