mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
Release Promotion Clean up (#8597)
This commit is contained in:
@@ -8,11 +8,6 @@
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
function getArgs() {
|
||||
const args = {};
|
||||
@@ -26,96 +21,147 @@ function getArgs() {
|
||||
}
|
||||
|
||||
function getLatestTag(pattern) {
|
||||
const command = `gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | ${pattern})] | .[0].tagName'`;
|
||||
const command = `git tag --sort=-creatordate -l '${pattern}' | head -n 1`;
|
||||
try {
|
||||
return execSync(command).toString().trim();
|
||||
} catch {
|
||||
// Suppress error output for cleaner test failures
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function getVersion(options = {}) {
|
||||
const args = getArgs();
|
||||
const type = options.type || args.type || 'nightly';
|
||||
function getVersionFromNPM(distTag) {
|
||||
const command = `npm view @google/gemini-cli version --tag=${distTag}`;
|
||||
try {
|
||||
return execSync(command).toString().trim();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
let releaseVersion;
|
||||
let npmTag;
|
||||
let previousReleaseTag;
|
||||
|
||||
if (type === 'nightly') {
|
||||
const packageJson = JSON.parse(
|
||||
readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'),
|
||||
);
|
||||
const versionParts = packageJson.version.split('.');
|
||||
const major = versionParts[0];
|
||||
const minor = versionParts[1] ? parseInt(versionParts[1]) : 0;
|
||||
const nextMinor = minor + 1;
|
||||
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
||||
const gitShortHash = execSync('git rev-parse --short HEAD')
|
||||
.toString()
|
||||
.trim();
|
||||
releaseVersion = `${major}.${nextMinor}.0-nightly.${date}.${gitShortHash}`;
|
||||
npmTag = 'nightly';
|
||||
previousReleaseTag = getLatestTag('contains("nightly")');
|
||||
} else if (type === 'stable') {
|
||||
const latestPreviewTag = getLatestTag('contains("preview")');
|
||||
releaseVersion = latestPreviewTag
|
||||
.replace(/-preview.*/, '')
|
||||
.replace(/^v/, '');
|
||||
npmTag = 'latest';
|
||||
previousReleaseTag = getLatestTag(
|
||||
'(contains("nightly") or contains("preview")) | not',
|
||||
);
|
||||
} else if (type === 'preview') {
|
||||
const latestNightlyTag = getLatestTag('contains("nightly")');
|
||||
releaseVersion =
|
||||
latestNightlyTag.replace(/-nightly.*/, '').replace(/^v/, '') + '-preview';
|
||||
npmTag = 'preview';
|
||||
previousReleaseTag = getLatestTag('contains("preview")');
|
||||
} else if (type === 'patch') {
|
||||
const patchFrom = options.patchFrom || args.patchFrom;
|
||||
if (!patchFrom || (patchFrom !== 'stable' && patchFrom !== 'preview')) {
|
||||
function verifyGitHubReleaseExists(tagName) {
|
||||
const command = `gh release view "${tagName}" --json tagName --jq .tagName`;
|
||||
try {
|
||||
const output = execSync(command).toString().trim();
|
||||
if (output !== tagName) {
|
||||
throw new Error(
|
||||
'Patch type must be specified with --patch-from=stable or --patch-from=preview',
|
||||
`Discrepancy found! NPM version ${tagName} is missing a corresponding GitHub release.`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`Discrepancy found! Failed to verify GitHub release for ${tagName}. Error: ${error.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (patchFrom === 'stable') {
|
||||
previousReleaseTag = getLatestTag(
|
||||
'(contains("nightly") or contains("preview")) | not',
|
||||
);
|
||||
const versionParts = previousReleaseTag.replace(/^v/, '').split('.');
|
||||
const major = versionParts[0];
|
||||
const minor = versionParts[1];
|
||||
const patch = versionParts[2] ? parseInt(versionParts[2]) : 0;
|
||||
releaseVersion = `${major}.${minor}.${patch + 1}`;
|
||||
npmTag = 'latest';
|
||||
} else {
|
||||
// patchFrom === 'preview'
|
||||
previousReleaseTag = getLatestTag('contains("preview")');
|
||||
const [version, prerelease] = previousReleaseTag
|
||||
.replace(/^v/, '')
|
||||
.split('-');
|
||||
const versionParts = version.split('.');
|
||||
const major = versionParts[0];
|
||||
const minor = versionParts[1];
|
||||
const patch = versionParts[2] ? parseInt(versionParts[2]) : 0;
|
||||
releaseVersion = `${major}.${minor}.${patch + 1}-${prerelease}`;
|
||||
npmTag = 'preview';
|
||||
}
|
||||
function getAndVerifyTags(npmDistTag, gitTagPattern) {
|
||||
const latestVersion = getVersionFromNPM(npmDistTag);
|
||||
const latestTag = getLatestTag(gitTagPattern);
|
||||
if (`v${latestVersion}` !== latestTag) {
|
||||
throw new Error(
|
||||
`Discrepancy found! NPM ${npmDistTag} tag (${latestVersion}) does not match latest git ${npmDistTag} tag (${latestTag}).`,
|
||||
);
|
||||
}
|
||||
verifyGitHubReleaseExists(latestTag);
|
||||
return { latestVersion, latestTag };
|
||||
}
|
||||
|
||||
function getNightlyVersion() {
|
||||
const { latestVersion, latestTag } = getAndVerifyTags(
|
||||
'nightly',
|
||||
'v*-nightly*',
|
||||
);
|
||||
const baseVersion = latestVersion.split('-')[0];
|
||||
const versionParts = baseVersion.split('.');
|
||||
const major = versionParts[0];
|
||||
const minor = versionParts[1] ? parseInt(versionParts[1]) : 0;
|
||||
const nextMinor = minor + 1;
|
||||
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
||||
const gitShortHash = execSync('git rev-parse --short HEAD').toString().trim();
|
||||
return {
|
||||
releaseVersion: `${major}.${nextMinor}.0-nightly.${date}.${gitShortHash}`,
|
||||
npmTag: 'nightly',
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
|
||||
function getStableVersion() {
|
||||
const { latestVersion, latestTag } = getAndVerifyTags(
|
||||
'preview',
|
||||
'v*-preview*',
|
||||
);
|
||||
return {
|
||||
releaseVersion: latestVersion.replace(/-preview.*/, ''),
|
||||
npmTag: 'latest',
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
|
||||
function getPreviewVersion() {
|
||||
const { latestVersion, latestTag } = getAndVerifyTags(
|
||||
'nightly',
|
||||
'v*-nightly*',
|
||||
);
|
||||
return {
|
||||
releaseVersion: latestVersion.replace(/-nightly.*/, '') + '-preview',
|
||||
npmTag: 'preview',
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
|
||||
function getPatchVersion(patchFrom) {
|
||||
if (!patchFrom || (patchFrom !== 'stable' && patchFrom !== 'preview')) {
|
||||
throw new Error(
|
||||
'Patch type must be specified with --patch-from=stable or --patch-from=preview',
|
||||
);
|
||||
}
|
||||
const distTag = patchFrom === 'stable' ? 'latest' : 'preview';
|
||||
const pattern = distTag === 'latest' ? 'v[0-9].[0-9].[0-9]' : 'v*-preview*';
|
||||
const { latestVersion, latestTag } = getAndVerifyTags(distTag, pattern);
|
||||
const [version, ...prereleaseParts] = latestVersion.split('-');
|
||||
const prerelease = prereleaseParts.join('-');
|
||||
const versionParts = version.split('.');
|
||||
const major = versionParts[0];
|
||||
const minor = versionParts[1];
|
||||
const patch = versionParts[2] ? parseInt(versionParts[2]) : 0;
|
||||
const releaseVersion = prerelease
|
||||
? `${major}.${minor}.${patch + 1}-${prerelease}`
|
||||
: `${major}.${minor}.${patch + 1}`;
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: distTag,
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
|
||||
export function getVersion(options = {}) {
|
||||
const args = { ...getArgs(), ...options };
|
||||
const type = args.type || 'nightly';
|
||||
|
||||
let versionData;
|
||||
switch (type) {
|
||||
case 'nightly':
|
||||
versionData = getNightlyVersion();
|
||||
break;
|
||||
case 'stable':
|
||||
versionData = getStableVersion();
|
||||
break;
|
||||
case 'preview':
|
||||
versionData = getPreviewVersion();
|
||||
break;
|
||||
case 'patch':
|
||||
versionData = getPatchVersion(args['patch-from']);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown release type: ${type}`);
|
||||
}
|
||||
|
||||
const releaseTag = `v${releaseVersion}`;
|
||||
|
||||
return {
|
||||
releaseTag,
|
||||
releaseVersion,
|
||||
npmTag,
|
||||
previousReleaseTag,
|
||||
releaseTag: `v${versionData.releaseVersion}`,
|
||||
...versionData,
|
||||
};
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
console.log(JSON.stringify(getVersion(), null, 2));
|
||||
console.log(JSON.stringify(getVersion(getArgs()), null, 2));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user