From c7fce4d6c9613113ee19b586613b12e6f26c2905 Mon Sep 17 00:00:00 2001 From: mkorwel Date: Fri, 24 Apr 2026 21:29:38 +0000 Subject: [PATCH] ci: use correct scope and registry for publishing --- .github/workflows/ci-bundling-trial.yml | 9 ++- scripts/prepare-package.js | 78 ++++++++++++++----------- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci-bundling-trial.yml b/.github/workflows/ci-bundling-trial.yml index da8848b16c..2dd8454eca 100644 --- a/.github/workflows/ci-bundling-trial.yml +++ b/.github/workflows/ci-bundling-trial.yml @@ -32,6 +32,10 @@ jobs: - name: 'Build project' run: 'npm run build' + - name: 'Prepare Packages with Scope' + run: 'node scripts/prepare-package.js --scope=@google-gemini' + shell: 'bash' + - name: 'Set version with SHA' run: | npm version 0.0.0-${{ github.sha }} --no-git-tag-version --workspaces @@ -39,14 +43,15 @@ jobs: - name: 'Configure npm for GitHub Packages' run: | + rm -f .npmrc echo "//npm.pkg.github.com/:_authToken=\${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc echo "@google-gemini:registry=https://npm.pkg.github.com" >> ~/.npmrc shell: 'bash' - name: 'Publish Packages' run: | - npm publish --workspace @google/gemini-cli-core - npm publish --workspace @google/gemini-cli + npm publish --workspace @google-gemini/gemini-cli-core --registry=https://npm.pkg.github.com + npm publish --workspace @google-gemini/gemini-cli --registry=https://npm.pkg.github.com shell: 'bash' test_ui_messages: diff --git a/scripts/prepare-package.js b/scripts/prepare-package.js index ff1dc137ff..7f3fd412cf 100644 --- a/scripts/prepare-package.js +++ b/scripts/prepare-package.js @@ -6,46 +6,56 @@ 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); -const __dirname = path.dirname(__filename); +const rootDir = process.cwd(); -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); - } +function getArg(name) { + const arg = process.argv.find((arg) => arg.startsWith(name)); + if (!arg) { + return null; } + return arg.split('=')[1]; } -// Prepare 'core' package -copyFiles('core', { - 'README.md': 'README.md', - LICENSE: 'LICENSE', - '.npmrc': '.npmrc', +function updatePackageJson(packagePath, updateFn) { + const packageJsonPath = path.resolve(rootDir, packagePath); + if (!fs.existsSync(packageJsonPath)) { + console.error(`Error: package.json not found at ${packageJsonPath}`); + process.exit(1); + } + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + updateFn(packageJson); + fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); + console.log(`Updated ${packagePath}`); +} + +const scope = getArg('--scope'); +if (!scope) { + console.error('Error: --scope argument is required.'); + process.exit(1); +} + +console.log(`Preparing packages with scope: ${scope}...`); + +// Update root package.json +updatePackageJson('package.json', (pkg) => { + pkg.name = `${scope}/gemini-cli`; }); -// Prepare 'cli' package -copyFiles('cli', { - 'README.md': 'README.md', - LICENSE: 'LICENSE', +// Update @google/gemini-cli-core +updatePackageJson('packages/core/package.json', (pkg) => { + pkg.name = `${scope}/gemini-cli-core`; }); -console.log('Successfully prepared all packages.'); +// Update @google/gemini-cli +updatePackageJson('packages/cli/package.json', (pkg) => { + pkg.name = `${scope}/gemini-cli`; + // Update dependency to point to the new scoped core package + if (pkg.dependencies && pkg.dependencies['@google/gemini-cli-core']) { + pkg.dependencies[`${scope}/gemini-cli-core`] = + `npm:${scope}/gemini-cli-core@^0.0.0`; + delete pkg.dependencies['@google/gemini-cli-core']; + } +}); + +console.log('Successfully prepared packages.');