From 64578304c2d1b5006dd29696b88b97c7148eafef Mon Sep 17 00:00:00 2001 From: Tom Hayward Date: Tue, 9 Dec 2025 10:34:23 -0800 Subject: [PATCH] Automate release workflow Signed-off-by: Tom Hayward --- .github/workflows/release.yaml | 63 ++++++++++++++++++++++++++++++++++ Makefile | 4 +++ tools/bump-version.sh | 51 +++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100755 tools/bump-version.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..94807771 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,63 @@ +name: Release Chart + +on: + workflow_dispatch: + inputs: + version: + description: 'New version (e.g. 1.2.3). If omitted, bumps based on changelog.' + required: false + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v4 + with: + version: v3.12.1 + + - name: Bump Version + run: make bump-version VERSION="${{ inputs.version }}" + + - name: Get New Version + id: version + run: | + new_version=$(grep '^version:' Chart.yaml | awk '{print $2}') + echo "new_version=$new_version" >> $GITHUB_OUTPUT + + - name: Update README + run: make README.md + + - name: Package Chart + run: | + helm dependency build + helm package . -d docs + helm repo index ./docs/ --url https://cortexproject.github.io/cortex-helm-chart + + - name: Create Pull Request + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git checkout -b release-${{ steps.version.outputs.new_version }} + git add Chart.yaml README.md CHANGELOG.md docs/ + git commit -s -m "Release ${{ steps.version.outputs.new_version }}" + git push origin release-${{ steps.version.outputs.new_version }} + gh pr create --title "Release ${{ steps.version.outputs.new_version }}" \ + --body "Automated release PR for version ${{ steps.version.outputs.new_version }}" \ + --base ${{ github.ref_name }} \ + --head release-${{ steps.version.outputs.new_version }} diff --git a/Makefile b/Makefile index be99cc5e..2f4f8506 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ .PHONY: README.md README.md: docker run --rm --volume "$(shell pwd):/helm-docs" -u $(shell id -u) jnorwood/helm-docs:v1.11.0 + +.PHONY: bump-version +bump-version: + ./tools/bump-version.sh $(VERSION) diff --git a/tools/bump-version.sh b/tools/bump-version.sh new file mode 100755 index 00000000..8f4ec9cc --- /dev/null +++ b/tools/bump-version.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +VERSION="${1:-}" + +current_version=$(grep '^version:' Chart.yaml | awk '{print $2}') +echo "Current version: $current_version" + +if [ -n "$VERSION" ]; then + new_version="$VERSION" +else + unreleased_changes=$(awk '/^## master \/ unreleased/{flag=1; next} /^## /{flag=0} flag' CHANGELOG.md) + echo "Unreleased changes analysis:" + echo "$unreleased_changes" + + if echo "$unreleased_changes" | grep -q "\[CHANGE\]"; then + echo "Found [CHANGE], applying major bump." + bump="major" + elif echo "$unreleased_changes" | grep -q "\[ENHANCEMENT\]"; then + echo "Found [ENHANCEMENT], applying minor bump." + bump="minor" + else + echo "Defaulting to patch bump ([BUGFIX], [DEPENDENCY], or other)." + bump="patch" + fi + + IFS='.' read -r -a parts <<< "$current_version" + major="${parts[0]}" + minor="${parts[1]}" + patch="${parts[2]}" + + case "$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" +fi + +echo "New version: $new_version" + +# Update Chart.yaml +# Using temp file for portability +sed "s/^version: .*/version: $new_version/" Chart.yaml > Chart.yaml.tmp && mv Chart.yaml.tmp Chart.yaml + +# Update Changelog +date_str=$(date +%Y-%m-%d) +# Use perl for consistent behavior across platforms (macOS/Linux) regarding newlines in replacement +perl -i -pe "s/^## master \/ unreleased/## master \/ unreleased\n\n## $new_version \/ $date_str/" CHANGELOG.md + +echo "Successfully bumped version to $new_version"