Skip to content

Trigger release

Trigger release #3

Workflow file for this run

name: Trigger release
on:
workflow_dispatch:
inputs:
version-bump:
description: 'Whether to bump major, minor or patch version'
required: false
default: patch
type: choice
options:
- major
- minor
- patch
desired-version:
description: 'Version to be released; if specified, version-bump will be ignored'
required: false
default: ''
concurrency: release
env:
TAG_PREFIX: v
INITIAL_TAG: v0.1.0
SEMVER_VERSION: 3.4.0
CHART_DIRECTORY: chart
defaults:
run:
shell: bash
jobs:
release:
name: Trigger release
runs-on: ubuntu-22.04
permissions:
contents: write
# TODO: ensure that github.ref is not refs/tags/*
# TODO: maybe even ensure that github.ref == refs/heads/main
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
- name: Setup semver
uses: ./.github/actions/setup-semver
with:
version: ${{ env.SEMVER_VERSION }}
install-directory: ${{ runner.temp }}/bin
- name: Determine current release
id: get_current_release
uses: ./.github/actions/get-highest-tag
with:
prefix: ${{ env.TAG_PREFIX }}
- name: Determine target release
id: get_target_release
run: |
desired_version=${{ inputs.desired-version }}
current_version=${{ steps.get_current_release.outputs.version }}
version_bump=${{ inputs.version-bump }}
if [ -z "$desired_version" ]; then
case $version_bump in
major|minor|patch)
# ok
;;
*)
>&1 echo "Invalid input: version-bump ($version_bump)."
exit 1
esac
if [ -z "$current_version" ]; then
version=${INITIAL_TAG/#$TAG_PREFIX/}
tag=$INITIAL_TAG
else
version=$(semver bump $version_bump $current_version)
tag=$TAG_PREFIX$version
fi
else
if [[ $desired_version =~ ^$TAG_PREFIX([0-9].*)$ ]]; then
version=${BASH_REMATCH[1]}
tag=$desired_version
else
>&1 echo "Invalid input: desired-version ($desired_version) should start with $TAG_PREFIX."
exit 1
fi
if [ "$(semver validate $version)" != valid ]; then
>&1 echo "Invalid input: desired-version ($version) is not a valid semantic version."
exit 1
fi
if [ "$(semver compare $version $current_version)" -le 0 ]; then
>&1 echo "Invalid input: desired-version ($version) should be higher than current version ($current_version)."
exit 1
fi
fi
echo "Target version: $version"
echo "Target tag: $tag."
echo "version=$version" >> $GITHUB_OUTPUT
echo "tag=$tag" >> $GITHUB_OUTPUT
echo
- name: Update chart version and appVersion
run: |
current_chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
current_app_version=$(yq .appVersion $CHART_DIRECTORY/Chart.yaml)
target_chart_version=${{ steps.get_target_release.outputs.version }}
target_app_version=${{ steps.get_target_release.outputs.tag }}
echo "Updating $CHART_DIRECTORY/Chart.yaml from $current_chart_version to $target_chart_version."
perl -pi -e "s#^version:.*#version: $target_chart_version#g" $CHART_DIRECTORY/Chart.yaml
perl -pi -e "s#^appVersion:.*#appVersion: $target_app_version#g" $CHART_DIRECTORY/Chart.yaml
if [ -z "$(git status --porcelain)" ]; then
echo "Nothing has changed; skipping commit/push."
else
git config user.name "${{ vars.WORKFLOW_USER_NAME }}"
git config user.email "${{ vars.WORKFLOW_USER_EMAIL }}"
git add -A
git commit -m "Bump chart/app version from $current_chart_version/$current_app_version to $target_chart_version/$target_app_version"
git push
fi
- name: Determine target commit
id: get_target_commit
run: |
sha=$(git rev-parse HEAD)
echo "Target commit: $sha."
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_target_release.outputs.tag }}
draft: false
prerelease: false
target_commitish: ${{ steps.get_target_commit.outputs.sha }}
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
generate_release_notes: false