From 6bcf1394936aa6365ad9b6361dd30ad38bf5f0d1 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:04:37 +0200 Subject: [PATCH] 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. --- .github/workflows/publish_release.yml | 65 +++++++++++++++------------ 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index f8ddd32..57c8a38 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -1,7 +1,7 @@ name: Publish draft release on: - workflow_dispatch: + workflow_dispatch: # Manual trigger; can be automated later permissions: contents: write @@ -14,7 +14,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - + - name: Get latest draft release id: draft run: | @@ -31,46 +31,55 @@ jobs: fi echo "Found draft version: ${{ steps.draft.outputs.tag_name }}" - + - name: Create branch and commit VERSION run: | - branch="update-version-${{ steps.draft.outputs.tag_name }}" - git push origin --delete "$branch" || echo "No remote branch to delete" - git fetch origin main - git checkout -b "$branch" origin/main - version="${{ steps.draft.outputs.tag_name }}" - echo "$version" | sed 's/^v//' > VERSION - echo "# generated at $(date +%s)" >> VERSION - git add VERSION - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git commit -m "chore: add VERSION $version" || echo "No changes" - git push --set-upstream origin "$branch" - -# - name: Create pull request -# id: pr -# uses: peter-evans/create-pull-request@v6 -# with: -# token: ${{ secrets.GITHUB_TOKEN }} -# branch: "update-version-${{ steps.draft.outputs.tag_name }}" -# base: main -# title: "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" -# body: "This PR adds or updates the VERSION file for ${{ steps.draft.outputs.tag_name }}" -# labels: automated + 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 fetch origin main + git checkout -b "$branch" origin/main + # Write VERSION file and timestamp to ensure a diff + version="${{ steps.draft.outputs.tag_name }}" + echo "$version" | sed 's/^v//' > VERSION + echo "# generated at $(date +%s)" >> VERSION + git add VERSION + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -m "chore: add VERSION $version" --allow-empty + git push --set-upstream origin "$branch" + + - name: Create PR with GitHub CLI + id: pr + run: | + pr_number=$(gh pr create \ + --base main \ + --head update-version-${{ steps.draft.outputs.tag_name }} \ + --title "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" \ + --body "Adds VERSION file for release ${{ steps.draft.outputs.tag_name }}" \ + --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 uses: peter-evans/enable-pull-request-automerge@v2 with: token: ${{ secrets.GITHUB_TOKEN }} - pull-request-number: ${{ steps.pr.outputs.pull-request-number }} + pull-request-number: ${{ steps.pr.outputs.pr_number }} merge-method: squash + - name: Wait for PR merge uses: actions/github-script@v7 with: script: | - const prNum = parseInt("${{ steps.pr.outputs.pull-request-number }}") + const prNum = parseInt("${{ steps.pr.outputs.pr_number }}") let merged = false const maxRetries = 20 let tries = 0