Releasing: Utilizing Github Actions and Tagging for release. (#2852)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
matt korwel
2025-07-03 22:57:01 -05:00
committed by GitHub
parent 32db5ba0e1
commit d43ea268b0
20 changed files with 811 additions and 179 deletions

View File

@@ -1,50 +0,0 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'node:fs';
import path from 'node:path';
import _ from 'lodash';
function bindPackageDependencies() {
const scriptDir = process.cwd();
const currentPkgJsonPath = path.join(scriptDir, 'package.json');
const currentPkg = JSON.parse(fs.readFileSync(currentPkgJsonPath));
// assume packages are all under /<repo_root>/packages/
const packagesDir = path.join(path.dirname(scriptDir));
const geminiCodePkgs = fs
.readdirSync(packagesDir)
.filter(
(name) =>
fs.statSync(path.join(packagesDir, name)).isDirectory() &&
fs.existsSync(path.join(packagesDir, name, 'package.json')),
)
.map((packageDirname) => {
const packageJsonPath = path.join(
packagesDir,
packageDirname,
'package.json',
);
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
})
.reduce((pkgs, pkg) => ({ ...pkgs, [pkg.name]: pkg }), {});
currentPkg.dependencies = _.mapValues(
currentPkg.dependencies,
(value, key) => {
if (geminiCodePkgs[key]) {
console.log(
`Package ${currentPkg.name} has a dependency on ${key}. Updating dependent version.`,
);
return geminiCodePkgs[key].version;
}
return value;
},
);
const updatedPkgJson = JSON.stringify(currentPkg, null, 2) + '\n';
fs.writeFileSync(currentPkgJsonPath, updatedPkgJson);
}
bindPackageDependencies();

View File

@@ -1,42 +0,0 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'node:fs';
import path from 'node:path';
// Assuming script is run from a package directory (e.g., packages/cli)
const packageDir = process.cwd();
const rootDir = path.join(packageDir, '..', '..'); // Go up two directories to find the repo root
function getRepoVersion() {
// Read root package.json
const rootPackageJsonPath = path.join(rootDir, 'package.json');
const rootPackage = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'));
return rootPackage.version; // This version is now expected to be the full version string
}
const newVersion = getRepoVersion();
console.log(`Setting package version to: ${newVersion}`);
const packageJsonPath = path.join(packageDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
console.log(`Updating version for ${packageJsonPath}`);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
packageJson.version = newVersion;
fs.writeFileSync(
packageJsonPath,
JSON.stringify(packageJson, null, 2) + '\n',
'utf8',
);
} else {
console.error(
`Error: package.json not found in the current directory: ${packageJsonPath}`,
);
process.exit(1);
}
console.log('Done.');

View File

@@ -123,13 +123,17 @@ function buildImage(imageName, dockerfile) {
readFileSync(join(process.cwd(), 'package.json'), 'utf-8'),
).version;
const imageTag =
process.env.GEMINI_SANDBOX_IMAGE_TAG || imageName.split(':')[1];
const finalImageName = `${imageName.split(':')[0]}:${imageTag}`;
execSync(
`${buildCommand} ${
process.env.BUILD_SANDBOX_FLAGS || ''
} --build-arg CLI_VERSION_ARG=${npmPackageVersion} -f "${dockerfile}" -t "${imageName}" .`,
} --build-arg CLI_VERSION_ARG=${npmPackageVersion} -f "${dockerfile}" -t "${finalImageName}" .`,
{ stdio: buildStdout, shell: '/bin/bash' },
);
console.log(`built ${imageName}`);
console.log(`built ${finalImageName}`);
}
if (baseImage && baseDockerfile) {

65
scripts/check-versions.js Normal file
View File

@@ -0,0 +1,65 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { readFileSync } from 'fs';
import path from 'path';
function readPackageJson(dir) {
const p = path.join(dir, 'package.json');
return JSON.parse(readFileSync(p, 'utf-8'));
}
const root = readPackageJson('.');
const cli = readPackageJson('packages/cli');
const core = readPackageJson('packages/core');
const errors = [];
console.log('Checking version consistency...');
// 1. Check that all package versions are the same.
if (root.version !== cli.version || root.version !== core.version) {
errors.push(
`Version mismatch: root (${root.version}), cli (${cli.version}), core (${core.version})`,
);
} else {
console.log(`- All packages are at version ${root.version}.`);
}
// 2. Check that the cli's dependency on core matches the core version.
const coreDepVersion = cli.dependencies['@google/gemini-cli-core'];
const expectedCoreVersion = `^${core.version}`;
if (
coreDepVersion !== expectedCoreVersion &&
coreDepVersion !== 'file:../core'
) {
errors.push(
`CLI dependency on core is wrong: expected ${expectedCoreVersion} or "file:../core", got ${coreDepVersion}`,
);
} else {
console.log(`- CLI dependency on core (${coreDepVersion}) is correct.`);
}
// 3. Check that the sandbox image tag matches the root version.
const imageUri = root.config.sandboxImageUri;
const imageTag = imageUri.split(':').pop();
if (imageTag !== root.version) {
errors.push(
`Sandbox image tag mismatch: expected ${root.version}, got ${imageTag}`,
);
} else {
console.log(`- Sandbox image tag (${imageTag}) is correct.`);
}
if (errors.length > 0) {
console.error('\nVersion consistency checks failed:');
for (const error of errors) {
console.error(`- ${error}`);
}
process.exit(1);
}
console.log('\nAll version checks passed!');

View File

@@ -27,6 +27,7 @@ const root = join(__dirname, '..');
// remove npm install/build artifacts
rmSync(join(root, 'node_modules'), { recursive: true, force: true });
rmSync(join(root, 'bundle'), { recursive: true, force: true });
rmSync(join(root, 'packages/cli/src/generated/'), {
recursive: true,
force: true,

View File

@@ -1,37 +0,0 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// ES module equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Copy README.md to packages/core
const rootReadmePath = path.resolve(__dirname, '../README.md');
const coreReadmePath = path.resolve(__dirname, '../packages/core/README.md');
try {
fs.copyFileSync(rootReadmePath, coreReadmePath);
console.log('Copied root README.md to packages/core/');
} catch (err) {
console.error('Error copying README.md:', err);
process.exit(1);
}
// Copy README.md to packages/cli
const rootLicensePath = path.resolve(__dirname, '../LICENSE');
const coreLicensePath = path.resolve(__dirname, '../packages/core/LICENSE');
try {
fs.copyFileSync(rootLicensePath, coreLicensePath);
console.log('Copied root LICENSE to packages/core/');
} catch (err) {
console.error('Error copying LICENSE:', err);
process.exit(1);
}

View File

@@ -0,0 +1,51 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
// ES module equivalent of __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');
function copyFiles(packageName, filesToCopy) {
const packageDir = path.resolve(rootDir, 'packages', packageName);
if (!fs.existsSync(packageDir)) {
console.error(`Error: Package directory not found at ${packageDir}`);
process.exit(1);
}
console.log(`Preparing package: ${packageName}`);
for (const [source, dest] of Object.entries(filesToCopy)) {
const sourcePath = path.resolve(rootDir, source);
const destPath = path.resolve(packageDir, dest);
try {
fs.copyFileSync(sourcePath, destPath);
console.log(`Copied ${source} to packages/${packageName}/`);
} catch (err) {
console.error(`Error copying ${source}:`, err);
process.exit(1);
}
}
}
// Prepare 'core' package
copyFiles('core', {
'README.md': 'README.md',
LICENSE: 'LICENSE',
'.npmrc': '.npmrc',
});
// Prepare 'cli' package
copyFiles('cli', {
'README.md': 'README.md',
LICENSE: 'LICENSE',
});
console.log('Successfully prepared all packages.');

View File

@@ -19,9 +19,14 @@ if (!fs.existsSync(packageJsonPath)) {
errors.push(`Error: package.json not found in ${process.cwd()}`);
} else {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
if (packageJson.repository !== 'google-gemini/gemini-cli') {
if (
!packageJson.repository ||
typeof packageJson.repository !== 'object' ||
packageJson.repository.type !== 'git' ||
!packageJson.repository.url.includes('google-gemini/gemini-cli')
) {
errors.push(
`Error: The "repository" field in ${packageJsonPath} must be "google-gemini/gemini-cli".`,
`Error: The "repository" field in ${packageJsonPath} must be an object pointing to the "google-gemini/gemini-cli" git repository.`,
);
}
}

View File

@@ -20,33 +20,25 @@
import { execSync } from 'child_process';
const {
SANDBOX_IMAGE_REGISTRY,
SANDBOX_IMAGE_NAME,
npm_package_version,
npm_package_config_sandboxImageUri,
DOCKER_DRY_RUN,
GEMINI_SANDBOX_IMAGE_TAG,
} = process.env;
if (!SANDBOX_IMAGE_REGISTRY) {
if (!npm_package_config_sandboxImageUri) {
console.error(
'Error: SANDBOX_IMAGE_REGISTRY environment variable is not set.',
'Error: npm_package_config_sandboxImageUri environment variable is not set (should be run via npm).',
);
process.exit(1);
}
if (!SANDBOX_IMAGE_NAME) {
console.error('Error: SANDBOX_IMAGE_NAME environment variable is not set.');
process.exit(1);
}
let imageUri = npm_package_config_sandboxImageUri;
if (!npm_package_version) {
console.error(
'Error: npm_package_version environment variable is not set (should be run via npm).',
);
process.exit(1);
if (GEMINI_SANDBOX_IMAGE_TAG) {
const [baseUri] = imageUri.split(':');
imageUri = `${baseUri}:${GEMINI_SANDBOX_IMAGE_TAG}`;
}
const imageUri = `${SANDBOX_IMAGE_REGISTRY}/${SANDBOX_IMAGE_NAME}:${npm_package_version}`;
if (DOCKER_DRY_RUN) {
console.log(`DRY RUN: Would execute: docker push "${imageUri}"`);
} else {

68
scripts/version.js Normal file
View File

@@ -0,0 +1,68 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { execSync } from 'child_process';
import { readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
// A script to handle versioning and ensure all related changes are in a single, atomic commit.
function run(command) {
console.log(`> ${command}`);
execSync(command, { stdio: 'inherit' });
}
function readJson(filePath) {
return JSON.parse(readFileSync(filePath, 'utf-8'));
}
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>');
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`);
run(
`npm version ${versionType} --workspaces --no-git-tag-version --allow-same-version`,
);
// 3. Get the new version number from the root package.json
const rootPackageJsonPath = resolve(process.cwd(), 'package.json');
const newVersion = readJson(rootPackageJsonPath).version;
// 4. Update the sandboxImageUri in the root package.json
const rootPackageJson = readJson(rootPackageJsonPath);
if (rootPackageJson.config?.sandboxImageUri) {
rootPackageJson.config.sandboxImageUri =
rootPackageJson.config.sandboxImageUri.replace(/:.*$/, `:${newVersion}`);
console.log(`Updated sandboxImageUri in root to use version ${newVersion}`);
writeJson(rootPackageJsonPath, rootPackageJson);
}
// 5. Update the sandboxImageUri in the cli package.json
const cliPackageJsonPath = resolve(process.cwd(), 'packages/cli/package.json');
const cliPackageJson = readJson(cliPackageJsonPath);
if (cliPackageJson.config?.sandboxImageUri) {
cliPackageJson.config.sandboxImageUri =
cliPackageJson.config.sandboxImageUri.replace(/:.*$/, `:${newVersion}`);
console.log(
`Updated sandboxImageUri in cli package to use version ${newVersion}`,
);
writeJson(cliPackageJsonPath, cliPackageJson);
}
// 6. Run `npm install` to update package-lock.json.
run('npm install');
console.log(`Successfully bumped versions to v${newVersion}.`);