chore: 0.7.x CI publish adjustment #135
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust | |
on: | |
push: | |
branches: [ 0.7.x ] | |
tags: | |
- '*' | |
pull_request: | |
branches: [ 0.7.x ] | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Run check | |
run: cargo check | |
rustfmt: | |
name: rustfmt | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
profile: minimal | |
components: rustfmt | |
- name: Check formatting | |
run: | | |
cargo fmt -- --check | |
rustclippy: | |
name: rustclippy | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
profile: minimal | |
components: clippy | |
- name: Clippy check | |
run: | | |
cargo clippy | |
test: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
profile: minimal | |
components: clippy | |
- name: Run tests | |
run: | | |
cargo test | |
publish: | |
runs-on: ubuntu-20.04 | |
needs: [rustfmt, rustclippy] | |
if: startsWith(github.ref, 'refs/tags/') && github.base_ref == '0.7.x' | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
with: | |
# fetch tags for cargo ws publish | |
# might be a simple `fetch-tags: true` option soon, see https://github.com/actions/checkout/pull/579 | |
fetch-depth: 0 | |
- name: Extract Tag Name | |
id: get_version | |
run: | | |
echo "::set-output name=version::${GITHUB_REF/refs\/tags\//}" | |
- name: Publish to crates.io and tag the commit | |
id: tag-and-publish | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
run: | | |
cargo ws publish --all --yes --exact \ | |
--version ${{ steps.get_version.outputs.version }} \ | |
--skip-published --no-git-commit --allow-dirty \ | |
--tag-existing --tag-prefix 'v' \ | |
--tag-msg 'crates.io snapshot' --tag-msg '%{https://crates.io/crates/%n/%v}' \ | |
--no-individual-tags --no-git-push | |
# We still want to capture the latest tag name, though it should match the one we just extracted. | |
GIT_LATEST_TAG=$(git describe --tags --abbrev=0) | |
echo "::set-output name=tagged::$( [[ "$GIT_LATEST_TAG" == "${{ steps.get_version.outputs.version }}" ]] && echo 0 || echo 1 )" | |
# Extracting the message from the latest tag | |
GIT_TAG_MESSAGE="$(git tag -l --format='%(body)' ${GIT_LATEST_TAG})" | |
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//'%'/'%25'}" | |
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\n'/'%0A'}" | |
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\r'/'%0D'}" | |
echo "::set-output name=git_tag_message::${GIT_TAG_MESSAGE}" |