Bump Version #33
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: Bump Version | |
on: | |
workflow_dispatch: | |
inputs: | |
update: | |
description: 'Semver update type (patch, minor, major)' | |
required: true | |
default: 'minor' | |
permissions: | |
contents: read | |
env: | |
VERSION_FILE: pkg/version/version.go | |
jobs: | |
version: | |
if: ${{ github.repository }} == 'chainguard-dev/malcontent' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
pull-requests: write | |
steps: | |
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 | |
with: | |
egress-policy: audit | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- uses: chainguard-dev/actions/setup-gitsign@e82b4e5ae10182af72972addcb3fedf7454621c8 | |
- name: Set up Octo-STS | |
uses: octo-sts/action@6177b4481c00308b3839969c3eca88c96a91775f # v1.0.0 | |
id: octo-sts | |
with: | |
scope: chainguard-dev/malcontent | |
identity: release | |
- name: Update Version | |
id: update | |
run: | | |
UPDATE_TYPE=${{ github.event.inputs.update }} | |
CURRENT_VERSION=$(awk -F'"' '/ID string =/ {print $2}' ${{ env.VERSION_FILE }}) | |
if [[ ! "${CURRENT_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Error: CURRENT_VERSION is not a valid semver" | |
exit 1 | |
fi | |
IFS='.' read -ra VERSION_PARTS <<< "${CURRENT_VERSION:1}" | |
case "$UPDATE_TYPE" in | |
major) | |
VERSION=$(printf "v%d.0.0" $((${VERSION_PARTS[0]}+1))) | |
;; | |
minor) | |
VERSION=$(printf "v%s.%d.0" ${VERSION_PARTS[0]} $((${VERSION_PARTS[1]}+1))) | |
;; | |
patch) | |
VERSION=$(printf "v%s.%s.%d" ${VERSION_PARTS[0]} ${VERSION_PARTS[1]} $((${VERSION_PARTS[2]}+1))) | |
;; | |
*) | |
echo "Error: Invalid update type" | |
exit 1 | |
;; | |
esac | |
if [[ ! "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Error: VERSION is not a valid semver" | |
exit 1 | |
fi | |
echo "Current malcontent version: $CURRENT_VERSION" | |
echo "New malcontent version: $VERSION" | |
sed -i "s/ID string = \"v[0-9]*\.[0-9]*\.[0-9]*\"/ID string = \"${VERSION}\"/" ${{ env.VERSION_FILE }} | |
BRANCH="malcontent-version-bump-$VERSION" | |
git checkout -b $BRANCH | |
git add ${{ env.VERSION_FILE }} | |
git commit -m "Bump malcontent version to $VERSION" | |
git push origin $BRANCH | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
- name: Create Pull Request | |
env: | |
GH_TOKEN: ${{ steps.octo-sts.outputs.token }} | |
run: | | |
VERSION=${{ steps.update.outputs.VERSION }} | |
gh pr create -t "Update malcontent to $VERSION" -b "PR to update the version in ${{ env.VERSION_FILE }} to $VERSION" -B main |