update typo (#4) #1
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: Publish to crates.io | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- 'v*' | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Check if publication is necessary | |
id: check | |
run: | | |
if [[ "${{ github.ref }}" == refs/tags/* ]] || [[ "${{ github.ref }}" == refs/heads/master ]]; then | |
echo "Publishing is necessary" | |
echo "publish=true" >> $GITHUB_OUTPUT | |
else | |
echo "Publishing is not necessary" | |
echo "publish=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish to crates.io | |
if: steps.check.outputs.publish == 'true' | |
env: | |
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} | |
run: | | |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then | |
# If it's a tag, publish as is | |
cargo publish | |
else | |
# If it's a push to master, publish as a pre-release version | |
VERSION=$(grep version Cargo.toml | sed -E 's/version = "(.*)"/\1/' | tr -d ' ') | |
COMMIT_HASH=$(git rev-parse --short HEAD) | |
NEW_VERSION="${VERSION}-pre.${COMMIT_HASH}" | |
sed -i "s/^version = .*/version = \"${NEW_VERSION}\"/" Cargo.toml | |
cargo publish --allow-dirty | |
fi |