docs: update README.md #33
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: Create Tag on Release Commit | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
create-tag: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.extract_version.outputs.version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.RELEASE_BOT }} | |
- name: Extract version from commit message | |
id: extract_version | |
run: | | |
COMMIT_MSG=$(git log --format=%B -n 1 ${{ github.sha }}) | |
if [[ $COMMIT_MSG =~ chore\(main\):\ release\ ([0-9]+\.[0-9]+\.[0-9]+) ]]; then | |
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT | |
else | |
echo "version=" >> $GITHUB_OUTPUT | |
fi | |
- name: Create and push tag | |
if: steps.extract_version.outputs.version != '' | |
run: | | |
VERSION=${{ steps.extract_version.outputs.version }} | |
git config user.name Guilherme Prokisch | |
git config user.email guilherme.prokisch@gmail.com | |
git tag -a v$VERSION -m "Release v$VERSION" | |
git push origin v$VERSION | |
env: | |
GH_TOKEN: ${{ secrets.RELEASE_BOT }} | |
publish: | |
name: Publish to crates.io | |
needs: create-tag | |
if: needs.create-tag.outputs.version != '' | |
runs-on: ubuntu-latest | |
environment: crates.io | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: swatinem/rust-cache@v2 | |
- name: Publish | |
run: > | |
cargo publish | |
--verbose | |
--locked | |
--token ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
cleanup-pr-labels: | |
name: Remove labels from release PR | |
needs: [create-tag, publish] | |
if: needs.create-tag.outputs.version != '' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.RELEASE_BOT }} | |
- name: Remove labels from release PR | |
env: | |
GH_TOKEN: ${{ secrets.RELEASE_BOT }} | |
VERSION: ${{ needs.create-tag.outputs.version }} | |
run: | | |
PR_NUMBER=$(gh pr list --state closed --limit 1 --search "chore(main): release $VERSION in:title" --json number --jq '.[0].number') | |
if [ ! -z "$PR_NUMBER" ]; then | |
echo "Found PR #$PR_NUMBER for release $VERSION" | |
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name') | |
for label in $LABELS; do | |
echo "Removing label: $label" | |
gh pr edit $PR_NUMBER --remove-label "$label" | |
done | |
else | |
echo "No matching PR found for release $VERSION" | |
fi |