Release #3
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: Release | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
verify-branch: | |
name: Verify that runs on the main branch | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fail if branch is not main | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "The release workflow should only be triggered on the main branch" | |
exit 1 | |
get-version: | |
name: Get version from Cargo.toml | |
needs: verify-branch | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get version from Cargo.toml | |
id: lookupVersion | |
uses: mikefarah/yq@bc5b54cb1d1f720db16c9f75c5b45384d00e5cbf | |
with: | |
cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml' | |
- name: Print version | |
id: version | |
run: | | |
VERSION=${{ steps.lookupVersion.outputs.result }} | |
echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
verify-release-existence: | |
name: Check if release exists on GitHub | |
needs: get-version | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if release exists | |
id: check_release | |
run: | | |
VERSION=${{ needs.get-version.outputs.version }} | |
REPO="software-mansion/cairo-annotations" | |
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "Accept: application/json" "https://api.github.com/repos/$REPO/releases/tags/v$VERSION") | |
if [ "$RESPONSE" -eq 200 ]; then | |
echo "Release for version $VERSION already exists on GitHub." | |
exit 1 | |
else | |
echo "No release found for version $VERSION." | |
fi | |
create-release: | |
name: Create release | |
runs-on: ubuntu-latest | |
needs: [verify-release-existence, get-version] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create GitHub release | |
id: create-release | |
uses: taiki-e/create-gh-release-action@72d65cee1f8033ef0c8b5d79eaf0c45c7c578ce3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
changelog: CHANGELOG.md | |
allow-missing-changelog: true | |
title: $version | |
ref: refs/tags/${{ needs.get-version.outputs.version }} |