name: Rust - Crate build, deploy, and coverage report
on:
release:
types: [ released ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: build
run: cargo build --verbose
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run tests
run: cargo test --verbose
deploy:
name: Deploy
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Tag Version
run: echo GIT_VERSION=$(git describe --tags) >> $GITHUB_ENV
- name: Prepare Git
run: |
git config user.email "github@github.com"
git config user.name "Github Actions"
git checkout -b main
# Use throw-away branch so we don't push the changes to origin
git checkout -b deploy_branch
- name: Prepare Crate
run: |
# Update cargo version,
sed -i "s/version = \"0.0.0\"/version = \"$GIT_VERSION\"/" Cargo.toml
git add Cargo.toml
# Commit changes so cargo doesn't complain about dirty repo
git commit -m "Deploy changes."
# Package crate to ensure it works without issue
cargo package --allow-dirty
- name: Cargo Login
env:
CRATES_IO_DEPLOY_TOKEN: ${{ secrets.CRATES_IO_DEPLOY_TOKEN }}
run: cargo login "$CRATES_IO_DEPLOY_TOKEN"
- name: Publish
run: cargo publish --allow-dirty
coverage:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v5
- name: Install Rust
run: rustup update stable
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: cargo llvm-cov --all-features > llvm_coverage.report
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
with:
name: rust-coverage-report
path: ./llvm_coverage.report