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:
parent
32db5ba0e1
commit
d43ea268b0
|
@ -0,0 +1,58 @@
|
|||
steps:
|
||||
# Step 1: Install root dependencies (includes workspaces)
|
||||
- name: 'us-west1-docker.pkg.dev/gemini-code-dev/gemini-code-containers/gemini-code-builder'
|
||||
id: 'Install Dependencies'
|
||||
entrypoint: 'npm'
|
||||
args: ['install']
|
||||
|
||||
# Step 4: Authenticate for Docker (so we can push images to the artifact registry)
|
||||
- name: 'us-west1-docker.pkg.dev/gemini-code-dev/gemini-code-containers/gemini-code-builder'
|
||||
id: 'Authenticate docker'
|
||||
entrypoint: 'npm'
|
||||
args: ['run', 'auth']
|
||||
|
||||
# Step 5: Build workspace packages
|
||||
- name: 'us-west1-docker.pkg.dev/gemini-code-dev/gemini-code-containers/gemini-code-builder'
|
||||
id: 'Build packages'
|
||||
entrypoint: 'npm'
|
||||
args: ['run', 'build:packages']
|
||||
|
||||
# Step 6: Build sandbox container image
|
||||
- name: 'us-west1-docker.pkg.dev/gemini-code-dev/gemini-code-containers/gemini-code-builder'
|
||||
id: 'Build sandbox Docker image'
|
||||
entrypoint: 'bash'
|
||||
args:
|
||||
- -c
|
||||
- |
|
||||
if [ "$_OFFICIAL_RELEASE" = "true" ]; then
|
||||
export GEMINI_SANDBOX_IMAGE_TAG="${TAG_NAME#v}"
|
||||
else
|
||||
export GEMINI_SANDBOX_IMAGE_TAG="$SHORT_SHA"
|
||||
fi
|
||||
npm run build:sandbox:fast
|
||||
env:
|
||||
- 'GEMINI_SANDBOX=$_CONTAINER_TOOL'
|
||||
|
||||
# Step 7: Publish sandbox container image
|
||||
- name: 'us-west1-docker.pkg.dev/gemini-code-dev/gemini-code-containers/gemini-code-builder'
|
||||
id: 'Publish sandbox Docker image'
|
||||
entrypoint: 'bash'
|
||||
args:
|
||||
- -c
|
||||
- |
|
||||
if [ "$_OFFICIAL_RELEASE" = "true" ]; then
|
||||
export GEMINI_SANDBOX_IMAGE_TAG="${TAG_NAME#v}"
|
||||
else
|
||||
export GEMINI_SANDBOX_IMAGE_TAG="$SHORT_SHA"
|
||||
fi
|
||||
npm run publish:sandbox
|
||||
env:
|
||||
- 'GEMINI_SANDBOX=$_CONTAINER_TOOL'
|
||||
|
||||
options:
|
||||
defaultLogsBucketBehavior: REGIONAL_USER_OWNED_BUCKET
|
||||
dynamicSubstitutions: true
|
||||
|
||||
substitutions:
|
||||
_OFFICIAL_RELEASE: 'false'
|
||||
_CONTAINER_TOOL: 'docker'
|
|
@ -0,0 +1,143 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'The version to release (e.g., v0.1.11). Required for manual patch releases.'
|
||||
required: true
|
||||
type: string
|
||||
ref:
|
||||
description: 'The branch or ref to release from.'
|
||||
required: true
|
||||
type: string
|
||||
default: 'main'
|
||||
dry_run:
|
||||
description: 'Whether to run the publish step in dry-run mode.'
|
||||
required: true
|
||||
type: boolean
|
||||
default: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'google-gemini/gemini-cli'
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
# For manual runs, checkout the specified ref (e.g., main). For tag pushes, checkout the tag itself.
|
||||
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || github.ref }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Get the version
|
||||
id: version
|
||||
run: |
|
||||
echo "Workflow triggered by: ${{ github.event_name }}"
|
||||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
|
||||
echo "Input ref: ${{ inputs.ref }}"
|
||||
echo "Input version: ${{ inputs.version }}"
|
||||
RELEASE_TAG=${{ inputs.version }}
|
||||
else
|
||||
echo "Triggering ref: ${{ github.ref }}"
|
||||
RELEASE_TAG=${GITHUB_REF_NAME}
|
||||
fi
|
||||
|
||||
echo "---"
|
||||
echo "Initial RELEASE_TAG: ${RELEASE_TAG}"
|
||||
|
||||
# Validate that the tag starts with 'v' and follows semver
|
||||
if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
|
||||
echo "Error: Version must be in the format vX.Y.Z or vX.Y.Z-prerelease"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
RELEASE_VERSION="${RELEASE_TAG#v}"
|
||||
if [[ $RELEASE_VERSION == *-* ]]; then
|
||||
NPM_TAG=$(echo $RELEASE_VERSION | cut -d'-' -f2 | cut -d'.' -f1)
|
||||
elif [[ $RELEASE_VERSION == *+* ]]; then
|
||||
NPM_TAG=$(echo $RELEASE_VERSION | cut -d'+' -f2 | cut -d'.' -f1)
|
||||
else
|
||||
NPM_TAG="latest"
|
||||
fi
|
||||
|
||||
echo "Finalized RELEASE_VERSION: ${RELEASE_VERSION}"
|
||||
echo "Finalized NPM_TAG: ${NPM_TAG}"
|
||||
echo "---"
|
||||
|
||||
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_OUTPUT
|
||||
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_OUTPUT
|
||||
echo "NPM_TAG=${NPM_TAG}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Create and switch to a release branch
|
||||
id: release_branch
|
||||
run: |
|
||||
BRANCH_NAME="release/${{ steps.version.outputs.RELEASE_TAG }}"
|
||||
git switch -c $BRANCH_NAME
|
||||
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update package versions
|
||||
run: |
|
||||
npm run release:version ${{ steps.version.outputs.RELEASE_VERSION }}
|
||||
|
||||
- name: Commit package versions
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add package.json package-lock.json packages/*/package.json
|
||||
git commit -m "chore(release): ${{ steps.version.outputs.RELEASE_TAG }}"
|
||||
git push --set-upstream origin ${{ steps.release_branch.outputs.BRANCH_NAME }} --follow-tags
|
||||
|
||||
- name: Create GitHub Release and Tag
|
||||
if: '!inputs.dry_run'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
RELEASE_BRANCH: ${{ steps.release_branch.outputs.BRANCH_NAME }}
|
||||
run: |
|
||||
gh release create ${{ steps.version.outputs.RELEASE_TAG }} \
|
||||
bundle/gemini.js \
|
||||
--target "$RELEASE_BRANCH" \
|
||||
--title "Release ${{ steps.version.outputs.RELEASE_TAG }}" \
|
||||
--generate-notes
|
||||
|
||||
- name: Build and Prepare Packages
|
||||
run: |
|
||||
npm run build:packages
|
||||
npm run prepare:package
|
||||
|
||||
- name: Configure npm for publishing
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
registry-url: 'https://wombat-dressing-room.appspot.com'
|
||||
scope: '@google'
|
||||
|
||||
- name: Publish @google/gemini-cli-core
|
||||
run: npm publish --workspace=@google/gemini-cli-core --tag=${{ steps.version.outputs.NPM_TAG }} ${{ inputs.dry_run && '--dry-run' || '' }}
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.WOMBAT_TOKEN_CORE }}
|
||||
|
||||
- name: Install latest core package
|
||||
run: npm install @google/gemini-cli-core@${{ steps.version.outputs.RELEASE_VERSION }} --workspace=@google/gemini-cli --save-exact
|
||||
|
||||
- name: Publish @google/gemini-cli
|
||||
run: npm publish --workspace=@google/gemini-cli --tag=${{ steps.version.outputs.NPM_TAG }} ${{ inputs.dry_run && '--dry-run' || '' }}
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.WOMBAT_TOKEN_CLI }}
|
|
@ -0,0 +1,68 @@
|
|||
name: Scheduled Nightly Release
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Runs every day at midnight UTC.
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
nightly-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
issues: write
|
||||
|
||||
steps:
|
||||
- name: Checkout main branch
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: 'main'
|
||||
fetch-depth: 0 # Fetch all history for git tags
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run Preflight Checks
|
||||
run: npm run preflight
|
||||
|
||||
- name: Run Integration Tests (without Docker)
|
||||
uses: nick-invision/retry@v2
|
||||
with:
|
||||
max_attempts: 3
|
||||
retry_wait_seconds: 30
|
||||
command: npm run test:integration:sandbox:none
|
||||
|
||||
- name: Run Integration Tests (with Docker)
|
||||
uses: nick-invision/retry@v2
|
||||
with:
|
||||
max_attempts: 3
|
||||
retry_wait_seconds: 30
|
||||
command: npm run test:integration:sandbox:docker
|
||||
|
||||
- name: Configure Git User
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Create and Push Nightly Tag
|
||||
if: success()
|
||||
run: npm run tag:release:nightly
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create Issue on Failure
|
||||
if: failure()
|
||||
run: |
|
||||
gh issue create \
|
||||
--title "Nightly Release Failed on $(date +'%Y-%m-%d')" \
|
||||
--body "The scheduled nightly release workflow failed. See the full run for details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
|
||||
--label "bug,nightly-failure"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@ -31,6 +31,7 @@ This documentation is organized into the following sections:
|
|||
- **[Web Search Tool](./tools/web-search.md):** Documentation for the `google_web_search` tool.
|
||||
- **[Memory Tool](./tools/memory.md):** Documentation for the `save_memory` tool.
|
||||
- **[Contributing & Development Guide](../CONTRIBUTING.md):** Information for contributors and developers, including setup, building, testing, and coding conventions.
|
||||
- **[NPM Workspaces and Publishing](./npm.md):** Details on how the project's packages are managed and published.
|
||||
- **[Troubleshooting Guide](./troubleshooting.md):** Find solutions to common problems and FAQs.
|
||||
- **[Terms of Service and Privacy Notice](./tos-privacy.md):** Information on the terms of service and privacy notices applicable to your use of Gemini CLI.
|
||||
|
||||
|
|
|
@ -0,0 +1,305 @@
|
|||
# Package Overview
|
||||
|
||||
This monorepo contains two main packages: `@google/gemini-cli` and `@google/gemini-cli-core`.
|
||||
|
||||
## `@google/gemini-cli`
|
||||
|
||||
This is the main package for the Gemini CLI. It is responsible for the user interface, command parsing, and all other user-facing functionality.
|
||||
|
||||
When this package is published, it is bundled into a single executable file. This bundle includes all of the package's dependencies, including `@google/gemini-cli-core`. This means that whether a user installs the package with `npm install -g @google/gemini-cli` or runs it directly with `npx @google/gemini-cli`, they are using this single, self-contained executable.
|
||||
|
||||
## `@google/gemini-cli-core`
|
||||
|
||||
This package contains the core logic for interacting with the Gemini API. It is responsible for making API requests, handling authentication, and managing the local cache.
|
||||
|
||||
This package is not bundled. When it is published, it is published as a standard Node.js package with its own dependencies. This allows it to be used as a standalone package in other projects, if needed. All transpiled js code in the `dist` folder is included in the package.
|
||||
|
||||
# Release Process
|
||||
|
||||
This project follows a structured release process to ensure that all packages are versioned and published correctly. The process is designed to be as automated as possible.
|
||||
|
||||
## Current Theory
|
||||
|
||||
For most all changes, simply patching the minor version is acceptable. We can and should release frequently; the more often we release the easier it is to tell what change broke something. Developeres are encouraged to push a release as described below after their branch merges. I also think I'm open to doing the release publishing steps as a part of an existing PR, though this could have more churn if others are also releasing and version numbers change frequently.
|
||||
|
||||
## How To Release
|
||||
|
||||
Releasing a new version is as simple as creating and pushing a new Git tag. The tag must follow semantic versioning and be prefixed with `v`, for example `v0.2.0` or `v1.0.0-alpha.1`. From the branch you want to release from, run the following commands:
|
||||
|
||||
```bash
|
||||
# Create the new tag (e.g., v0.2.0)
|
||||
# Optional use git log to find an older commit sha to tag
|
||||
git tag v0.2.0 <optional sha>
|
||||
# Push the tag to the remote repository to trigger the release
|
||||
git push origin v0.2.0
|
||||
```
|
||||
|
||||
## Nightly Releases
|
||||
|
||||
In addition to manual releases, this project has an automated nightly release process to provide the latest "bleeding edge" version for testing and development.
|
||||
|
||||
### Process
|
||||
|
||||
Every night at midnight UTC, the [Scheduled Nightly Release workflow](https://github.com/google-gemini/gemini-cli/actions/workflows/scheduled-nightly-release.yml) runs automatically. It performs the following steps:
|
||||
|
||||
1. Checks out the latest code from the `main` branch.
|
||||
2. Installs all dependencies.
|
||||
3. Runs the full suite of `preflight` checks (linting, type-checking, etc.).
|
||||
4. Runs the integration tests, both with and without Docker. The tests are automatically retried up to three times to handle any flakiness.
|
||||
5. If all checks and tests succeed, it runs the `npm run tag:release:nightly` script. This script creates and pushes a new annotated Git tag with the format `v<version>+nightly.<ddmmyy>.<sha>`.
|
||||
6. Pushing this tag triggers the main [release workflow](https://github.com/google-gemini/gemini-cli/actions/workflows/release.yml), which publishes the package to npm with the `nightly` tag.
|
||||
|
||||
### Failure Handling
|
||||
|
||||
If any step in the nightly workflow fails, it will automatically create a new issue in the repository with the labels `bug` and `nightly-failure`. The issue will contain a link to the failed workflow run for easy debugging.
|
||||
|
||||
### How to Use the Nightly Build
|
||||
|
||||
To install the latest nightly build, use the `@nightly` tag:
|
||||
|
||||
```bash
|
||||
npm install -g @google/gemini-cli@nightly
|
||||
```
|
||||
|
||||
The high-level process is:
|
||||
|
||||
1. Ensure your local branch `main` or `release-xxx` if hotfixing a previous release is up-to-date with the remote repository.
|
||||
1. Decide on the new version number based on the changes since the last release.
|
||||
1. _Optionally_ `git log` to find the sha of the commit you want to push if not latest
|
||||
1. _Optionally_ run [integration tests](integration-tests.md) locally to increase confidence in the release.
|
||||
1. Create a new Git tag with the desired version number.
|
||||
1. Push the tag to the `google-gemini/gemini-cli` repository.
|
||||
1. The push will trigger the release workflow, which automates the rest of the process.
|
||||
1. Once the workflow is complete, it will have created a `release/vX.Y.Z` branch with the version bumps. Create a pull request from this branch to merge the version changes back into `main`.
|
||||
|
||||
Pushing a new tag will trigger the [release workflow](https://github.com/google-gemini/gemini-cli/actions/workflows/release.yml), which will automatically:
|
||||
|
||||
- Build and publish the packages to the npm registry.
|
||||
- Create a new GitHub release with generated release notes.
|
||||
- Create a new branch `release/vX.Y.Z` containing the version bump in the `package.json` files.
|
||||
|
||||
We also run a Gooogle cloud build called [release-docker.yml](../.gcp/release-docker.yaml). Which publishes the sandbox docker to match your release. This will also be moved to GH and combined with the main relase file once service account permissions are sorted out.
|
||||
|
||||
### 2. Monitor the Release Workflow
|
||||
|
||||
You can monitor the progress of the release workflow in the [GitHub Actions tab](https://github.com/google-gemini/gemini-cli/actions/workflows/release.yml). If the workflow fails, you will need to investigate the cause of the failure, fix the issue, and then create a new tag to trigger a new release.
|
||||
|
||||
### After the Release
|
||||
|
||||
After the workflow has successfully completed, you should:
|
||||
|
||||
1. Go to the [pull requests page](https://github.com/google-gemini/gemini-cli/pulls) of the repository.
|
||||
2. Create a new pull request from the `release/vX.Y.Z` branch to `main`.
|
||||
3. Review the pull request (it should only contain version updates in `package.json` files) and merge it. This keeps the version in `main` up-to-date.
|
||||
|
||||
## Release Validation
|
||||
|
||||
After pushing a new release smoke testing should be performed to ensure that the packages are working as expected. This can be done by installing the packages locally and running a set of tests to ensure that they are functioning correctly.
|
||||
|
||||
- `npx -y @google/gemini-cli@latest --version` to validate the push worked as expected if you were not doing a rc or dev tag
|
||||
- `npx -y @google/gemini-cli@<release tag> --version` to validate the tag pushed appropriately
|
||||
- _This is destructive locally_ `npm uninstall @google/gemini-cli && npm uninstall -g @google/gemini-cli && npm cache clean --force && npm install @google/gemini-cli@<version>`
|
||||
- Smoke testing a basic run through of exercising a few llm commands and tools is recommended to ensure that the packages are working as expected. We'll codify this more in the future.
|
||||
|
||||
## When to merge the version change, or not?
|
||||
|
||||
The above pattern for creating patch or hotfix releases from current or older commits leaves the repository in the following state:
|
||||
|
||||
1. The Tag (`vX.Y.Z-patch.1`): This tag correctly points to the original commit on main
|
||||
that contains the stable code you intended to release. This is crucial. Anyone checking
|
||||
out this tag gets the exact code that was published.
|
||||
2. The Branch (`release-vX.Y.Z-patch.1`): This branch contains one new commit on top of the
|
||||
tagged commit. That new commit only contains the version number change in package.json
|
||||
(and other related files like package-lock.json).
|
||||
|
||||
This separation is good. It keeps your main branch history clean of release-specific
|
||||
version bumps until you decide to merge them.
|
||||
|
||||
This is the critical decision, and it depends entirely on the nature of the release.
|
||||
|
||||
### Merge Back for Stable Patches and Hotfixes
|
||||
|
||||
You almost always want to merge the `release-<tag>` branch back into `main` for any
|
||||
stable patch or hotfix release.
|
||||
|
||||
- Why? The primary reason is to update the version in main's package.json. If you release
|
||||
v1.2.1 from an older commit but never merge the version bump back, your main branch's
|
||||
package.json will still say "version": "1.2.0". The next developer who starts work for
|
||||
the next feature release (v1.3.0) will be branching from a codebase that has an
|
||||
incorrect, older version number. This leads to confusion and requires manual version
|
||||
bumping later.
|
||||
- The Process: After the release-v1.2.1 branch is created and the package is successfully
|
||||
published, you should open a pull request to merge release-v1.2.1 into main. This PR
|
||||
will contain just one commit: "chore: bump version to v1.2.1". It's a clean, simple
|
||||
integration that keeps your main branch in sync with the latest released version.
|
||||
|
||||
### Do NOT Merge Back for Pre-Releases (RC, Beta, Dev)
|
||||
|
||||
You typically do not merge release branches for pre-releases back into `main`.
|
||||
|
||||
- Why? Pre-release versions (e.g., v1.3.0-rc.1, v1.3.0-rc.2) are, by definition, not
|
||||
stable and are temporary. You don't want to pollute your main branch's history with a
|
||||
series of version bumps for release candidates. The package.json in main should reflect
|
||||
the latest stable release version, not an RC.
|
||||
- The Process: The release-v1.3.0-rc.1 branch is created, the npm publish --tag rc happens,
|
||||
and then... the branch has served its purpose. You can simply delete it. The code for
|
||||
the RC is already on main (or a feature branch), so no functional code is lost. The
|
||||
release branch was just a temporary vehicle for the version number.
|
||||
|
||||
## Local Testing and Validation: Changes to the Packaging and Publishing Process
|
||||
|
||||
If you need to test the release process without actually publishing to NPM or creating a public GitHub release, you can trigger the workflow manually from the GitHub UI.
|
||||
|
||||
1. Go to the [Actions tab](https://github.com/google-gemini/gemini-cli/actions/workflows/release.yml) of the repository.
|
||||
2. Click on the "Run workflow" dropdown.
|
||||
3. Leave the `dry_run` option checked (`true`).
|
||||
4. Click the "Run workflow" button.
|
||||
|
||||
This will run the entire release process but will skip the `npm publish` and `gh release create` steps. You can inspect the workflow logs to ensure everything is working as expected.
|
||||
|
||||
It is crucial to test any changes to the packaging and publishing process locally before committing them. This ensures that the packages will be published correctly and that they will work as expected when installed by a user.
|
||||
|
||||
To validate your changes, you can perform a dry run of the publishing process. This will simulate the publishing process without actually publishing the packages to the npm registry.
|
||||
|
||||
```bash
|
||||
npm_package_version=9.9.9 SANDBOX_IMAGE_REGISTRY="registry" SANDBOX_IMAGE_NAME="thename" npm run publish:npm --dry-run
|
||||
```
|
||||
|
||||
This command will do the following:
|
||||
|
||||
1. Build all the packages.
|
||||
2. Run all the prepublish scripts.
|
||||
3. Create the package tarballs that would be published to npm.
|
||||
4. Print a summary of the packages that would be published.
|
||||
|
||||
You can then inspect the generated tarballs to ensure that they contain the correct files and that the `package.json` files have been updated correctly. The tarballs will be created in the root of each package's directory (e.g., `packages/cli/google-gemini-cli-0.1.6.tgz`).
|
||||
|
||||
By performing a dry run, you can be confident that your changes to the packaging process are correct and that the packages will be published successfully.
|
||||
|
||||
## Release Deep Dive
|
||||
|
||||
The main goal of the release process is to take the source code from the packages/ directory, build it, and assemble a
|
||||
clean, self-contained package in a temporary `bundle` directory at the root of the project. This `bundle` directory is what
|
||||
actually gets published to NPM.
|
||||
|
||||
Here are the key stages:
|
||||
|
||||
Stage 1: Pre-Release Sanity Checks and Versioning
|
||||
|
||||
- What happens: Before any files are moved, the process ensures the project is in a good state. This involves running tests,
|
||||
linting, and type-checking (npm run preflight). The version number in the root package.json and packages/cli/package.json
|
||||
is updated to the new release version.
|
||||
- Why: This guarantees that only high-quality, working code is released. Versioning is the first step to signify a new
|
||||
release.
|
||||
|
||||
Stage 2: Building the Source Code
|
||||
|
||||
- What happens: The TypeScript source code in packages/core/src and packages/cli/src is compiled into JavaScript.
|
||||
- File movement:
|
||||
- packages/core/src/\*_/_.ts -> compiled to -> packages/core/dist/
|
||||
- packages/cli/src/\*_/_.ts -> compiled to -> packages/cli/dist/
|
||||
- Why: The TypeScript code written during development needs to be converted into plain JavaScript that can be run by
|
||||
Node.js. The core package is built first as the cli package depends on it.
|
||||
|
||||
Stage 3: Assembling the Final Publishable Package
|
||||
|
||||
This is the most critical stage where files are moved and transformed into their final state for publishing. A temporary
|
||||
`bundle` folder is created at the project root to house the final package contents.
|
||||
|
||||
1. The `package.json` is Transformed:
|
||||
- What happens: The package.json from packages/cli/ is read, modified, and written into the root `bundle`/ directory. The
|
||||
script scripts/prepare-cli-packagejson.js is responsible for this.
|
||||
- File movement: packages/cli/package.json -> (in-memory transformation) -> `bundle`/package.json
|
||||
- Why: The final package.json must be different from the one used in development. Key changes include:
|
||||
- Removing devDependencies.
|
||||
- Removing workspace-specific "dependencies": { "@gemini-cli/core": "workspace:\*" } and ensuring the core code is
|
||||
bundled directly into the final JavaScript file.
|
||||
- Ensuring the bin, main, and files fields point to the correct locations within the final package structure.
|
||||
|
||||
2. The JavaScript Bundle is Created:
|
||||
- What happens: The built JavaScript from both packages/core/dist and packages/cli/dist are bundled into a single,
|
||||
executable JavaScript file.
|
||||
- File movement: packages/cli/dist/index.js + packages/core/dist/index.js -> (bundled by esbuild) -> `bundle`/gemini.js (or a
|
||||
similar name).
|
||||
- Why: This creates a single, optimized file that contains all the necessary application code. It simplifies the package
|
||||
by removing the need for the core package to be a separate dependency on NPM, as its code is now included directly.
|
||||
|
||||
3. Static and Supporting Files are Copied:
|
||||
- What happens: Essential files that are not part of the source code but are required for the package to work correctly
|
||||
or be well-described are copied into the `bundle` directory.
|
||||
- File movement:
|
||||
- README.md -> `bundle`/README.md
|
||||
- LICENSE -> `bundle`/LICENSE
|
||||
- packages/cli/src/utils/\*.sb (sandbox profiles) -> `bundle`/
|
||||
- Why:
|
||||
- The README.md and LICENSE are standard files that should be included in any NPM package.
|
||||
- The sandbox profiles (.sb files) are critical runtime assets required for the CLI's sandboxing feature to
|
||||
function. They must be located next to the final executable.
|
||||
|
||||
Stage 4: Publishing to NPM
|
||||
|
||||
- What happens: The npm publish command is run from inside the root `bundle` directory.
|
||||
- Why: By running npm publish from within the `bundle` directory, only the files we carefully assembled in Stage 3 are uploaded
|
||||
to the NPM registry. This prevents any source code, test files, or development configurations from being accidentally
|
||||
published, resulting in a clean and minimal package for users.
|
||||
|
||||
Summary of File Flow
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
subgraph "Source Files"
|
||||
A["packages/core/src/*.ts<br/>packages/cli/src/*.ts"]
|
||||
B["packages/cli/package.json"]
|
||||
C["README.md<br/>LICENSE<br/>packages/cli/src/utils/*.sb"]
|
||||
end
|
||||
|
||||
subgraph "Process"
|
||||
D(Build)
|
||||
E(Transform)
|
||||
F(Assemble)
|
||||
G(Publish)
|
||||
end
|
||||
|
||||
subgraph "Artifacts"
|
||||
H["Bundled JS"]
|
||||
I["Final package.json"]
|
||||
J["bundle/"]
|
||||
end
|
||||
|
||||
subgraph "Destination"
|
||||
K["NPM Registry"]
|
||||
end
|
||||
|
||||
A --> D --> H
|
||||
B --> E --> I
|
||||
C --> F
|
||||
H --> F
|
||||
I --> F
|
||||
F --> J
|
||||
J --> G --> K
|
||||
```
|
||||
|
||||
This process ensures that the final published artifact is a purpose-built, clean, and efficient representation of the
|
||||
project, rather than a direct copy of the development workspace.
|
||||
|
||||
## NPM Workspaces
|
||||
|
||||
This project uses [NPM Workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) to manage the packages within this monorepo. This simplifies development by allowing us to manage dependencies and run scripts across multiple packages from the root of the project.
|
||||
|
||||
### How it Works
|
||||
|
||||
The root `package.json` file defines the workspaces for this project:
|
||||
|
||||
```json
|
||||
{
|
||||
"workspaces": ["packages/*"]
|
||||
}
|
||||
```
|
||||
|
||||
This tells NPM that any folder inside the `packages` directory is a separate package that should be managed as part of the workspace.
|
||||
|
||||
### Benefits of Workspaces
|
||||
|
||||
- **Simplified Dependency Management**: Running `npm install` from the root of the project will install all dependencies for all packages in the workspace and link them together. This means you don't need to run `npm install` in each package's directory.
|
||||
- **Automatic Linking**: Packages within the workspace can depend on each other. When you run `npm install`, NPM will automatically create symlinks between the packages. This means that when you make changes to one package, the changes are immediately available to other packages that depend on it.
|
||||
- **Simplified Script Execution**: You can run scripts in any package from the root of the project using the `--workspace` flag. For example, to run the `build` script in the `cli` package, you can run `npm run build --workspace @google/gemini-cli`.
|
|
@ -11202,7 +11202,7 @@
|
|||
"name": "@google/gemini-cli",
|
||||
"version": "0.1.9",
|
||||
"dependencies": {
|
||||
"@google/gemini-cli-core": "*",
|
||||
"@google/gemini-cli-core": "file:../core",
|
||||
"@types/update-notifier": "^6.0.8",
|
||||
"command-exists": "^1.2.9",
|
||||
"diff": "^7.0.0",
|
||||
|
|
25
package.json
25
package.json
|
@ -8,9 +8,13 @@
|
|||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"repository": "google-gemini/gemini-cli",
|
||||
"private": "true",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/google-gemini/gemini-cli.git"
|
||||
},
|
||||
"config": {
|
||||
"sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.8"
|
||||
"sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.9"
|
||||
},
|
||||
"scripts": {
|
||||
"generate": "node scripts/generate-git-commit-info.js",
|
||||
|
@ -39,18 +43,17 @@
|
|||
"auth": "npm run auth:npm && npm run auth:docker",
|
||||
"prerelease:dev": "npm run prerelease:version --workspaces && npm run prerelease:deps --workspaces",
|
||||
"bundle": "npm run generate && node esbuild.config.js && node scripts/copy_bundle_assets.js",
|
||||
"build:cli": "npm run build --workspace packages/cli",
|
||||
"build:core": "npm run build --workspace packages/core",
|
||||
"build:packages": "npm run build:core && npm run build:cli",
|
||||
"build:packages": "npm run build --workspaces",
|
||||
"build:sandbox:fast": "node scripts/build_sandbox.js --skip-npm-install-build",
|
||||
"prepare:cli-packagejson": "node scripts/prepare-cli-packagejson.js",
|
||||
"prepare:packages": "node scripts/prepare-cli-packagejson.js && node scripts/prepare-core-package.js",
|
||||
"prepare:package": "node scripts/prepare-package.js",
|
||||
"publish:sandbox": "node scripts/publish-sandbox.js",
|
||||
"publish:npm": "npm publish --workspaces ${NPM_PUBLISH_TAG:+--tag=$NPM_PUBLISH_TAG} ${NPM_DRY_RUN:+--dry-run}",
|
||||
"publish:release": "npm run build:packages && npm run prepare:cli-packagejson && npm run build:sandbox:fast && npm run publish:sandbox && npm run publish:npm",
|
||||
"telemetry": "node scripts/telemetry.js",
|
||||
"start:gcp": "concurrently --raw --kill-others \"npm run telemetry -- --target=gcp\" \"npm start\"",
|
||||
"prepublishOnly": "node scripts/prepublish.js"
|
||||
"publish:release": "npm run prepare:package && npm run build:packages && npm run build:sandbox:fast && npm run publish:sandbox && npm run publish:npm",
|
||||
"prepublishOnly": "node scripts/check-versions.js && node scripts/prepublish.js",
|
||||
"release:version": "node scripts/version.js",
|
||||
"tag:release:nightly": "TAG_NAME=\"v$(node -p \"require('./package.json').version\")+nightly.$(date -u +%d%m%y).$(git rev-parse --short HEAD)\"; git tag -a $TAG_NAME -m '' && git push origin $TAG_NAME",
|
||||
"check:versions": "node scripts/check-versions.js",
|
||||
"publish:actions-release": "npm run prepare:package && npm run build:packages && npm run publish:npm"
|
||||
},
|
||||
"bin": {
|
||||
"gemini": "bundle/gemini.js"
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
"name": "@google/gemini-cli",
|
||||
"version": "0.1.9",
|
||||
"description": "Gemini CLI",
|
||||
"repository": "google-gemini/gemini-cli",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/google-gemini/gemini-cli.git"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
@ -16,20 +19,16 @@
|
|||
"format": "prettier --write .",
|
||||
"test": "vitest run",
|
||||
"test:ci": "vitest run --coverage",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"prerelease:version": "node ../../scripts/bind_package_version.js",
|
||||
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
|
||||
"prepack": "npm run build",
|
||||
"prepublishOnly": "node ../../scripts/prepublish.js"
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"config": {
|
||||
"sandboxImageUri": "gemini-cli-sandbox"
|
||||
"sandboxImageUri": "us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"@google/gemini-cli-core": "*",
|
||||
"@google/gemini-cli-core": "file:../core",
|
||||
"@types/update-notifier": "^6.0.8",
|
||||
"command-exists": "^1.2.9",
|
||||
"diff": "^7.0.0",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@google/gemini-cli-core",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@google/gemini-cli-core",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.9",
|
||||
"dependencies": {
|
||||
"@google/genai": "^1.4.0",
|
||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||
|
|
|
@ -1,22 +1,20 @@
|
|||
{
|
||||
"name": "@google/gemini-cli-core",
|
||||
"version": "0.1.9",
|
||||
"description": "Gemini CLI Server",
|
||||
"repository": "google-gemini/gemini-cli",
|
||||
"description": "Gemini CLI Core",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/google-gemini/gemini-cli.git"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"start": "node dist/src/index.js",
|
||||
"build": "node ../../scripts/build_package.js",
|
||||
"lint": "eslint . --ext .ts,.tsx",
|
||||
"format": "prettier --write .",
|
||||
"test": "vitest run",
|
||||
"test:ci": "vitest run --coverage",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"prerelease:version": "node ../../scripts/bind_package_version.js",
|
||||
"prerelease:deps": "node ../../scripts/bind_package_dependencies.js",
|
||||
"prepack": "npm run build",
|
||||
"prepublishOnly": "node ../../scripts/prepublish.js"
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
|
|
|
@ -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.');
|
|
@ -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) {
|
||||
|
|
|
@ -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!');
|
|
@ -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);
|
||||
}
|
|
@ -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.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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}.`);
|
Loading…
Reference in New Issue