name: Release to crates.io
on:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
id-token: write
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Update version in Cargo.toml
run: |
VERSION="${{ steps.get_version.outputs.version }}"
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
sed -i "s/astrea-macro = { version = \".*\", path/astrea-macro = { version = \"$VERSION\", path/" Cargo.toml
cargo update -w
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish astrea-macro
working-directory: ./astrea-macro
run: |
OUTPUT=$(cargo publish --allow-dirty 2>&1) || {
if echo "$OUTPUT" | grep -q "already exists"; then
echo "✓ astrea-macro already published, skipping..."
else
echo "$OUTPUT" >&2
exit 1
fi
}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish astrea
run: |
OUTPUT=$(cargo publish --allow-dirty 2>&1) || {
if echo "$OUTPUT" | grep -q "already exists"; then
echo "✓ astrea already published, skipping..."
else
echo "$OUTPUT" >&2
exit 1
fi
}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}