Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate moving major ref on release publish #13

Merged
merged 15 commits into from
Mar 25, 2022
39 changes: 39 additions & 0 deletions .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,43 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get release version
id: get-release-version
run: |
VERSION="${{ github.event.release.tag_name }}"
if [[ ! $VERSION ]]; then
VERSION="${{ github.event.inputs.release-version }}"
fi

RE='^[vV]?([0-9]+)[.]([0-9]+)[.]([0-9]+)(-[0-9A-Za-z.+-]*)?'
if [[ $VERSION =~ $RE ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
PRERELEASE="${BASH_REMATCH[4]}"
else
echo "::error::Version '$VERSION' is not in a valid format" && exit 1
fi

echo "::set-output name=major-ref::v$MAJOR"
if [[ "$PRERELEASE" ]]; then pre=true; else pre=false; fi
echo "::set-output name=is-prerelease::$pre"

- name: Prerelease
if: fromJSON(steps.get-release-version.outputs.is-prerelease)
run: |
echo "::notice::Pre-release version detected, not moving ref ${{ steps.get-release-version.outputs.major-ref }}"

- name: Update major release ref
if: ${{ ! fromJSON(steps.get-release-version.outputs.is-prerelease) }}
run: |
VERSION="${{ github.event.release.tag_name }}"
if [[ ! $VERSION ]]; then
VERSION="${{ github.event.inputs.release-version }}"
fi
git push origin $VERSION:${{ steps.get-release-version.outputs.major-ref }}
echo "::notice::Updated ref ${{ steps.get-release-version.outputs.major-ref }}"

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added

- Automatically bump the major ref (e.g. `v1`) when a release is published

## [0.1.0] - 2022-03-14

### Fixed
Expand Down