Refactor publish_release workflow for PR creation

Updated the workflow to create a pull request using GitHub CLI and modified the handling of the VERSION file.
This commit is contained in:
Michel Roegl-Brunner
2025-10-07 11:04:37 +02:00
committed by GitHub
parent eb8801bfc8
commit 6bcf139493

View File

@@ -1,7 +1,7 @@
name: Publish draft release name: Publish draft release
on: on:
workflow_dispatch: workflow_dispatch: # Manual trigger; can be automated later
permissions: permissions:
contents: write contents: write
@@ -35,42 +35,51 @@ jobs:
- name: Create branch and commit VERSION - name: Create branch and commit VERSION
run: | run: |
branch="update-version-${{ steps.draft.outputs.tag_name }}" branch="update-version-${{ steps.draft.outputs.tag_name }}"
# Delete remote branch if exists
git push origin --delete "$branch" || echo "No remote branch to delete" git push origin --delete "$branch" || echo "No remote branch to delete"
git fetch origin main git fetch origin main
git checkout -b "$branch" origin/main git checkout -b "$branch" origin/main
# Write VERSION file and timestamp to ensure a diff
version="${{ steps.draft.outputs.tag_name }}" version="${{ steps.draft.outputs.tag_name }}"
echo "$version" | sed 's/^v//' > VERSION echo "$version" | sed 's/^v//' > VERSION
echo "# generated at $(date +%s)" >> VERSION echo "# generated at $(date +%s)" >> VERSION
git add VERSION git add VERSION
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: add VERSION $version" || echo "No changes" git commit -m "chore: add VERSION $version" --allow-empty
git push --set-upstream origin "$branch" git push --set-upstream origin "$branch"
# - name: Create pull request
# id: pr - name: Create PR with GitHub CLI
# uses: peter-evans/create-pull-request@v6 id: pr
# with: run: |
# token: ${{ secrets.GITHUB_TOKEN }} pr_number=$(gh pr create \
# branch: "update-version-${{ steps.draft.outputs.tag_name }}" --base main \
# base: main --head update-version-${{ steps.draft.outputs.tag_name }} \
# title: "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" --title "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" \
# body: "This PR adds or updates the VERSION file for ${{ steps.draft.outputs.tag_name }}" --body "Adds VERSION file for release ${{ steps.draft.outputs.tag_name }}" \
# labels: automated --label automated \
--json number \
--jq '.number')
echo $pr_number
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto-merge PR - name: Auto-merge PR
uses: peter-evans/enable-pull-request-automerge@v2 uses: peter-evans/enable-pull-request-automerge@v2
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.pr.outputs.pull-request-number }} pull-request-number: ${{ steps.pr.outputs.pr_number }}
merge-method: squash merge-method: squash
- name: Wait for PR merge - name: Wait for PR merge
uses: actions/github-script@v7 uses: actions/github-script@v7
with: with:
script: | script: |
const prNum = parseInt("${{ steps.pr.outputs.pull-request-number }}") const prNum = parseInt("${{ steps.pr.outputs.pr_number }}")
let merged = false let merged = false
const maxRetries = 20 const maxRetries = 20
let tries = 0 let tries = 0