mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(release): update release process for nightly and preview builds (#6643)
Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
@@ -6,59 +6,98 @@
|
||||
|
||||
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
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', () => ({
|
||||
execSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('fs', async (importOriginal) => {
|
||||
const mod = await importOriginal();
|
||||
return {
|
||||
...mod,
|
||||
default: {
|
||||
...mod.default,
|
||||
readFileSync: vi.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('getReleaseVersion', () => {
|
||||
describe('getReleaseVersion', async () => {
|
||||
// Dynamically import execSync after mocking
|
||||
const { execSync } = await import('child_process');
|
||||
const originalEnv = { ...process.env };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
vi.resetAllMocks();
|
||||
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(() => {
|
||||
process.env = originalEnv;
|
||||
vi.clearAllMocks();
|
||||
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';
|
||||
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');
|
||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
||||
expect(releaseTag).toBe('v0.1.0-nightly.250720.abcdef');
|
||||
expect(releaseVersion).toBe('0.1.0-nightly.250720.abcdef');
|
||||
expect(npmTag).toBe('nightly');
|
||||
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
if (command.includes('git tag')) {
|
||||
return 'v0.1.0\nv0.0.1';
|
||||
}
|
||||
if (command.includes('git rev-parse')) {
|
||||
return 'abcdef';
|
||||
}
|
||||
if (command.includes('gh release list')) {
|
||||
return 'v0.3.0-nightly.20250819.abcdef';
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = getReleaseVersion();
|
||||
|
||||
expect(result).toEqual({
|
||||
releaseTag: 'v0.3.0-nightly.20250820.abcdef',
|
||||
releaseVersion: '0.3.0-nightly.20250820.abcdef',
|
||||
npmTag: 'nightly',
|
||||
previousReleaseTag: 'v0.3.0-nightly.20250819.abcdef',
|
||||
});
|
||||
});
|
||||
|
||||
it('should use manual version when provided', () => {
|
||||
process.env.MANUAL_VERSION = '1.2.3';
|
||||
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
|
||||
expect(releaseTag).toBe('v1.2.3');
|
||||
expect(releaseVersion).toBe('1.2.3');
|
||||
expect(npmTag).toBe('latest');
|
||||
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', () => {
|
||||
@@ -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(
|
||||
'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.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
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',
|
||||
npmTag: 'nightly',
|
||||
};
|
||||
execSync.mockReturnValue(JSON.stringify(expectedJson));
|
||||
it('should correctly calculate the next version from a patch release', () => {
|
||||
process.env.IS_PREVIEW = 'true';
|
||||
|
||||
const result = execSync('node scripts/get-release-version.js').toString();
|
||||
expect(JSON.parse(result)).toEqual(expectedJson);
|
||||
vi.mocked(execSync).mockImplementation((command) => {
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user