-
Notifications
You must be signed in to change notification settings - Fork 409
crate publishing workflow #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
96952ee
Initial plan
Copilot 6affcd3
Add automated crate publishing workflow and documentation
Copilot f717d30
Fix crate publish order to respect all dependencies
Copilot 52849b1
Add release information to README with crates.io badge
Copilot 4710c0d
Fix grep pattern for crate search and improve rollback documentation
Copilot 556f9af
Add dry-run testing capability to publish workflow
Copilot 0759b3c
reduce changes
harsha-simhadri 24b706a
use workspace publishing
harsha-simhadri 11eee5b
Apply suggestion from @Copilot
harsha-simhadri b300f77
modify the workflow to dry run on PR and publish on tag after PR merge
harsha-simhadri db5b6ed
prevent publish from non main branch
harsha-simhadri b5fb444
Apply suggestion from @Copilot
harsha-simhadri d6d61f9
dry run flag
harsha-simhadri 2da92af
Apply suggestion from @Copilot
harsha-simhadri 7b31be4
error fix and more validations
harsha-simhadri d7b3e87
specify what to verify after publishing
harsha-simhadri 37f755c
add dep version matching instuction, and change rust-toolchain config
harsha-simhadri 21363c6
removed another round of tests
harsha-simhadri 9b8611d
simplify conditional in CI
harsha-simhadri 2558af3
prevent tags on non-main branch
harsha-simhadri 36238aa
updated illustrative version number in readme to X.Y.Z
harsha-simhadri 226de95
update checklist to delete merged branch
harsha-simhadri 9712c86
set concurrency cancel-in-progress to false
harsha-simhadri ee80b27
added suggestions to recover from partial publish
harsha-simhadri 0be6156
Merge branch 'main' into copilot/automate-crate-publishing
harsha-simhadri 189e92b
Merge branch 'main' into copilot/automate-crate-publishing
harsha-simhadri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Release Process | ||
|
|
||
| Publishing DiskANN crates to [crates.io](https://crates.io). | ||
|
|
||
| ## Overview | ||
|
|
||
| All workspace crates are published together with synchronized version numbers using `cargo publish --workspace`, which automatically resolves dependency order and waits for each crate to be indexed before publishing its dependents. The Rust toolchain version is read from [`rust-toolchain.toml`](../../rust-toolchain.toml). | ||
|
|
||
| Releases follow a pull-request workflow: bump the version on a branch, open a PR, let the dry-run check pass, merge, then tag the release via the GitHub UI. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. **CRATES_IO_TOKEN Secret**: A crates.io API token configured as a GitHub repository secret named `CRATES_IO_TOKEN` with publish permissions for all DiskANN crates. | ||
| - Create a token: [crates.io/settings/tokens](https://crates.io/settings/tokens) | ||
| - Add the secret: Repository Settings → Secrets and variables → Actions → New repository secret | ||
|
|
||
| 2. **Maintainer Access**: Write access to the repository and owner/maintainer of all crates on crates.io. | ||
|
|
||
| ## Dry-Run Testing | ||
|
|
||
| A `cargo publish --workspace --dry-run` runs **automatically** as a pull-request check whenever `Cargo.toml` is changed. You can also trigger a dry-run manually: | ||
|
|
||
| ### Manual: GitHub Actions | ||
|
|
||
| 1. Navigate to: `https://github.com/microsoft/DiskANN/actions/workflows/publish.yml` | ||
| 2. Click **Run workflow**, select your branch, keep **dry-run = true** | ||
| 3. Watch the workflow — look for successful `cargo publish --workspace --dry-run` | ||
|
|
||
| ### Manual: Local | ||
|
|
||
| ```bash | ||
| cargo publish --locked --workspace --dry-run | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ### What Dry-Run Tests | ||
|
|
||
| - Crate metadata and packaging validation | ||
| - Dependency resolution and publish ordering | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| - Build verification | ||
|
|
||
| ### What It Does NOT Test | ||
|
|
||
| - Actual publishing, registry token auth, upload reliability | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
|
|
||
| ## Release Steps | ||
|
|
||
| 1. **Create a release branch** from `main`: | ||
|
|
||
| ```bash | ||
| git checkout main && git pull | ||
| git checkout -b release-0.46.0 | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| 2. **Update version** in root `Cargo.toml`: | ||
|
|
||
| ```toml | ||
| [workspace.package] | ||
| version = "0.46.0" | ||
| ``` | ||
|
|
||
| All workspace crates inherit this via `version.workspace = true`. | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
|
|
||
| 3. **Update CHANGELOG** (if applicable). | ||
|
|
||
| 4. **Push and open a pull request** to `main`: | ||
|
|
||
| ```bash | ||
| git commit -am "Bump version to 0.46.0" | ||
| git push origin release-0.46.0 | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
| Open a PR on GitHub. The **Publish to crates.io / Dry-run publish test** check runs automatically. | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
|
|
||
| 5. **Wait for checks** — the dry-run and CI must both pass before merge. | ||
|
|
||
| 6. **Merge the PR** into `main`. | ||
|
|
||
| 7. **Create a release** via the GitHub UI: | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| - Go to **Releases → Draft a new release** | ||
| - Create a new tag `v0.46.0` targeting `main` | ||
| - Add release notes describing changes | ||
| - Click **Publish release** | ||
|
|
||
| Pushing the tag triggers the real publish workflow. | ||
|
|
||
| 8. **Verify** the published crates: | ||
|
|
||
| ```bash | ||
| cargo search diskann --limit 20 | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ## Pre-release Checklist | ||
|
|
||
| - [ ] All CI checks pass on the PR | ||
| - [ ] Version number is updated in `Cargo.toml` | ||
| - [ ] CHANGELOG is updated (if applicable) | ||
| - [ ] Documentation is up to date | ||
| - [ ] Breaking changes are clearly documented | ||
| - [ ] **Dry-run publish check passes on the PR** | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT license. | ||
|
|
||
| # Publishes all workspace crates to crates.io. | ||
| # | ||
| # Triggers: | ||
| # - push tag v{major}.{minor}.{patch} → real publish | ||
| # - pull_request touching Cargo.toml → automatic dry-run (pre-merge check) | ||
| # - workflow_dispatch → manual dry-run or real publish | ||
| # | ||
| # Requires CRATES_IO_TOKEN secret. Rust toolchain version is read from rust-toolchain.toml. | ||
|
|
||
| name: Publish to crates.io | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v[0-9]+.[0-9]+.[0-9]+' | ||
| pull_request: | ||
| branches: ["main"] | ||
| paths: | ||
| - 'Cargo.toml' | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: 'Run in dry-run mode (test without actually publishing)' | ||
| required: false | ||
| default: 'true' | ||
| type: choice | ||
| options: | ||
| - 'true' | ||
| - 'false' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
|
|
||
| env: | ||
| RUST_BACKTRACE: 1 | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: >- | ||
| ${{ | ||
| github.event_name == 'pull_request' | ||
| && 'Dry-run publish test' | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| || github.event.inputs.dry_run == 'true' | ||
| && 'Dry-run publish test' | ||
| || 'Publish crates to crates.io' | ||
| }} | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| lfs: true | ||
|
|
||
| - name: Read Rust version from rust-toolchain.toml | ||
| id: rust-version | ||
| run: | | ||
| RUST_VERSION=$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml) | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| echo "channel=$RUST_VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Install Rust ${{ steps.rust-version.outputs.channel }} | ||
| uses: dtolnay/rust-toolchain@stable | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
| with: | ||
| toolchain: ${{ steps.rust-version.outputs.channel }} | ||
|
|
||
| - uses: Swatinem/rust-cache@v2 | ||
|
|
||
| - name: Prevent publish from non-main branch | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| if: >- | ||
| github.event_name == 'workflow_dispatch' | ||
| && github.event.inputs.dry_run != 'true' | ||
| && github.ref != 'refs/heads/main' | ||
| run: | | ||
| echo "::error::Live publishing is only allowed from main. Use dry-run for other branches." | ||
| exit 1 | ||
|
|
||
| - name: Verify version matches tag | ||
| if: github.event_name == 'push' | ||
| run: | | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| TAG_VERSION="${GITHUB_REF#refs/tags/v}" | ||
| CARGO_VERSION=$(grep -A 5 '^\[workspace\.package\]' Cargo.toml | grep 'version = ' | head -n1 | sed 's/.*"\(.*\)".*/\1/') | ||
| if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then | ||
| echo "::error::Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)" | ||
| exit 1 | ||
| fi | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
|
|
||
| - name: Run tests | ||
|
harsha-simhadri marked this conversation as resolved.
Outdated
harsha-simhadri marked this conversation as resolved.
Outdated
|
||
| run: cargo test --locked --workspace --profile ci | ||
|
|
||
| - name: Publish workspace crates | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }} | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "pull_request" ] || [ "$DRY_RUN" = "true" ]; then | ||
| DRY_RUN_FLAG="--dry-run" | ||
| echo "🧪 DRY-RUN MODE" | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
| else | ||
| echo "📦 LIVE MODE - Publishing to crates.io" | ||
| fi | ||
| cargo publish --locked --workspace $DRY_RUN_FLAG | ||
|
harsha-simhadri marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.