name: Release
on:
push:
tags:
- 'v[0-9]+.*'
env:
CARGO_TERM_COLOR: always
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all-features
- name: Build docs
run: cargo doc --no-deps --all-features
publish:
name: Publish to crates.io
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Verify version matches tag
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
- name: Publish
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
github-release:
name: GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
- name: Generate changelog
id: changelog
run: |
# Extract changelog for this version if CHANGELOG.md exists
if [ -f CHANGELOG.md ]; then
# Try to extract section for this version
VERSION="${{ steps.version.outputs.version }}"
CHANGELOG=$(sed -n "/^## \[${VERSION}\]/,/^## \[/p" CHANGELOG.md | head -n -1 || echo "")
if [ -z "$CHANGELOG" ]; then
CHANGELOG="Release ${VERSION}"
fi
else
CHANGELOG="Release ${{ steps.version.outputs.version }}"
fi
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.version.outputs.version }}
body: |
## Installation
Add to your `Cargo.toml`:
```toml
[dependencies]
parcllabs = "${{ steps.version.outputs.version }}"
```
Or use cargo:
```bash
cargo add parcllabs
```
## What's Changed
${{ steps.changelog.outputs.changelog }}
## Links
- [crates.io](https://crates.io/crates/parcllabs)
- [Documentation](https://docs.rs/parcllabs)
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}