Documentation
# Release Setup Guide

This guide explains how to set up automated publishing to crates.io when you create a GitHub release.

## Prerequisites

### 1. Set up your crates.io API token

1. Go to [crates.io]https://crates.io/ and log in
2. Go to Account Settings → API Tokens
3. Create a new token with "Publish new crates" and "Publish updates to existing crates" permissions
4. Copy the token (you won't be able to see it again)

### 2. Add the token to GitHub Secrets

1. Go to your GitHub repository
2. Navigate to Settings → Secrets and variables → Actions
3. Click "New repository secret"
4. Name: `CARGO_REGISTRY_TOKEN`
5. Value: Paste your crates.io API token
6. Click "Add secret"

## How to Create a Release

### 1. Update version in Cargo.toml

Before creating a release, make sure to update the version in your `Cargo.toml`:

```toml
[package]
name = "linch"
version = "0.2.0"  # Update this version
```

### 2. Commit and push changes

```bash
git add Cargo.toml
git commit -m "Bump version to 0.2.0"
git push origin main
```

### 3. Create a Git tag

```bash
git tag v0.2.0
git push origin v0.2.0
```

### 4. Create GitHub Release

1. Go to your GitHub repository
2. Click "Releases" → "Create a new release"
3. Choose the tag you just created (v0.2.0)
4. Fill in the release title and description
5. Click "Publish release"

## What Happens Automatically

When you publish a release, the GitHub Action will:

1. ✅ Checkout the code
2. ✅ Set up Rust toolchain
3. ✅ Cache dependencies for faster builds
4. ✅ Run all tests
5. ✅ Check code formatting (`cargo fmt`)
6. ✅ Run clippy lints
7. ✅ Verify the version in Cargo.toml matches the release tag
8. ✅ Publish to crates.io

## Version Matching

The workflow automatically verifies that your `Cargo.toml` version matches your git tag:
- Git tag: `v0.2.0` 
- Cargo.toml version: `0.2.0`
If they don't match, the workflow will fail with a clear error message.

## Troubleshooting

### Common Issues

1. **Version mismatch**: Make sure your Cargo.toml version matches your git tag (without the 'v' prefix)
2. **Tests failing**: The workflow runs tests before publishing. Fix any failing tests first.
3. **Formatting issues**: Run `cargo fmt` locally before creating the release
4. **Clippy warnings**: Run `cargo clippy` and fix any warnings
5. **Token issues**: Make sure your `CARGO_REGISTRY_TOKEN` secret is set correctly

### Manual Publishing

If you need to publish manually for any reason:

```bash
cargo publish --token YOUR_CRATES_IO_TOKEN
```

## Security Notes

- The crates.io token is stored securely in GitHub Secrets
- The token is only accessible during the workflow execution
- The workflow only runs on published releases, not on every commit
- All tests and checks must pass before publishing

## Workflow File Location

The workflow is defined in `.github/workflows/release.yml` and will automatically trigger when you create a new release on GitHub.