Enhance publish_release workflow with PR automation

Updated the workflow to create a branch for the VERSION file and automate PR creation and merging.
This commit is contained in:
Michel Roegl-Brunner
2025-10-07 10:13:21 +02:00
committed by GitHub
parent 05d88eb8c8
commit 6baef6bb84

View File

@@ -2,9 +2,9 @@ name: Publish draft release
on: on:
workflow_dispatch: workflow_dispatch:
permissions: permissions:
contents: write contents: write
pull-requests: write
jobs: jobs:
publish: publish:
@@ -16,7 +16,7 @@ jobs:
- name: Get latest draft release - name: Get latest draft release
id: draft id: draft
run: | run: |
draft_info=$(gh release list --limit 5 --json tagName,isDraft,publishedAt --jq '.[] | select(.isDraft==true) | .tagName' | head -n1) draft_info=$(gh release list --limit 5 --json tagName,isDraft --jq '.[] | select(.isDraft==true) | .tagName' | head -n1)
echo "tag_name=${draft_info}" >> $GITHUB_OUTPUT echo "tag_name=${draft_info}" >> $GITHUB_OUTPUT
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -29,18 +29,57 @@ jobs:
fi fi
echo "Found draft version: ${{ steps.draft.outputs.tag_name }}" echo "Found draft version: ${{ steps.draft.outputs.tag_name }}"
- name: Write VERSION file - name: Create branch and commit VERSION
run: | run: |
branch="update-version-${{ steps.draft.outputs.tag_name }}"
git checkout -b "$branch"
echo "${{ steps.draft.outputs.tag_name }}" | sed 's/^v//' > VERSION echo "${{ steps.draft.outputs.tag_name }}" | sed 's/^v//' > VERSION
cat VERSION git add VERSION
- name: Commit VERSION file
run: |
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 add VERSION git commit -m "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" || echo "No changes"
git commit -m "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" || echo "No changes to commit" git push origin "$branch"
git push --force
- name: Create PR
uses: peter-evans/create-pull-request@v6
id: pr
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
- 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 }}
merge-method: squash
- name: Wait for merge
uses: actions/github-script@v7
with:
script: |
const prNum = parseInt("${{ steps.pr.outputs.pull-request-number }}")
let merged = false
const maxRetries = 20
let tries = 0
while(!merged && tries < maxRetries){
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNum
})
merged = pr.data.merged
if(!merged){
tries++
console.log("Waiting for PR to merge...")
await new Promise(r => setTimeout(r, 5000))
}
}
if(!merged) throw new Error("PR not merged in time")
# - name: Create tag # - name: Create tag
# run: | # run: |