fix release workflow (#172)

This commit is contained in:
Yiheng Xu
2025-08-01 17:13:07 +08:00
committed by GitHub
parent bdf946a321
commit 999f3af098
4 changed files with 73 additions and 36 deletions

View File

@@ -37,7 +37,7 @@ jobs:
environment:
name: production-release
url: ${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.version.outputs.RELEASE_TAG }}
if: github.repository == 'google-gemini/gemini-cli'
if: github.repository == 'QwenLM/qwen-code'
permissions:
contents: write
packages: write
@@ -95,7 +95,9 @@ jobs:
npm run test:integration:sandbox:none
npm run test:integration:sandbox:docker
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
OPENAI_MODEL: ${{ secrets.OPENAI_MODEL }}
- name: Configure Git User
run: |
@@ -133,22 +135,22 @@ jobs:
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '20'
registry-url: 'https://wombat-dressing-room.appspot.com'
scope: '@google'
registry-url: 'https://registry.npmjs.org'
scope: '@qwen-code'
- name: Publish @google/gemini-cli-core
run: npm publish --workspace=@google/gemini-cli-core --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
- name: Publish @qwen-code/qwen-code-core
run: npm publish --workspace=@qwen-code/qwen-code-core --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.WOMBAT_TOKEN_CORE }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install latest core package
if: steps.vars.outputs.is_dry_run == 'false'
run: npm install @google/gemini-cli-core@${{ steps.version.outputs.RELEASE_VERSION }} --workspace=@google/gemini-cli --save-exact
run: npm install @qwen-code/qwen-code-core@${{ steps.version.outputs.RELEASE_VERSION }} --workspace=@qwen-code/qwen-code --save-exact
- name: Publish @google/gemini-cli
run: npm publish --workspace=@google/gemini-cli --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
- name: Publish @qwen-code/qwen-code
run: npm publish --workspace=@qwen-code/qwen-code --tag=${{ steps.version.outputs.NPM_TAG }} ${{ steps.vars.outputs.is_dry_run == 'true' && '--dry-run' || '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.WOMBAT_TOKEN_CLI }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release and Tag
if: ${{ steps.vars.outputs.is_dry_run == 'false' }}

View File

@@ -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 };

View File

@@ -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));

View File

@@ -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