name: Release
on:
workflow_dispatch:
inputs:
type:
description: 'Type of release (major/minor/patch)'
required: true
default: 'minor'
dry_run:
description: 'Dry run (true/false)'
required: true
default: true
jobs:
release:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Install cargo-release
run: cargo install cargo-release
- name: Build and Test Release
run: |
cargo build --release --verbose
cargo test --release --verbose
- name: Configure Git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
- name: Publish
run: |
BRANCH=${{ github.ref }}
DRY_RUN=${{ github.event.inputs.dry_run }}
REL_TYPE=${{ github.event.inputs.type }}
echo "Logging into crates.io"
cargo login ${{ secrets.CRATESIO_API_TOKEN }}
# Check if it's a dry run
if [ "$DRY_RUN" = "false" ]; then
echo "Executing release"
# Update version in Cargo.toml, commit, tag, push
cargo release --verbose --execute --no-confirm $REL_TYPE
# Push version commit and tag to github
# git add Cargo.toml
# git commit -m "Release version $VERSION"
VERSION=`grep "^version" Cargo.toml | cut -d '"' -f2`
echo "Pushing version $VERSION"
git push --tags origin $BRANCH
else
echo "Dry run: not executing release"
cargo release --verbose $REL_TYPE
fi
env:
CARGO_TERM_COLOR: always