diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 1264579247..b847b2b870 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -33,10 +33,10 @@ jobs: - name: 'Install dependencies' run: 'npm ci' - - 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: 'Bundle' run: 'npm run bundle' diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5d63c1e1fe..1661f25b84 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -9,6 +9,10 @@ on: description: 'The version of the published package' required: true type: 'string' + cli-package-name: + description: 'The name of the CLI package to install' + required: true + type: 'string' secrets: GEMINI_API_KEY: required: true @@ -31,7 +35,6 @@ jobs: - 'sandbox:docker' node-version: - '20.x' - steps: - name: 'Checkout (fork)' uses: 'actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955' # ratchet:actions/checkout@v5 @@ -46,15 +49,13 @@ jobs: with: ref: '${{ github.event.inputs.branch_ref || github.ref }}' - - 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 }}' - - - name: 'Set up Docker' + run: 'npm install ${{ inputs.cli-package-name }}@${{ inputs.version }}' if: "matrix.sandbox == 'sandbox:docker'" uses: 'docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435' # ratchet:docker/setup-buildx-action@v3 @@ -100,10 +101,10 @@ jobs: with: node-version: '20.x' - - 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 }}' @@ -171,14 +172,13 @@ jobs: npm config set registry https://registry.npmjs.org/ shell: 'pwsh' - - 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 - shell: 'pwsh' + - 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 }}' + run: 'npm install ${{ inputs.cli-package-name }}@${{ inputs.version }}' shell: 'pwsh' - name: 'Run E2E tests' @@ -216,4 +216,4 @@ jobs: echo "One or more E2E jobs failed." exit 1 fi - echo "All required E2E jobs passed!" + echo "All required E2E jobs passed!" \ No newline at end of file diff --git a/.github/workflows/orchestrator.yml b/.github/workflows/orchestrator.yml index 5d6357a0c6..8b8fd2a113 100644 --- a/.github/workflows/orchestrator.yml +++ b/.github/workflows/orchestrator.yml @@ -47,8 +47,10 @@ jobs: name: 'E2E Checks' needs: 'build-and-publish' uses: './.github/workflows/e2e.yml' + environment: dev with: version: '${{ needs.build-and-publish.outputs.version }}' + cli-package-name: '${{ vars.CLI_PACKAGE_NAME }}' secrets: GEMINI_API_KEY: '${{ secrets.GEMINI_API_KEY }}' diff --git a/scripts/configure-registry.js b/scripts/configure-registry.js index 3a2034ac1c..bb02d35b89 100644 --- a/scripts/configure-registry.js +++ b/scripts/configure-registry.js @@ -4,6 +4,22 @@ * SPDX-License-Identifier: Apache-2.0 */ +/** + * @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). + * + * 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. + * + * The script also handles backing up and restoring the user's existing + * .npmrc file, preventing accidental data loss. + */ + import fs from 'node:fs'; import path from 'node:path'; import os from 'node:os';