Created
September 14, 2022 12:44
-
-
Save ar2pi/2fb9cc003cb18ddb4dcc5b9640473a28 to your computer and use it in GitHub Desktop.
GitHub Action | Release with semver version bump + release branch tagging
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: | |
inputs: | |
versionBump: | |
description: 'Version bump' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
release: | |
name: release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout release branch | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
repository: ${{ github.repository }} | |
ref: release | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Commit new release | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git commit --allow-empty -m "#${{ github.event.inputs.versionBump }}" | |
git push | |
- name: Bump version and push tag | |
run: | | |
curl https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver -o semver | |
mv semver /usr/local/bin | |
chmod +x /usr/local/bin/semver | |
t=$(git rev-list --tags --max-count=1) | |
if [[ $t != "" ]]; then | |
t=$(git describe --tags $t) | |
fi | |
prevVersion="${t:-v0.0.0}" | |
newVersion="" | |
input="${{ github.event.inputs.versionBump }}" | |
case "$input" in | |
*major*) newVersion=$(semver bump major $prevVersion);; | |
*minor*) newVersion=$(semver bump minor $prevVersion);; | |
*patch*) newVersion=$(semver bump patch $prevVersion);; | |
*) newVersion=$(semver bump patch $prevVersion);; | |
esac | |
newVersion="v$newVersion" | |
echo "Previous version: $prevVersion" | |
echo "New version: $newVersion" | |
git tag $newVersion | |
git push origin $newVersion | |
- name: Merge release -> main | |
uses: devmasx/[email protected] | |
with: | |
type: now | |
from_branch: release | |
target_branch: main | |
github_token: ${{ secrets.GH_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment