name: Publish
on:
push:
tags:
- 'v*.*.*'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
check-branch:
name: Verify tag is on main
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check tag is on main
shell: bash
run: |
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref }})
if ! git merge-base --is-ancestor $TAG_COMMIT origin/main; then
echo "❌ Tag must be on main branch!"
echo "Create tag from main: git checkout main && git tag vX.Y.Z"
exit 1
fi
echo "✅ Tag is on main branch"
validate:
name: Validate Release
runs-on: ubuntu-latest
needs: check-branch
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Sync version from tag
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "🚀 Setting version to $VERSION"
sed -i "s/^version[[:space:]]*=[[:space:]]*\".*\"/version = \"$VERSION\"/" Cargo.toml
sed -i "s/^version[[:space:]]*=[[:space:]]*\".*\"/version = \"$VERSION\"/" fastserial-derive/Cargo.toml
sed -i "s/fastserial-derive[[:space:]]*=[[:space:]]*{[[:space:]]*version[[:space:]]*=[[:space:]]*\"[^\"]*\"/fastserial-derive = { version = \"$VERSION\"/" Cargo.toml
echo "✅ Version set to $VERSION"
- name: Check docs build
run: cargo doc --no-deps --all-features --document-private-items
env:
RUSTDOCFLAGS: "-D warnings"
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Sync version from tag
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/v}
sed -i "s/^version[[:space:]]*=[[:space:]]*\".*\"/version = \"$VERSION\"/" Cargo.toml
sed -i "s/^version[[:space:]]*=[[:space:]]*\".*\"/version = \"$VERSION\"/" fastserial-derive/Cargo.toml
sed -i "s/fastserial-derive[[:space:]]*=[[:space:]]*{[[:space:]]*version[[:space:]]*=[[:space:]]*\"[^\"]*\"/fastserial-derive = { version = \"$VERSION\"/" Cargo.toml
- name: Publish fastserial-derive
run: cargo publish -p fastserial-derive --no-verify --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Wait for crates.io index
run: sleep 30
- name: Publish fastserial
run: cargo publish -p fastserial --no-verify --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: publish
steps:
- uses: actions/checkout@v4
- name: Extract CHANGELOG entry
id: changelog
run: |
VERSION=${GITHUB_REF#refs/tags/v}
NOTES=$(awk "/^## \[$VERSION\]/{found=1; next} /^## \[/{found=0} found{print}" CHANGELOG.md)
if [ -z "$NOTES" ]; then
NOTES="Release v$VERSION"
fi
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.notes }}
draft: false
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
generate_release_notes: true