name: Release
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Conventional Commit Changelog
id: conventional_commits
run: |
curl -s -L -o./clog.tar.gz https://github.com/clog-tool/clog-cli/releases/download/v0.9.3/clog-v0.9.3-x86_64-unknown-linux-musl.tar.gz
tar -xf ./clog.tar.gz
chmod +x ./clog
# delete current tag locally
git tag -d "$GITHUB_REF_NAME"
if [[ "$GITHUB_REF_NAME" == *"-"* ]]; then
last_tag="$(git tag -l --sort version:refname | tail -n1)"
else
last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)"
fi
printf 'Using %s as last tag\n' "$last_tag"
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
./clog --from="$last_tag" --setversion="$GITHUB_REF_NAME" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Determine release type
id: release_type
shell: bash
run: |
[[ "$GITHUB_REF_NAME" == *"-"* ]] && is_pre='true' || is_pre='false'
printf 'is_pre=%s\n' "$is_pre" >> $GITHUB_OUTPUT
- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-git-${{ github.sha }}
restore-keys: |
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
test-${{ runner.os }}-
- name: rustfmt
shell: bash
run: |
cargo fmt -- --check
- name: Clippy
shell: bash
run: |
cargo clippy --tests --examples --benches -- -D warnings
- name: Test
shell: bash
run: |
cargo test
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
draft: ${{ steps.release_type.outputs.is_pre }}
prerelease: ${{ steps.release_type.outputs.is_pre }}
body: ${{ env.CHANGELOG }}
token: ${{ secrets.GITHUB_TOKEN }}