-
Notifications
You must be signed in to change notification settings - Fork 169
Automate release workflow #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| 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 }} |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that installed in the job container?