Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions tools/bump-version.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading