@@ -2,9 +2,9 @@ name: Publish draft release
22
33on :
44 workflow_dispatch :
5-
65permissions :
76 contents : write
7+ pull-requests : write
88
99jobs :
1010 publish :
1616 - name : Get latest draft release
1717 id : draft
1818 run : |
19- draft_info=$(gh release list --limit 5 --json tagName,isDraft,publishedAt --jq '.[] | select(.isDraft==true) | .tagName' | head -n1)
19+ draft_info=$(gh release list --limit 5 --json tagName,isDraft --jq '.[] | select(.isDraft==true) | .tagName' | head -n1)
2020 echo "tag_name=${draft_info}" >> $GITHUB_OUTPUT
2121 env :
2222 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -29,18 +29,57 @@ jobs:
2929 fi
3030 echo "Found draft version: ${{ steps.draft.outputs.tag_name }}"
3131
32- - name : Write VERSION file
32+ - name : Create branch and commit VERSION
3333 run : |
34+ branch="update-version-${{ steps.draft.outputs.tag_name }}"
35+ git checkout -b "$branch"
3436 echo "${{ steps.draft.outputs.tag_name }}" | sed 's/^v//' > VERSION
35- cat VERSION
36-
37- - name : Commit VERSION file
38- run : |
37+ git add VERSION
3938 git config user.name "github-actions[bot]"
4039 git config user.email "github-actions[bot]@users.noreply.github.com"
41- git add VERSION
42- git commit -m "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" || echo "No changes to commit"
43- git push --force
40+ git commit -m "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" || echo "No changes"
41+ git push origin "$branch"
42+
43+ - name : Create PR
44+ uses : peter-evans/create-pull-request@v6
45+ id : pr
46+ with :
47+ token : ${{ secrets.GITHUB_TOKEN }}
48+ branch : " update-version-${{ steps.draft.outputs.tag_name }}"
49+ base : main
50+ title : " chore: add VERSION ${{ steps.draft.outputs.tag_name }}"
51+ body : " This PR adds or updates the VERSION file for ${{ steps.draft.outputs.tag_name }}"
52+ labels : automated
53+
54+ - name : Auto-merge PR
55+ uses : peter-evans/enable-pull-request-automerge@v2
56+ with :
57+ token : ${{ secrets.GITHUB_TOKEN }}
58+ pull-request-number : ${{ steps.pr.outputs.pull-request-number }}
59+ merge-method : squash
60+
61+ - name : Wait for merge
62+ uses : actions/github-script@v7
63+ with :
64+ script : |
65+ const prNum = parseInt("${{ steps.pr.outputs.pull-request-number }}")
66+ let merged = false
67+ const maxRetries = 20
68+ let tries = 0
69+ while(!merged && tries < maxRetries){
70+ const pr = await github.rest.pulls.get({
71+ owner: context.repo.owner,
72+ repo: context.repo.repo,
73+ pull_number: prNum
74+ })
75+ merged = pr.data.merged
76+ if(!merged){
77+ tries++
78+ console.log("Waiting for PR to merge...")
79+ await new Promise(r => setTimeout(r, 5000))
80+ }
81+ }
82+ if(!merged) throw new Error("PR not merged in time")
4483
4584# - name: Create tag
4685# run: |
0 commit comments