Merge tag 'v0.3.0' into chore/sync-gemini-cli-v0.3.0

This commit is contained in:
mingholy.lmh
2025-09-10 21:01:40 +08:00
583 changed files with 30160 additions and 10770 deletions

View File

@@ -17,10 +17,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'node:child_process';
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = join(__dirname, '..');

View File

@@ -17,9 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { writeFileSync } from 'fs';
import { join } from 'path';
import { execSync } from 'node:child_process';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
if (!process.cwd().includes('packages')) {
console.error('must be invoked from a package directory');

View File

@@ -17,10 +17,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { join } from 'path';
import os from 'os';
import { execSync } from 'node:child_process';
import {
chmodSync,
existsSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs';
import { join } from 'node:path';
import os from 'node:os';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import cliPkgJson from '../packages/cli/package.json' with { type: 'json' };
@@ -53,9 +59,10 @@ try {
sandboxCommand = execSync('node scripts/sandbox_command.js')
.toString()
.trim();
} catch {
} catch (e) {
console.warn('ERROR: could not detect sandbox container command');
process.exit(0);
console.error(e);
process.exit(1);
}
if (sandboxCommand === 'sandbox-exec') {

View File

@@ -17,9 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'node:child_process';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = join(__dirname, '..');

View File

@@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'fs';
import path from 'path';
import os from 'os'; // Import os module
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os'; // Import os module
// --- Configuration ---
const cliPackageDir = path.resolve('packages', 'cli'); // Base directory for the CLI package

View File

@@ -17,9 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { rmSync, readFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { rmSync, readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { globSync } from 'glob';
const __dirname = dirname(fileURLToPath(import.meta.url));

View File

@@ -17,9 +17,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { copyFileSync, existsSync, mkdirSync } from 'fs';
import { dirname, join, basename } from 'path';
import { fileURLToPath } from 'url';
import { copyFileSync, existsSync, mkdirSync } from 'node:fs';
import { dirname, join, basename } from 'node:path';
import { fileURLToPath } from 'node:url';
import { glob } from 'glob';
const __dirname = dirname(fileURLToPath(import.meta.url));

View File

@@ -20,8 +20,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
const sourceDir = path.join('src');
const targetDir = path.join('dist', 'src');

View File

@@ -17,10 +17,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
import { dirname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'node:child_process';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { dirname, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readPackageUp } from 'read-package-up';
const __dirname = dirname(fileURLToPath(import.meta.url));

View File

@@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
import { execSync } from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
function getPackageVersion() {
const packageJsonPath = path.resolve(process.cwd(), 'package.json');
@@ -14,6 +14,20 @@ function getPackageVersion() {
return packageJson.version;
}
function getLatestStableTag() {
// Fetches all tags, then filters for the latest stable (non-prerelease) tag.
const tags = execSync('git tag --list "v*.*.*" --sort=-v:refname')
.toString()
.split('\n');
const latestStableTag = tags.find((tag) =>
tag.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/),
);
if (!latestStableTag) {
throw new Error('Could not find a stable tag.');
}
return latestStableTag;
}
function incrementPatchVersion(version) {
const parts = version.split('.');
const major = parseInt(parts[0]);
@@ -46,6 +60,12 @@ function getLatestNightlyCount() {
}
}
function getNextVersionString(stableVersion, minorIncrement) {
const [major, minor] = stableVersion.substring(1).split('.');
const nextMinorVersion = parseInt(minor, 10) + minorIncrement;
return `${major}.${nextMinorVersion}.0`;
}
export function getNightlyTagName() {
const version = getPackageVersion();
const nextVersion = incrementPatchVersion(version);
@@ -54,21 +74,50 @@ export function getNightlyTagName() {
return `v${nextVersion}-nightly.${nightlyCount}`;
}
export function getPreviewTagName(stableVersion) {
const version = getNextVersionString(stableVersion, 1);
return `v${version}-preview`;
}
function getPreviousReleaseTag(isNightly) {
if (isNightly) {
console.error('Finding latest nightly release...');
return execSync(
`gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | contains("nightly"))] | .[0].tagName'`,
)
.toString()
.trim();
} else {
console.error('Finding latest STABLE release (excluding pre-releases)...');
return execSync(
`gh release list --limit 100 --json tagName | jq -r '[.[] | select(.tagName | (contains("nightly") or contains("preview")) | not)] | .[0].tagName'`,
)
.toString()
.trim();
}
}
export function getReleaseVersion() {
const isNightly = process.env.IS_NIGHTLY === 'true';
const isPreview = process.env.IS_PREVIEW === 'true';
const manualVersion = process.env.MANUAL_VERSION;
let releaseTag;
if (isNightly) {
console.error('Calculating next nightly version...');
releaseTag = getNightlyTagName();
const stableVersion = getLatestStableTag();
releaseTag = getNightlyTagName(stableVersion);
} else if (isPreview) {
console.error('Calculating next preview version...');
const stableVersion = getLatestStableTag();
releaseTag = getPreviewTagName(stableVersion);
} else if (manualVersion) {
console.error(`Using manual version: ${manualVersion}`);
releaseTag = manualVersion;
} else {
throw new Error(
'Error: No version specified and this is not a nightly release.',
'Error: No version specified and this is not a nightly or preview release.',
);
}
@@ -105,7 +154,9 @@ export function getReleaseVersion() {
}
}
return { releaseTag, releaseVersion, npmTag };
const previousReleaseTag = getPreviousReleaseTag(isNightly);
return { releaseTag, releaseVersion, npmTag, previousReleaseTag };
}
if (process.argv[1] === new URL(import.meta.url).pathname) {

View File

@@ -6,10 +6,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
import path from 'path';
import fs from 'fs';
import { spawn, execSync } from 'child_process';
import { fileURLToPath } from 'url';
import path from 'node:path';
import fs from 'node:fs';
import { spawn, execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import {
BIN_DIR,
OTEL_DIR,
@@ -82,7 +82,7 @@ async function main() {
'otelcol-contrib',
false, // isJaeger = false
).catch((e) => {
console.error(`<EFBFBD><EFBFBD><EFBFBD> Error getting otelcol-contrib: ${e.message}`);
console.error(`🛑 Error getting otelcol-contrib: ${e.message}`);
return null;
});
if (!otelcolPath) process.exit(1);

View File

@@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// ES module equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);

View File

@@ -17,11 +17,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { execSync } from 'child_process';
import { existsSync, readFileSync } from 'fs';
import { join, dirname } from 'path';
import { execSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import stripJsonComments from 'strip-json-comments';
import os from 'os';
import os from 'node:os';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import dotenv from 'dotenv';

View File

@@ -17,10 +17,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { spawn, execSync } from 'child_process';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { readFileSync } from 'fs';
import { spawn, execSync } from 'node:child_process';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = join(__dirname, '..');

View File

@@ -6,9 +6,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'child_process';
import { join } from 'path';
import { existsSync, readFileSync } from 'fs';
import { execSync } from 'node:child_process';
import { join } from 'node:path';
import { existsSync, readFileSync } from 'node:fs';
const projectRoot = join(import.meta.dirname, '..');

View File

@@ -6,9 +6,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import path from 'path';
import fs from 'fs';
import { spawn, execSync } from 'child_process';
import path from 'node:path';
import fs from 'node:fs';
import { spawn, execSync } from 'node:child_process';
import {
OTEL_DIR,
BIN_DIR,

View File

@@ -6,12 +6,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
import path from 'path';
import fs from 'fs';
import net from 'net';
import os from 'os';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import path from 'node:path';
import fs from 'node:fs';
import net from 'node:net';
import os from 'node:os';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import crypto from 'node:crypto';
const __filename = fileURLToPath(import.meta.url);

View File

@@ -4,8 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
import path from 'path';
import { fileURLToPath } from 'url';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// Test how paths are normalized
function testPathNormalization() {

View File

@@ -6,58 +6,84 @@
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(),
},
};
});
// Mock fs module
vi.mock('fs', () => ({
default: {
readFileSync: vi.fn(),
},
}));
describe('getReleaseVersion', () => {
describe('getReleaseVersion', async () => {
// Dynamically import execSync and fs after mocking
const { execSync } = await import('node:child_process');
const fs = await import('fs');
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';
vi.mocked(fs.default.readFileSync).mockReturnValue(
JSON.stringify({ version: '0.1.0' }),
);
// Mock git tag command to return empty (no existing nightly tags)
vi.mocked(execSync).mockReturnValue('');
const { releaseTag, releaseVersion, npmTag } = getReleaseVersion();
vi.mocked(execSync).mockImplementation((command) => {
if (command.includes('git tag --list "v*.*.*"')) {
return 'v0.1.0\nv0.0.1'; // Mock stable tags for getLatestStableTag
}
if (command.includes('git tag -l "v0.1.1-nightly.*"')) {
return ''; // No existing nightly tags
}
if (command.includes('gh release list')) {
return 'v0.1.0-nightly.5'; // Previous nightly release
}
return '';
});
const { releaseTag, releaseVersion, npmTag, previousReleaseTag } =
getReleaseVersion();
expect(releaseTag).toBe('v0.1.1-nightly.0');
expect(releaseVersion).toBe('0.1.1-nightly.0');
expect(npmTag).toBe('nightly');
expect(previousReleaseTag).toBe('v0.1.0-nightly.5');
});
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 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', () => {
@@ -81,9 +107,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.',
);
});
@@ -93,18 +119,31 @@ 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.1-nightly.0',
releaseVersion: '0.1.1-nightly.0',
npmTag: 'nightly',
};
execSync.mockReturnValue(JSON.stringify(expectedJson));
it('should generate nightly version with existing nightly tags', () => {
process.env.IS_NIGHTLY = 'true';
vi.mocked(fs.default.readFileSync).mockReturnValue(
JSON.stringify({ version: '1.2.3' }),
);
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 --list "v*.*.*"')) {
return 'v1.2.3\nv1.2.2\nv1.2.1\nv1.2.0\nv1.1.0';
}
if (command.includes('git tag -l "v1.2.4-nightly.*"')) {
return 'v1.2.4-nightly.0\nv1.2.4-nightly.1\nv1.2.4-nightly.2'; // Existing nightly tags
}
if (command.includes('gh release list')) {
return 'v1.2.4-nightly.2'; // Previous nightly release
}
return '';
});
const result = getReleaseVersion();
expect(result.releaseTag).toBe('v1.2.4-nightly.3');
expect(result.releaseVersion).toBe('1.2.4-nightly.3');
expect(result.npmTag).toBe('nightly');
expect(result.previousReleaseTag).toBe('v1.2.4-nightly.2');
});
});

View File

@@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { execSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
// A script to handle versioning and ensure all related changes are in a single, atomic commit.