Skip to content

Cut Release

Cut Release #1

Workflow file for this run

name: Cut Release
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
cut-release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Compute new version
id: version
run: |
CURRENT=$(grep '^version:' charts/repo-guard/Chart.yaml | awk '{print $2}')
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
case "${{ github.event.inputs.bump }}" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "Current version: $CURRENT → New version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Update versions in Chart.yaml and Makefile
run: |
NEW_VERSION=${{ steps.version.outputs.new_version }}
sed -i "s/^version: .*/version: $NEW_VERSION/" charts/repo-guard/Chart.yaml
sed -i "s/^appVersion: .*/appVersion: \"$NEW_VERSION\"/" charts/repo-guard/Chart.yaml
sed -i "s|^IMG ?= \(.*\):.*|IMG ?= \1:$NEW_VERSION|" Makefile
- name: Create and auto-merge Pull Request
id: pr
env:
GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }}
run: |
NEW_VERSION=${{ steps.version.outputs.new_version }}
BRANCH_NAME="release-$NEW_VERSION"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH_NAME"
git add charts/repo-guard/Chart.yaml Makefile
git commit -s -m "chore: prepare release $NEW_VERSION"
git push origin "$BRANCH_NAME"
PR_URL=$(gh pr create \
--title "chore: prepare release $NEW_VERSION" \
--body "Automated version bump to $NEW_VERSION for release." \
--head "$BRANCH_NAME" \
--base main)
echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT"
echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
gh pr merge "$PR_URL" --auto --squash
- name: Wait for PR to merge
env:
GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }}
run: |
PR_URL=${{ steps.pr.outputs.pr_url }}
echo "Waiting for PR to merge: $PR_URL"
for i in $(seq 1 30); do
STATE=$(gh pr view "$PR_URL" --json state -q '.state')
if [ "$STATE" = "MERGED" ]; then
echo "PR merged."
exit 0
fi
echo "State: $STATE, attempt $i/30 — waiting 20s..."
sleep 20
done
echo "Timed out waiting for PR to merge." >&2
exit 1
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN_PR }}
run: |
NEW_VERSION=${{ steps.version.outputs.new_version }}
# Fetch the latest main so the tag points at the merge commit
git fetch origin main
git checkout main
git pull origin main
gh release create "v$NEW_VERSION" \
--title "v$NEW_VERSION" \
--generate-notes \
--target main