mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
chore: pump version to 0.1.0, and optimize release workflow
This commit is contained in:
@@ -1,213 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
/**
|
||||
* Determines the correct previous tag for release notes generation.
|
||||
* This function handles the complexity of mixed tag types (regular releases vs nightly releases).
|
||||
*
|
||||
* @param {string} currentTag - The current release tag (e.g., "v0.1.23")
|
||||
* @returns {string|null} - The previous tag to compare against, or null if no suitable tag found
|
||||
*/
|
||||
export function getPreviousTag(currentTag) {
|
||||
try {
|
||||
// Parse the current tag to understand its type
|
||||
const currentTagInfo = parseTag(currentTag);
|
||||
if (!currentTagInfo) {
|
||||
console.error(`Invalid current tag format: ${currentTag}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Find the appropriate previous tag based on the current tag type
|
||||
let previousTag = null;
|
||||
|
||||
if (currentTagInfo.isNightly) {
|
||||
// For nightly releases, find the last stable release
|
||||
previousTag = findLastStableTag(currentTagInfo);
|
||||
} else {
|
||||
// For stable releases, find the previous stable release
|
||||
previousTag = findPreviousStableTag(currentTagInfo);
|
||||
}
|
||||
|
||||
return previousTag;
|
||||
} catch (error) {
|
||||
console.error('Error getting previous tag:', error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a tag string to extract version information and type
|
||||
*/
|
||||
function parseTag(tag) {
|
||||
// Remove 'v' prefix if present
|
||||
const cleanTag = tag.startsWith('v') ? tag.substring(1) : tag;
|
||||
|
||||
// Match pattern: X.Y.Z or X.Y.Z-prerelease
|
||||
const match = cleanTag.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [, major, minor, patch, prerelease] = match;
|
||||
|
||||
return {
|
||||
original: tag,
|
||||
major: parseInt(major),
|
||||
minor: parseInt(minor),
|
||||
patch: parseInt(patch),
|
||||
prerelease: prerelease || null,
|
||||
isNightly: prerelease && prerelease.startsWith('nightly'),
|
||||
isPreview: prerelease && prerelease.startsWith('preview'),
|
||||
version: `${major}.${minor}.${patch}`,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the last stable tag for a nightly release
|
||||
* Assumes version numbers are incremental and checks backwards from current version
|
||||
*/
|
||||
function findLastStableTag(currentTagInfo) {
|
||||
// For nightly releases, find the stable version of the same version number first
|
||||
const baseVersion = `v${currentTagInfo.version}`;
|
||||
|
||||
// Check if the stable version of the current version exists
|
||||
if (tagExists(baseVersion)) {
|
||||
return baseVersion;
|
||||
}
|
||||
|
||||
// If not, look for the previous stable versions by decrementing version numbers
|
||||
let { major, minor, patch } = currentTagInfo;
|
||||
|
||||
// Try decrementing patch version first
|
||||
while (patch > 0) {
|
||||
patch--;
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
}
|
||||
|
||||
// Try decrementing minor version
|
||||
while (minor > 0) {
|
||||
minor--;
|
||||
patch = 999; // Start from a high patch number and work backwards
|
||||
while (patch >= 0) {
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
patch--;
|
||||
// Don't check too many patch versions to avoid infinite loops
|
||||
if (patch < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Try decrementing major version
|
||||
while (major > 0) {
|
||||
major--;
|
||||
minor = 999; // Start from a high minor number and work backwards
|
||||
while (minor >= 0) {
|
||||
patch = 999;
|
||||
while (patch >= 0) {
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
patch--;
|
||||
if (patch < 0) break;
|
||||
}
|
||||
minor--;
|
||||
if (minor < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the previous stable tag for a stable release
|
||||
* Assumes version numbers are incremental and checks backwards from current version
|
||||
*/
|
||||
function findPreviousStableTag(currentTagInfo) {
|
||||
let { major, minor, patch } = currentTagInfo;
|
||||
|
||||
// Try decrementing patch version first
|
||||
while (patch > 0) {
|
||||
patch--;
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
}
|
||||
|
||||
// Try decrementing minor version
|
||||
while (minor > 0) {
|
||||
minor--;
|
||||
patch = 999; // Start from a high patch number and work backwards
|
||||
while (patch >= 0) {
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
patch--;
|
||||
// Don't check too many patch versions to avoid infinite loops
|
||||
if (patch < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Try decrementing major version
|
||||
while (major > 0) {
|
||||
major--;
|
||||
minor = 999; // Start from a high minor number and work backwards
|
||||
while (minor >= 0) {
|
||||
patch = 999;
|
||||
while (patch >= 0) {
|
||||
const candidateTag = `v${major}.${minor}.${patch}`;
|
||||
if (tagExists(candidateTag)) {
|
||||
return candidateTag;
|
||||
}
|
||||
patch--;
|
||||
if (patch < 0) break;
|
||||
}
|
||||
minor--;
|
||||
if (minor < 0) break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a git tag exists
|
||||
*/
|
||||
function tagExists(tag) {
|
||||
try {
|
||||
execSync(`git rev-parse --verify ${tag}`, { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// CLI usage
|
||||
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
||||
const currentTag = process.argv[2];
|
||||
|
||||
if (!currentTag) {
|
||||
console.error('Usage: node get-previous-tag.js <current-tag>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const previousTag = getPreviousTag(currentTag);
|
||||
if (previousTag) {
|
||||
console.log(previousTag);
|
||||
} else {
|
||||
console.error('No suitable previous tag found');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -26,36 +26,8 @@ function getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
function getLatestTag(pattern) {
|
||||
const command = `git tag -l '${pattern}'`;
|
||||
try {
|
||||
const tags = execSync(command)
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
if (tags.length === 0) return '';
|
||||
|
||||
// Convert tags to versions (remove 'v' prefix) and sort by semver
|
||||
const versions = tags
|
||||
.map((tag) => tag.replace(/^v/, ''))
|
||||
.filter((version) => semver.valid(version))
|
||||
.sort((a, b) => semver.rcompare(a, b)); // rcompare for descending order
|
||||
|
||||
if (versions.length === 0) return '';
|
||||
|
||||
// Return the latest version with 'v' prefix restored
|
||||
return `v${versions[0]}`;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to get latest git tag for pattern "${pattern}": ${error.message}`,
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function getVersionFromNPM(distTag) {
|
||||
const command = `npm view @google/gemini-cli version --tag=${distTag}`;
|
||||
const command = `npm view @qwen-code/qwen-code version --tag=${distTag}`;
|
||||
try {
|
||||
return execSync(command).toString().trim();
|
||||
} catch (error) {
|
||||
@@ -67,7 +39,7 @@ function getVersionFromNPM(distTag) {
|
||||
}
|
||||
|
||||
function getAllVersionsFromNPM() {
|
||||
const command = `npm view @google/gemini-cli versions --json`;
|
||||
const command = `npm view @qwen-code/qwen-code versions --json`;
|
||||
try {
|
||||
const versionsJson = execSync(command).toString().trim();
|
||||
return JSON.parse(versionsJson);
|
||||
@@ -78,7 +50,7 @@ function getAllVersionsFromNPM() {
|
||||
}
|
||||
|
||||
function isVersionDeprecated(version) {
|
||||
const command = `npm view @google/gemini-cli@${version} deprecated`;
|
||||
const command = `npm view @qwen-code/qwen-code@${version} deprecated`;
|
||||
try {
|
||||
const output = execSync(command).toString().trim();
|
||||
return output.length > 0;
|
||||
@@ -159,7 +131,7 @@ function detectRollbackAndGetBaseline(npmDistTag) {
|
||||
function doesVersionExist(version) {
|
||||
// Check NPM
|
||||
try {
|
||||
const command = `npm view @google/gemini-cli@${version} version 2>/dev/null`;
|
||||
const command = `npm view @qwen-code/qwen-code@${version} version 2>/dev/null`;
|
||||
const output = execSync(command).toString().trim();
|
||||
if (output === version) {
|
||||
console.error(`Version ${version} already exists on NPM.`);
|
||||
@@ -229,11 +201,20 @@ function getAndVerifyTags(npmDistTag, _gitTagPattern) {
|
||||
};
|
||||
}
|
||||
|
||||
function getLatestStableReleaseTag() {
|
||||
try {
|
||||
const { latestTag } = getAndVerifyTags('latest', 'v[0-9].[0-9].[0-9]');
|
||||
return latestTag;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to determine latest stable release tag: ${error.message}`,
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function promoteNightlyVersion() {
|
||||
const { latestVersion, latestTag } = getAndVerifyTags(
|
||||
'nightly',
|
||||
'v*-nightly*',
|
||||
);
|
||||
const { latestVersion } = getAndVerifyTags('nightly', 'v*-nightly*');
|
||||
const baseVersion = latestVersion.split('-')[0];
|
||||
const versionParts = baseVersion.split('.');
|
||||
const major = versionParts[0];
|
||||
@@ -244,7 +225,6 @@ function promoteNightlyVersion() {
|
||||
return {
|
||||
releaseVersion: `${major}.${nextMinor}.0-nightly.${date}.${gitShortHash}`,
|
||||
npmTag: 'nightly',
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -254,12 +234,9 @@ function getNightlyVersion() {
|
||||
const date = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
||||
const gitShortHash = execSync('git rev-parse --short HEAD').toString().trim();
|
||||
const releaseVersion = `${baseVersion}-nightly.${date}.${gitShortHash}`;
|
||||
const previousReleaseTag = getLatestTag('v*-nightly*');
|
||||
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: 'nightly',
|
||||
previousReleaseTag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -290,15 +267,9 @@ function getStableVersion(args) {
|
||||
releaseVersion = latestPreviewVersion.replace(/-preview.*/, '');
|
||||
}
|
||||
|
||||
const { latestTag: previousStableTag } = getAndVerifyTags(
|
||||
'latest',
|
||||
'v[0-9].[0-9].[0-9]',
|
||||
);
|
||||
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: 'latest',
|
||||
previousReleaseTag: previousStableTag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -321,15 +292,9 @@ function getPreviewVersion(args) {
|
||||
latestNightlyVersion.replace(/-nightly.*/, '') + '-preview.0';
|
||||
}
|
||||
|
||||
const { latestTag: previousPreviewTag } = getAndVerifyTags(
|
||||
'preview',
|
||||
'v*-preview*',
|
||||
);
|
||||
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: 'preview',
|
||||
previousReleaseTag: previousPreviewTag,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -341,7 +306,7 @@ function getPatchVersion(patchFrom) {
|
||||
}
|
||||
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 { latestVersion } = getAndVerifyTags(distTag, pattern);
|
||||
|
||||
if (patchFrom === 'stable') {
|
||||
// For stable versions, increment the patch number: 0.5.4 -> 0.5.5
|
||||
@@ -353,7 +318,6 @@ function getPatchVersion(patchFrom) {
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: distTag,
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
} else {
|
||||
// For preview versions, increment the preview number: 0.6.0-preview.2 -> 0.6.0-preview.3
|
||||
@@ -373,7 +337,6 @@ function getPatchVersion(patchFrom) {
|
||||
return {
|
||||
releaseVersion,
|
||||
npmTag: distTag,
|
||||
previousReleaseTag: latestTag,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -438,6 +401,8 @@ export function getVersion(options = {}) {
|
||||
...versionData,
|
||||
};
|
||||
|
||||
result.previousReleaseTag = getLatestStableReleaseTag();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user