From 7c81b1837e0626311a8d7f0a5ef5c14f35284dc8 Mon Sep 17 00:00:00 2001 From: mkorwel Date: Fri, 24 Oct 2025 09:02:32 -0700 Subject: [PATCH] pr clean up --- .github/actions/publish-release/action.yml | 76 +++++++++------ .github/workflows/bundle-size.yml | 12 ++- .github/workflows/e2e.yml | 37 +++++--- .github/workflows/orchestrator.yml | 10 +- CONTRIBUTING.md | 45 ++++----- package.json | 3 +- scripts/configure-registry.js | 102 ++++++--------------- 7 files changed, 138 insertions(+), 147 deletions(-) diff --git a/.github/actions/publish-release/action.yml b/.github/actions/publish-release/action.yml index 46025d5dce..9fee37cf73 100644 --- a/.github/actions/publish-release/action.yml +++ b/.github/actions/publish-release/action.yml @@ -94,16 +94,20 @@ runs: working-directory: '${{ inputs.working-directory }}' id: 'release_branch' shell: 'bash' + env: + RELEASE_TAG: '${{ inputs.release-tag }}' run: | - BRANCH_NAME="release/${{ inputs.release-tag }}" + BRANCH_NAME="release/${RELEASE_TAG}" git switch -c "${BRANCH_NAME}" echo "BRANCH_NAME=${BRANCH_NAME}" >> "${GITHUB_OUTPUT}" - name: 'โฌ†๏ธ Update package versions' working-directory: '${{ inputs.working-directory }}' shell: 'bash' + env: + RELEASE_VERSION: '${{ inputs.release-version }}' run: | - npm run release:version "${{ inputs.release-version }}" + npm run release:version "${RELEASE_VERSION}" - name: '๐Ÿ’พ Commit and Conditionally Push package versions' working-directory: '${{ inputs.working-directory }}' @@ -151,10 +155,11 @@ runs: working-directory: '${{ inputs.working-directory }}' env: NODE_AUTH_TOKEN: '${{ inputs.github-token }}' + DRY_RUN: '${{ inputs.dry-run }}' shell: 'bash' run: | npm publish \ - --dry-run="${{ inputs.dry-run }}" \ + --dry-run="${DRY_RUN}" \ --no-tag - name: 'Configure npm for publishing to npm' @@ -181,22 +186,29 @@ runs: working-directory: '${{ inputs.working-directory }}' env: NODE_AUTH_TOKEN: '${{ steps.core-token.outputs.auth-token }}' + DRY_RUN: '${{ inputs.dry-run }}' + CORE_PACKAGE_NAME: '${{ inputs.core-package-name }}' shell: 'bash' run: | npm publish \ - --dry-run="${{ inputs.dry-run }}" \ - --workspace="${{ inputs.core-package-name }}" \ + --dry-run="${DRY_RUN}" \ + --workspace="${CORE_PACKAGE_NAME}" \ --no-tag - npm dist-tag rm ${{ inputs.core-package-name }} false --silent + npm dist-tag rm ${CORE_PACKAGE_NAME} false --silent - name: '๐Ÿ”— Install latest core package' - if: "${{ inputs.dry-run != 'true' && inputs.use-bundle-release == 'false' }}" + if: "${{ inputs.dry-run == 'false' && inputs.use-bundle-release == 'false' }}" working-directory: '${{ inputs.working-directory }}' shell: 'bash' + env: + CORE_PACKAGE_NAME: '${{ inputs.core-package-name }}' + RELEASE_VERSION: '${{ inputs.release-version }}' + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' + A2A_PACKAGE_NAME: '${{ inputs.a2a-package-name }}' run: | - npm install "${{ inputs.core-package-name }}@${{ inputs.release-version }}" \ - --workspace="${{ inputs.cli-package-name }}" \ - --workspace="${{ inputs.a2a-package-name }}" \ + npm install "${CORE_PACKAGE_NAME}@${RELEASE_VERSION}" \ + --workspace="${CLI_PACKAGE_NAME}" \ + --workspace="${A2A_PACKAGE_NAME}" \ --save-exact - name: 'Get CLI Token' @@ -215,12 +227,14 @@ runs: working-directory: '${{ inputs.working-directory }}' env: NODE_AUTH_TOKEN: '${{ steps.cli-token.outputs.auth-token }}' + DRY_RUN: '${{ inputs.dry-run }}' + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' shell: 'bash' run: | npm publish \ - --dry-run="${{ inputs.dry-run }}" \ + --dry-run="${DRY_RUN}" \ --no-tag - npm dist-tag rm ${{ inputs.cli-package-name }} false --silent + npm dist-tag rm ${CLI_PACKAGE_NAME} false --silent - name: 'Get a2a-server Token' if: "${{ inputs.use-bundle-release == 'false' }}" @@ -238,17 +252,19 @@ runs: working-directory: '${{ inputs.working-directory }}' env: NODE_AUTH_TOKEN: '${{ steps.a2a-token.outputs.auth-token }}' + DRY_RUN: '${{ inputs.dry-run }}' + A2A_PACKAGE_NAME: '${{ inputs.a2a-package-name }}' shell: 'bash' # Tag staging for initial release run: | npm publish \ - --dry-run="${{ inputs.dry-run }}" \ - --workspace="${{ inputs.a2a-package-name }}" \ + --dry-run="${DRY_RUN}" \ + --workspace="${A2A_PACKAGE_NAME}" \ --no-tag - npm dist-tag rm ${{ inputs.a2a-package-name }} false --silent + npm dist-tag rm ${A2A_PACKAGE_NAME} false --silent - name: '๐Ÿ”ฌ Verify NPM release by version' - if: "${{ inputs.dry-run != 'true' && inputs.force-skip-tests != 'true' && inputs.use-bundle-release == 'false' }}" + if: "${{ inputs.dry-run == 'false' && inputs.force-skip-tests == 'false' && inputs.use-bundle-release == 'false' }}" uses: './.github/actions/verify-release' with: npm-package: '${{ inputs.cli-package-name }}@${{ inputs.release-version }}' @@ -275,31 +291,39 @@ runs: working-directory: '${{ inputs.working-directory }}' - name: '๐Ÿ”ฌ Verify Bundled NPM release by version' - if: "${{ inputs.dry-run != 'true' && inputs.force-skip-tests != 'true' && inputs.use-bundle-release == 'true' }}" + if: "${{ inputs.dry-run == 'false' && inputs.force-skip-tests == 'false' && inputs.use-bundle-release == 'true' }}" working-directory: '${{ inputs.working-directory }}' shell: 'bash' + env: + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' + RELEASE_VERSION: '${{ inputs.release-version }}' run: | - npx -y ${{ inputs.cli-package-name }}@${{ inputs.release-version }} --version + npx -y ${CLI_PACKAGE_NAME}@${RELEASE_VERSION} --version - name: '๐ŸŽ‰ Create GitHub Release' working-directory: '${{ inputs.working-directory }}' - if: "${{ inputs.dry-run != 'true' && inputs.skip-github-release != 'true' && inputs.npm-tag != 'dev' && inputs.npm-registry-url != 'https://npm.pkg.github.com/' }}" + if: "${{ inputs.dry-run == 'false' && inputs.skip-github-release == 'false' && inputs.npm-tag != 'dev' && inputs.npm-registry-url != 'https://npm.pkg.github.com/' }}" env: GITHUB_TOKEN: '${{ inputs.github-token }}' + RELEASE_TAG: '${{ inputs.release-tag }}' + BRANCH_NAME: '${{ steps.release_branch.outputs.BRANCH_NAME }}' + PREVIOUS_TAG: '${{ inputs.previous-tag }}' shell: 'bash' run: | - gh release create "${{ inputs.release-tag }}" \ + gh release create "${RELEASE_TAG}" \ bundle/gemini.js \ - --target "${{ steps.release_branch.outputs.BRANCH_NAME }}" \ - --title "Release ${{ inputs.release-tag }}" \ - --notes-start-tag "${{ inputs.previous-tag }}" \ + --target "${BRANCH_NAME}" \ + --title "Release ${RELEASE_TAG}" \ + --notes-start-tag "${PREVIOUS_TAG}" \ --generate-notes - name: '๐Ÿงน Clean up release branch' working-directory: '${{ inputs.working-directory }}' - if: "${{ inputs.dry-run != 'true' && inputs.skip-branch-cleanup != 'true' }}" + if: "${{ inputs.dry-run == 'false' && inputs.skip-branch-cleanup == 'false' }}" continue-on-error: true shell: 'bash' + env: + BRANCH_NAME: '${{ steps.release_branch.outputs.BRANCH_NAME }}' run: | - echo "Cleaning up release branch ${{ steps.release_branch.outputs.BRANCH_NAME }}..." - git push origin --delete "${{ steps.release_branch.outputs.BRANCH_NAME }}" + echo "Cleaning up release branch ${BRANCH_NAME}..." + git push origin --delete "${BRANCH_NAME}" diff --git a/.github/workflows/bundle-size.yml b/.github/workflows/bundle-size.yml index b7d026614d..0ef8e48a77 100644 --- a/.github/workflows/bundle-size.yml +++ b/.github/workflows/bundle-size.yml @@ -30,13 +30,15 @@ jobs: node-version-file: '.nvmrc' cache: 'npm' - - name: 'Configure npm for GitHub Packages' - run: | - echo "@google-gemini:registry=https://npm.pkg.github.com/" > .npmrc - echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc + - name: 'Setup NPMRC' + uses: './.github/actions/setup-npmrc' + with: + github-token: '${{ secrets.GITHUB_TOKEN }}' - name: 'Install dependencies' - run: 'npm install @google-gemini/gemini-cli@${{ inputs.version }}' + env: + VERSION: '${{ inputs.version }}' + run: 'npm install @google-gemini/gemini-cli@${{ env.VERSION }}' - name: 'Check Bundle Size' uses: 'preactjs/compressed-size-action@946a292cd35bd1088e0d7eb92b69d1a8d5b5d76a' diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 8a941c9b4d..65a7a12dd7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -21,11 +21,11 @@ jobs: e2e_linux: name: 'E2E Test (Linux) - ${{ matrix.sandbox }}' if: | - (github.event_name == 'push' || + github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' || - (github.event.pull_request.head.repo.full_name == github.repository) || - (github.event.label.name == 'maintainer:e2e:ok')) + github.event.pull_request.head.repo.full_name == github.repository || + github.event.label.name == 'maintainer:e2e:ok' runs-on: 'gemini-cli-ubuntu-16-core' strategy: fail-fast: false @@ -65,7 +65,10 @@ jobs: run: 'docker pull ${{ inputs.image-uri }}' - name: 'Install dependencies' - run: 'npm install ${{ inputs.cli-package-name }}@${{ inputs.version }}' + env: + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' + VERSION: '${{ inputs.version }}' + run: 'npm install ${{ env.CLI_PACKAGE_NAME }}@${{ env.VERSION }}' - name: 'Run E2E tests' env: @@ -85,11 +88,11 @@ jobs: e2e_mac: name: 'E2E Test (macOS)' if: | - (github.event_name == 'push' || + github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' || - (github.event.pull_request.head.repo.full_name == github.repository) || - (github.event.label.name == 'maintainer:e2e:ok')) + github.event.pull_request.head.repo.full_name == github.repository || + github.event.label.name == 'maintainer:e2e:ok' runs-on: 'macos-latest' steps: - name: 'Checkout (fork)' @@ -116,7 +119,10 @@ jobs: github-token: '${{ secrets.GITHUB_TOKEN }}' - name: 'Install dependencies' - run: 'npm install @google-gemini/gemini-cli@${{ inputs.version }}' + env: + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' + VERSION: '${{ inputs.version }}' + run: 'npm install ${{ env.CLI_PACKAGE_NAME }}@${{ env.VERSION }}' - name: 'Fix rollup optional dependencies on macOS' if: "runner.os == 'macOS'" @@ -135,11 +141,11 @@ jobs: e2e_windows: name: 'Slow E2E - Win' if: | - (github.event_name == 'push' || + github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' || - (github.event.pull_request.head.repo.full_name == github.repository) || - (github.event.label.name == 'maintainer:e2e:ok')) + github.event.pull_request.head.repo.full_name == github.repository || + github.event.label.name == 'maintainer:e2e:ok' runs-on: 'gemini-cli-windows-16-core' continue-on-error: true @@ -187,7 +193,10 @@ jobs: github-token: '${{ secrets.GITHUB_TOKEN }}' - name: 'Install dependencies' - run: 'npm install ${{ inputs.cli-package-name }}@${{ inputs.version }}' + env: + CLI_PACKAGE_NAME: '${{ inputs.cli-package-name }}' + VERSION: '${{ inputs.version }}' + run: 'npm install ${{ env.CLI_PACKAGE_NAME }}@${{ env.VERSION }}' shell: 'pwsh' - name: 'Run E2E tests' @@ -210,8 +219,8 @@ jobs: github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' || - (github.event.pull_request.head.repo.full_name == github.repository) || - (github.event.label.name == 'maintainer:e2e:ok') + github.event.pull_request.head.repo.full_name == github.repository || + github.event.label.name == 'maintainer:e2e:ok' ) needs: - 'e2e_linux' diff --git a/.github/workflows/orchestrator.yml b/.github/workflows/orchestrator.yml index 6b1460e9ad..860c9a5636 100644 --- a/.github/workflows/orchestrator.yml +++ b/.github/workflows/orchestrator.yml @@ -46,10 +46,14 @@ jobs: npm-registry-url: '${{ steps.get-vars.outputs.npm-registry-url }}' steps: - id: 'get-vars' + env: + CLI_PACKAGE_NAME: '${{ vars.CLI_PACKAGE_NAME }}' + NPM_REGISTRY_SCOPE: '${{ vars.NPM_REGISTRY_SCOPE }}' + NPM_REGISTRY_URL: '${{ vars.NPM_REGISTRY_URL }}' run: | - echo 'cli-package-name=${{ vars.CLI_PACKAGE_NAME }}' >> "$GITHUB_OUTPUT" - echo 'npm-registry-scope=${{ vars.NPM_REGISTRY_SCOPE }}' >> "$GITHUB_OUTPUT" - echo 'npm-registry-url=${{ vars.NPM_REGISTRY_URL }}' >> "$GITHUB_OUTPUT" + echo "cli-package-name=${CLI_PACKAGE_NAME}" >> "$GITHUB_OUTPUT" + echo "npm-registry-scope=${NPM_REGISTRY_SCOPE}" >> "$GITHUB_OUTPUT" + echo "npm-registry-url=${NPM_REGISTRY_URL}" >> "$GITHUB_OUTPUT" build-and-publish: name: 'Build and Publish CI Bundle' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26222462c1..317b33bf44 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -279,21 +279,27 @@ npm run lint - **Imports:** Pay special attention to import paths. The project uses ESLint to enforce restrictions on relative imports between packages. -### Working with Pre-Release Versions (Development) +### Setting Up Your NPM Environment -This project uses **GitHub Packages** to host development and pre-release -versions of the CLI. To install these versions, you must configure your -user-level `~/.npmrc` file to authenticate with the GitHub registry. +**Note:** The following instructions are intended for contributors who need to +work with pre-release versions hosted on the private GitHub Packages registry. +General contributors who only use the public `npmjs.org` registry may not need +to perform this setup. -We have created a script to automate this process for you. +This project uses a hybrid registry model: +- Production packages (e.g., `@google/gemini-cli`) are published to `npmjs.org`. +- Pre-release and development packages (e.g., `@google-gemini/gemini-cli`) are + published to **GitHub Packages**. -#### Setting Up Your Environment for Development (Recommended) +To work with both registries, you need to configure your user-level `~/.npmrc` +file to authenticate with GitHub Packages. We have a script to automate this. -To automatically configure your environment to use the GitHub Packages registry, -run the following command: +#### Configure Your `~/.npmrc` File + +Run the following command to automatically configure your `~/.npmrc` file: ```bash -npm run use-dev +npm run setup-npmrc ``` This command will: @@ -302,23 +308,12 @@ This command will: installed and that you are logged in. 2. **Back up** your existing `~/.npmrc` to `~/.npmrc.bak` if a backup doesn't already exist. -3. **Automatically add** the necessary configuration to your `~/.npmrc` file. +3. **Overwrite** your `~/.npmrc` with the correct configuration to pull + packages from both `npmjs.org` and `npm.pkg.github.com` based on their scope. -This setup is required for installing pre-release packages with the -`@google-gemini` scope, both locally within a project and globally (e.g., -`npm install -g @google-gemini/gemini-cli@`). - -#### Switching Back to the Production Registry - -To automatically remove the development configuration and revert to the public -npm registry (`npmjs.org`), you can run: - -```bash -npm run use-prod -``` - -This command will safely remove the lines added by the `use-dev` script from -your `~/.npmrc` file. +After running this, you can install packages from both registries without any +further configuration. If your GitHub token expires, you can simply run the +command again to update it. ### Project Structure diff --git a/package.json b/package.json index c4b0f1ef4c..b431256b25 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,7 @@ "check:lockfile": "node scripts/check-lockfile.js", "clean": "node scripts/clean.js", "pre-commit": "node scripts/pre-commit.js", - "use-dev": "node scripts/configure-registry.js dev", - "use-prod": "node scripts/configure-registry.js prod" + "setup-npmrc": "node scripts/configure-registry.js" }, "overrides": { "wrap-ansi": "9.0.2", diff --git a/scripts/configure-registry.js b/scripts/configure-registry.js index bb02d35b89..39871deda9 100644 --- a/scripts/configure-registry.js +++ b/scripts/configure-registry.js @@ -6,18 +6,16 @@ /** * @fileoverview This script automates the configuration of the user's - * global .npmrc file to switch between the production npm registry (npmjs.org) - * and the development registry (GitHub Packages). + * global .npmrc file to work with this repository's development workflow. * * Rationale: - * While a developer could manually configure their .npmrc file, this script - * provides a consistent, automated, and less error-prone way to manage - * registry configurations. It simplifies the process of switching between - * consuming production packages and pre-release packages for development - * and testing, which is a common workflow in this project. + * This project uses a hybrid registry setup: + * - Production packages (`@google/gemini-cli`) are on the public npmjs.org registry. + * - Pre-release packages (`@google-gemini/gemini-cli`) are on the GitHub Packages registry. * - * The script also handles backing up and restoring the user's existing - * .npmrc file, preventing accidental data loss. + * This script provides a consistent, automated, and less error-prone way to + * configure the necessary scopes and authentication for both registries. It + * backs up the user's existing .npmrc, making it a safe, one-time setup. */ import fs from 'node:fs'; @@ -25,14 +23,14 @@ import path from 'node:path'; import os from 'node:os'; import { execSync } from 'node:child_process'; -const arg = process.argv[2]; const homedir = os.homedir(); const npmrcPath = path.join(homedir, '.npmrc'); const backupPath = path.join(homedir, '.npmrc.bak'); const GITHUB_REGISTRY_URL = 'https://npm.pkg.github.com/'; const GITHUB_SCOPE = '@google-gemini'; -const REGISTRY_LINE = `${GITHUB_SCOPE}:registry=${GITHUB_REGISTRY_URL}`; +const PROD_SCOPE = '@google'; +const PROD_REGISTRY_URL = 'https://registry.npmjs.org/'; function checkGhCli() { try { @@ -78,10 +76,8 @@ function getGhAuthToken() { } } -function setupDev() { - console.log( - 'Configuring your global ~/.npmrc for `dev` (GitHub Packages)...', - ); +function setupNpmrc() { + console.log('Configuring your global ~/.npmrc for development...'); if (!checkGhCli() || !getGhAuthStatus()) { process.exit(1); @@ -92,68 +88,30 @@ function setupDev() { process.exit(1); } - const AUTH_LINE = `//npm.pkg.github.com/:_authToken=${token}`; - let npmrcContent = ''; - - if (fs.existsSync(npmrcPath)) { - npmrcContent = fs.readFileSync(npmrcPath, 'utf-8'); - if (npmrcContent.includes(REGISTRY_LINE)) { - console.log('โœ… Your ~/.npmrc file is already configured for dev.'); - return; - } - // Create a backup if one doesn't already exist - if (!fs.existsSync(backupPath)) { - fs.copyFileSync(npmrcPath, backupPath); - console.log(`Backed up your existing configuration to ${backupPath}`); - } + // Back up the original .npmrc if it exists and a backup doesn't already. + if (fs.existsSync(npmrcPath) && !fs.existsSync(backupPath)) { + fs.copyFileSync(npmrcPath, backupPath); + console.log(`Backed up your existing configuration to ${backupPath}`); } const newContent = [ - npmrcContent, - `\n# Added by gemini-cli for dev environment`, - REGISTRY_LINE, - AUTH_LINE, - ] - .join('\n') - .trim(); + `# Added by gemini-cli setup`, + `# Configures scopes for both production and development registries`, + ``, + `# Production packages from npmjs.org`, + `${PROD_SCOPE}:registry=${PROD_REGISTRY_URL}`, + ``, + `# Pre-release packages from GitHub Packages`, + `${GITHUB_SCOPE}:registry=${GITHUB_REGISTRY_URL}`, + `//${new URL(GITHUB_REGISTRY_URL).hostname}/:_authToken=${token}`, + ``, + ].join('\n'); - fs.writeFileSync(npmrcPath, newContent + '\n'); - console.log(`โœ… Successfully updated your ~/.npmrc file.`); + fs.writeFileSync(npmrcPath, newContent); + console.log(`โœ… Successfully configured your ~/.npmrc file.`); console.log( - 'You can now install pre-release packages, e.g., `npm install -g @google-gemini/gemini-cli@`', + 'You can now install both production and pre-release packages.', ); } -function setupProd() { - console.log('Configuring your global ~/.npmrc for `prod` (npmjs.org)...'); - if (!fs.existsSync(backupPath)) { - console.log('No backup file (`~/.npmrc.bak`) found. No changes were made.'); - console.log( - 'If you have manually removed the dev configuration, you are already configured for prod.', - ); - return; - } - - try { - fs.copyFileSync(backupPath, npmrcPath); - console.log( - `โœ… Successfully restored your configuration from ${backupPath}`, - ); - // Optional: remove the backup file after successful restoration - // fs.unlinkSync(backupPath); - // console.log(`Cleaned up backup file: ${backupPath}`); - } catch (err) { - console.error(`Error restoring configuration: ${err}`); - process.exit(1); - } -} - -if (arg === 'dev') { - setupDev(); -} else if (arg === 'prod') { - setupProd(); -} else { - console.error('Invalid argument. Please use `dev` or `prod`.'); - console.error('Usage: node scripts/configure-registry.js '); - process.exit(1); -} +setupNpmrc(); \ No newline at end of file