Skip to content

Commit

Permalink
Automate moving major ref on release publish (#13)
Browse files Browse the repository at this point in the history
* feat: Automate bump of major version ref

* Update changelog
  • Loading branch information
richtea authored Mar 25, 2022
1 parent 671cc19 commit d689dad
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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

0 comments on commit d689dad

Please sign in to comment.