Skip to content

Commit 6556934

Browse files
ci: Automate version updates with pull requests and auto-merge
Refactors the version update process to create an automated pull request instead of directly pushing changes to the default branch. This improves traceability and allows for better integration practices. Enables auto-merge for these generated pull requests, ensuring efficient integration of version bumps. Updates `checkout` actions to use `github.token` for standard repository operations, simplifying token management. A conditional check is added to only create a pull request if version changes are detected.
1 parent b0890a1 commit 6556934

1 file changed

Lines changed: 37 additions & 10 deletions

File tree

.github/workflows/ci-cd-pipeline.yml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ jobs:
110110
- name: Checkout code
111111
uses: actions/checkout@v4
112112
with:
113-
token: ${{ secrets.GH_TOKEN }}
114113
fetch-depth: 0
114+
token: ${{ github.token }}
115115

116116
- name: Configure Git
117117
run: |
118118
git config --local user.email "github-actions[bot]@users.noreply.github.com"
119119
git config --local user.name "github-actions[bot]"
120120
121121
- name: Update Directory.Build.props
122+
id: update
122123
run: |
123124
VERSION="${{ needs.extract-version.outputs.version }}"
124125
ASSEMBLY_VERSION="${{ needs.extract-version.outputs.assembly_version }}"
@@ -139,17 +140,43 @@ jobs:
139140
140141
echo "Updated Directory.Build.props:"
141142
grep -E "(VersionPrefix|AssemblyVersion|FileVersion)" Directory.Build.props
142-
143-
- name: Commit and push version changes
144-
run: |
143+
144+
# Check if there are changes
145145
if git diff --quiet Directory.Build.props; then
146-
echo "No version changes to commit"
146+
echo "No version changes detected"
147+
echo "has_changes=false" >> $GITHUB_OUTPUT
147148
else
148-
git add Directory.Build.props
149-
git commit -m "chore: update version to ${{ needs.extract-version.outputs.version }} (assembly: ${{ needs.extract-version.outputs.assembly_version }}) [skip ci]"
150-
git push origin HEAD:${{ github.event.repository.default_branch }}
151-
echo "Version changes committed and pushed"
149+
echo "Version changes detected"
150+
echo "has_changes=true" >> $GITHUB_OUTPUT
152151
fi
152+
153+
- name: Create Pull Request
154+
if: steps.update.outputs.has_changes == 'true'
155+
id: cpr
156+
uses: peter-evans/create-pull-request@v6
157+
with:
158+
token: ${{ github.token }}
159+
commit-message: 'chore: update version to ${{ needs.extract-version.outputs.version }} (assembly: ${{ needs.extract-version.outputs.assembly_version }}) [skip ci]'
160+
branch: version-update-${{ needs.extract-version.outputs.version }}
161+
delete-branch: true
162+
title: 'Update version to ${{ needs.extract-version.outputs.version }}'
163+
body: |
164+
Automated version update for release ${{ needs.extract-version.outputs.tag_name }}
165+
166+
- Version: ${{ needs.extract-version.outputs.version }}
167+
- Assembly Version: ${{ needs.extract-version.outputs.assembly_version }}
168+
- Commit Count: ${{ needs.extract-version.outputs.commit_count }}
169+
170+
Auto-generated by GitHub Actions
171+
labels: automated
172+
173+
- name: Enable auto-merge for PR
174+
if: steps.cpr.outputs.pull-request-number != ''
175+
env:
176+
GH_TOKEN: ${{ github.token }}
177+
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
178+
run: |
179+
gh pr merge --auto --rebase --delete-branch "$PR_NUMBER"
153180
154181
create-release:
155182
name: Create GitHub Release
@@ -162,7 +189,7 @@ jobs:
162189
uses: actions/checkout@v4
163190
with:
164191
fetch-depth: 0
165-
token: ${{ secrets.GH_TOKEN }}
192+
token: ${{ github.token }}
166193

167194
- name: Generate release notes
168195
id: release_notes

0 commit comments

Comments
 (0)