mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-14 16:10:59 -07:00
working to move release into github actions
This commit is contained in:
@@ -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();
|
||||
@@ -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.');
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
51
scripts/prepare-package.js
Normal file
51
scripts/prepare-package.js
Normal 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.');
|
||||
@@ -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.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
77
scripts/version.js
Normal file
77
scripts/version.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @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} --workspaces --no-git-tag-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');
|
||||
|
||||
const commitMessage = `chore(release): v${newVersion}`;
|
||||
console.log(
|
||||
`All files updated. Committing version v${newVersion} with message: "${commitMessage}"...`,
|
||||
);
|
||||
|
||||
// 7. Add all the changed files to the git staging area.
|
||||
run(
|
||||
'git add package.json package-lock.json packages/cli/package.json packages/core/package.json',
|
||||
);
|
||||
|
||||
// 8. Create the atomic commit with all changes.
|
||||
run(`git commit --no-edit -m "${commitMessage}"`);
|
||||
|
||||
// 9. Create the git tag to match the commit.
|
||||
run(`git tag -a "v${newVersion}" -m "${commitMessage}"`);
|
||||
|
||||
console.log(`Successfully committed and tagged v${newVersion}.`);
|
||||
Reference in New Issue
Block a user