From d689dad1318f9bfd047629ea8623d0bd0c69745d Mon Sep 17 00:00:00 2001 From: Rich Tebb Date: Fri, 25 Mar 2022 09:14:44 +0000 Subject: [PATCH] Automate moving major ref on release publish (#13) * feat: Automate bump of major version ref * Update changelog --- .github/workflows/release-published.yml | 39 +++++++++++++++++++++++++ CHANGELOG.md | 6 ++++ 2 files changed, 45 insertions(+) diff --git a/.github/workflows/release-published.yml b/.github/workflows/release-published.yml index b8b83d8..b67ea08 100644 --- a/.github/workflows/release-published.yml +++ b/.github/workflows/release-published.yml @@ -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 }}" diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c7218..0f6269c 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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