Skip to content

Commit 4e84724

Browse files
fix: update release workflow to create PR instead of pushing directly… (#407)
* fix: update release workflow to create PR instead of pushing directly to protected main branch - Create a branch for release updates - Open a pull request instead of direct push - Auto-approve and merge the PR with squash - Requires enabling auto-merge in repository settings * fix: resolve yamllint errors in release workflow - Quote 'on' key to avoid truthy value warning - Remove trailing spaces on lines 97, 101, and 104 * feat: add complete CHANGELOG automation from feature/automatic-releases - Add scripts/update-changelog-from-release.sh for automatic changelog updates - Add CHANGELOG.md with complete release history - Fix sed command to use pipe separator for better compatibility - Integrate changelog updates into PR-based release workflow --------- Co-authored-by: Pablo Garcia Miranda <[email protected]>
1 parent a1e41fb commit 4e84724

File tree

3 files changed

+505
-5
lines changed

3 files changed

+505
-5
lines changed

.github/workflows/release.yaml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
# Get tag name and message
3232
TAG_NAME=${GITHUB_REF#refs/tags/}
33-
TAG_MESSAGE=$(git tag -n1 "$TAG_NAME" | sed "s/^$TAG_NAME[[:space:]]*//")
33+
TAG_MESSAGE=$(git tag -n1 "$TAG_NAME" | sed "s|^$TAG_NAME[[:space:]]*||")
3434
3535
# If tag message is empty, use a default
3636
if [ -z "$TAG_MESSAGE" ]; then
@@ -64,16 +64,43 @@ jobs:
6464
run: |
6565
./scripts/bump-version.sh "${{ steps.tag_data.outputs.TAG_NAME }}"
6666
67+
- name: Update CHANGELOG.md
68+
env:
69+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
run: |
71+
./scripts/update-changelog-from-release.sh "${{ steps.tag_data.outputs.TAG_NAME }}"
72+
6773
- name: Commit and push changes
74+
env:
75+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6876
run: |
6977
# Check if there are changes to commit
7078
if git diff --quiet; then
7179
echo "No changes to commit"
7280
exit 0
7381
fi
7482
75-
git add config/manager/kustomization.yaml
76-
git commit -m "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} [skip ci]"
83+
# Create a new branch for the changes
84+
BRANCH_NAME="release-updates-${{ steps.tag_data.outputs.TAG_NAME }}"
85+
git checkout -b "$BRANCH_NAME"
86+
87+
git add config/manager/kustomization.yaml CHANGELOG.md
88+
git commit -m "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog [skip ci]"
89+
90+
# Push the branch and create PR
91+
git push origin "$BRANCH_NAME"
92+
PR_URL=$(gh pr create \
93+
--title "chore: bump version to ${{ steps.tag_data.outputs.TAG_NAME }} and update changelog" \
94+
--body "Automated version bump and changelog update for release ${{ steps.tag_data.outputs.TAG_NAME }}" \
95+
--head "$BRANCH_NAME" \
96+
--base main)
97+
98+
# Extract PR number from URL
99+
PR_NUMBER=$(echo "$PR_URL" | sed 's/.*\/pull\///')
100+
echo "Created PR #$PR_NUMBER: $PR_URL"
101+
102+
# Auto-approve the PR
103+
gh pr review "$PR_NUMBER" --approve --body "Auto-approving automated release PR"
77104
78-
# Push to main branch
79-
git push origin HEAD:main
105+
# Enable auto-merge and merge the PR
106+
gh pr merge "$PR_NUMBER" --auto --squash --delete-branch

0 commit comments

Comments
 (0)