Skip to content

ci: Make release tag when version is bumped #18

ci: Make release tag when version is bumped

ci: Make release tag when version is bumped #18

Workflow file for this run

name: Release
# This workflow is not ordered after the 'Lint' workflow. And doing so is difficult, because
# workflow_run: only applies on the default branch, and I EXPRESSLY WANT this workflow to run in PRs
# too, because it validates some preconditions for making the release.
#
# So make the assumption that if the PR pipeline passed, and this workflow runs on the default
# branch, it's okay to make a release without waiting for the build and test
on: push
jobs:
trigger-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate SemVer Version
shell: bash # Explicitly setting the shell sets errexit and pipefail flags
run: |
VERSION="$(.github/parse-manifest-key.sh Cargo.toml version)"
echo "Validating SemVer version '$VERSION' ..."
.github/validate-version-is-semver-compliant.sh "$VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Check if current version has a Git tag
id: if-tag-exists
shell: bash
continue-on-error: true
run: |-
# Delete any local tags cached by the runner, and fetch remote tags to ensure we're
# up-to-date.
git tag --list | xargs git tag --delete
git fetch --force --tags
# Exits with success if tag does not exist, failure if tag _does_ exist.
.github/check-if-tag-already-exists.sh \
--tag-prefix 'v' \
--target-branch 'main' \
"$VERSION" \
;
- name: Skip release
if: steps.if-tag-exists.conclusion == 'failure'
run: echo "Found tag for version '$VERSION'. Skipping release ..."
- name: Trigger release
if: steps.if-tag-exists.conclusion == 'success'
# TODO: Restrict this to main or release branches
shell: bash
run: |-
echo "Could not find tag for current version '$VERSION'. Making release ..."
# Run all jobs except "Make The Release" on every push event
release-notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract Release Metadata
shell: bash
run: |
VERSION="$(.github/parse-manifest-key.sh Cargo.toml version)"
DESCRIPTION="$(.github/parse-manifest-key.sh Cargo.toml description)"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "DESCRIPTION=$DESCRIPTION" >> "$GITHUB_ENV"
# Always generate release notes for the current version. If the version from the Cargo
# manifest isn't found in the CHANGELOG.md, then fail the pipeline (even in PRs)
- name: Generate Release Notes
shell: bash
run: .github/get-release-notes.sh "$VERSION" "$DESCRIPTION" | tee release.md
- name: Make The Release
uses: softprops/action-gh-release@v2
# Only actually make the release on a tag
if: startsWith(github.ref, 'refs/tags/')
with:
body_path: release.md
prerelease: ${{ contains(env.VERSION, '-rc') }}
token: ${{ secrets.HEROSTRATUS_RELEASE_TOKEN }}