Merge pull request #108 from plx-pdg/prepare-release-v0.2.0 #26
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: Tag, Release and Publish | |
on: | |
push: | |
branches: ["main"] | |
permissions: | |
contents: write | |
jobs: | |
tag: | |
runs-on: ubuntu-latest | |
outputs: | |
tag_created: ${{ steps.create_tag.outputs.tag_created }} | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
- name: Get the current version | |
id: get_version | |
run: | | |
VERSION=v$(cat Cargo.toml | grep -m 1 version | grep -o -P "\d+\.\d+\.\d+") | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Create tag | |
if: ${{env.VERSION != env.LATEST_TAG}} | |
id: create_tag | |
run: | | |
git tag ${{env.VERSION}} | |
git push origin ${{env.VERSION}} | |
echo "tag_created=true" >> $GITHUB_OUTPUT | |
release: | |
needs: tag | |
if: needs.tag.outputs.tag_created == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get the current version | |
id: get_version | |
run: | | |
VERSION=$(cat Cargo.toml | grep version | grep -o -P "\d+\.\d+\.\d+") | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Get Changelog line | |
run: | | |
CHANGELOG_HEADER=$(cat CHANGELOG.md | grep "\[${{env.VERSION}}\]" | sed s/#//g | sed -E "s/\(.*\)//g" | sed "s/\ \[//g" | sed "s/\]//g" | sed "s/\ /-/g" | sed "s/\.//g") | |
echo "CHANGELOG_HEADER=$CHANGELOG_HEADER" >> $GITHUB_ENV | |
- name: Debug Info | |
run: | | |
echo "Version: ${{ env.VERSION }}" | |
echo "Changelog Header: ${{ env.CHANGELOG_HEADER }}" | |
- name: Check If Changelog Header is valid | |
if: ${{ env.CHANGELOG_HEADER == '' }} | |
run: exit 1 | |
- name: Create GitHub Release | |
if: ${{ env.CHANGELOG_HEADER != '' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.VERSION }} | |
release_name: v${{ env.VERSION }} | |
draft: false | |
body: See changelog for this version [here](CHANGELOG.md#${{env.CHANGELOG_HEADER}}) | |
prerelease: false | |
publish: | |
needs: [tag,release] | |
if: needs.tag.outputs.tag_created == 'true' | |
# Based on: https://users.rust-lang.org/t/does-anyone-use-github-actions-to-run-cargo-publish/92374/5 | |
name: Publish to crates.io | |
runs-on: ubuntu-latest | |
environment: crates.io | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: swatinem/rust-cache@v2 | |
- name: cargo publish | |
# https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials | |
run: | | |
cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} && cargo publish --verbose --locked |