mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix release workflow (#172)
This commit is contained in:
@@ -14,20 +14,44 @@ function getPackageVersion() {
|
||||
return packageJson.version;
|
||||
}
|
||||
|
||||
function getShortSha() {
|
||||
return execSync('git rev-parse --short HEAD').toString().trim();
|
||||
function incrementPatchVersion(version) {
|
||||
const parts = version.split('.');
|
||||
const major = parseInt(parts[0]);
|
||||
const minor = parseInt(parts[1]);
|
||||
const patch = parseInt(parts[2].split('-')[0]); // Handle pre-release versions
|
||||
return `${major}.${minor}.${patch + 1}`;
|
||||
}
|
||||
|
||||
function getLatestNightlyCount() {
|
||||
try {
|
||||
// Try to get the latest nightly tag from git to determine the counter
|
||||
const currentVersion = getPackageVersion();
|
||||
const nextVersion = incrementPatchVersion(currentVersion);
|
||||
const tags = execSync(`git tag -l "v${nextVersion}-nightly.*"`)
|
||||
.toString()
|
||||
.trim();
|
||||
|
||||
if (!tags) return 0;
|
||||
|
||||
const nightlyTags = tags.split('\n').filter(Boolean);
|
||||
const counts = nightlyTags.map((tag) => {
|
||||
const match = tag.match(/nightly\.(\d+)$/);
|
||||
return match ? parseInt(match[1]) : 0;
|
||||
});
|
||||
|
||||
return Math.max(...counts, -1) + 1;
|
||||
} catch (_error) {
|
||||
// If we can't get tags, start from 0
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function getNightlyTagName() {
|
||||
const version = getPackageVersion();
|
||||
const now = new Date();
|
||||
const year = now.getUTCFullYear().toString().slice(-2);
|
||||
const month = (now.getUTCMonth() + 1).toString().padStart(2, '0');
|
||||
const day = now.getUTCDate().toString().padStart(2, '0');
|
||||
const date = `${year}${month}${day}`;
|
||||
const nextVersion = incrementPatchVersion(version);
|
||||
const nightlyCount = getLatestNightlyCount();
|
||||
|
||||
const sha = getShortSha();
|
||||
return `v${version}-nightly.${date}.${sha}`;
|
||||
return `v${nextVersion}-nightly.${nightlyCount}`;
|
||||
}
|
||||
|
||||
export function getReleaseVersion() {
|
||||
@@ -72,7 +96,13 @@ export function getReleaseVersion() {
|
||||
const releaseVersion = releaseTag.substring(1);
|
||||
let npmTag = 'latest';
|
||||
if (releaseVersion.includes('-')) {
|
||||
npmTag = releaseVersion.split('-')[1].split('.')[0];
|
||||
const prereleasePart = releaseVersion.split('-')[1];
|
||||
npmTag = prereleasePart.split('.')[0];
|
||||
|
||||
// Ensure nightly releases use 'nightly' tag, not 'latest'
|
||||
if (npmTag === 'nightly') {
|
||||
npmTag = 'nightly';
|
||||
}
|
||||
}
|
||||
|
||||
return { releaseTag, releaseVersion, npmTag };
|
||||
|
||||
@@ -41,15 +41,14 @@ describe('getReleaseVersion', () => {
|
||||
|
||||
it('should calculate nightly version when IS_NIGHTLY is true', () => {
|
||||
process.env.IS_NIGHTLY = 'true';
|
||||
const knownDate = new Date('2025-07-20T10:00:00.000Z');
|
||||
vi.setSystemTime(knownDate);
|
||||
vi.mocked(fs.default.readFileSync).mockReturnValue(
|
||||
JSON.stringify({ version: '0.1.0' }),
|
||||
);
|
||||
vi.mocked(execSync).mockReturnValue('abcdef');
|
||||
// Mock git tag command to return empty (no existing nightly tags)
|
||||
vi.mocked(execSync).mockReturnValue('');
|
||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
||||
expect(releaseTag).toBe('v0.1.0-nightly.250720.abcdef');
|
||||
expect(releaseVersion).toBe('0.1.0-nightly.250720.abcdef');
|
||||
expect(releaseTag).toBe('v0.1.1-nightly.0');
|
||||
expect(releaseVersion).toBe('0.1.1-nightly.0');
|
||||
expect(npmTag).toBe('nightly');
|
||||
});
|
||||
|
||||
@@ -99,8 +98,8 @@ describe('getReleaseVersion', () => {
|
||||
describe('get-release-version script', () => {
|
||||
it('should print version JSON to stdout when executed directly', () => {
|
||||
const expectedJson = {
|
||||
releaseTag: 'v0.1.0-nightly.20250705',
|
||||
releaseVersion: '0.1.0-nightly.20250705',
|
||||
releaseTag: 'v0.1.1-nightly.0',
|
||||
releaseVersion: '0.1.1-nightly.0',
|
||||
npmTag: 'nightly',
|
||||
};
|
||||
execSync.mockReturnValue(JSON.stringify(expectedJson));
|
||||
|
||||
@@ -23,18 +23,24 @@ function writeJson(filePath, data) {
|
||||
writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
|
||||
}
|
||||
|
||||
// 1. Get the version type from the command line arguments.
|
||||
const versionType = process.argv[2];
|
||||
if (!versionType) {
|
||||
console.error('Error: No version type specified.');
|
||||
console.error('Usage: npm run version <patch|minor|major|prerelease>');
|
||||
// 1. Get the version from the command line arguments.
|
||||
const versionArg = process.argv[2];
|
||||
if (!versionArg) {
|
||||
console.error('Error: No version specified.');
|
||||
console.error(
|
||||
'Usage: npm run version <version> (e.g., 1.2.3 or patch|minor|major|prerelease)',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 2. Bump the version in the root and all workspace package.json files.
|
||||
run(`npm version ${versionType} --no-git-tag-version --allow-same-version`);
|
||||
// 2. Determine if we have a specific version or a version type
|
||||
const isSpecificVersion = /^\d+\.\d+\.\d+/.test(versionArg);
|
||||
const npmVersionArg = isSpecificVersion ? versionArg : versionArg;
|
||||
|
||||
// 3. Bump the version in the root and all workspace package.json files.
|
||||
run(`npm version ${npmVersionArg} --no-git-tag-version --allow-same-version`);
|
||||
run(
|
||||
`npm version ${versionType} --workspaces --no-git-tag-version --allow-same-version`,
|
||||
`npm version ${npmVersionArg} --workspaces --no-git-tag-version --allow-same-version`,
|
||||
);
|
||||
|
||||
// 3. Get the new version number from the root package.json
|
||||
|
||||
Reference in New Issue
Block a user