11name : Publish draft release
22
33on :
4- workflow_dispatch :
4+ workflow_dispatch : # Manual trigger; can be automated later
55
66permissions :
77 contents : write
1414 - name : Checkout repo
1515 uses : actions/checkout@v4
1616
17-
17+
1818 - name : Get latest draft release
1919 id : draft
2020 run : |
@@ -31,46 +31,55 @@ jobs:
3131 fi
3232 echo "Found draft version: ${{ steps.draft.outputs.tag_name }}"
3333
34-
34+
3535 - name : Create branch and commit VERSION
3636 run : |
37- branch="update-version-${{ steps.draft.outputs.tag_name }}"
38- git push origin --delete "$branch" || echo "No remote branch to delete"
39- git fetch origin main
40- git checkout -b "$branch" origin/main
41- version="${{ steps.draft.outputs.tag_name }}"
42- echo "$version" | sed 's/^v//' > VERSION
43- echo "# generated at $(date +%s)" >> VERSION
44- git add VERSION
45- git config user.name "github-actions[bot]"
46- git config user.email "github-actions[bot]@users.noreply.github.com"
47- git commit -m "chore: add VERSION $version" || echo "No changes"
48- git push --set-upstream origin "$branch"
49-
50- # - name: Create pull request
51- # id: pr
52- # uses: peter-evans/create-pull-request@v6
53- # with:
54- # token: ${{ secrets.GITHUB_TOKEN }}
55- # branch: "update-version-${{ steps.draft.outputs.tag_name }}"
56- # base: main
57- # title: "chore: add VERSION ${{ steps.draft.outputs.tag_name }}"
58- # body: "This PR adds or updates the VERSION file for ${{ steps.draft.outputs.tag_name }}"
59- # labels: automated
37+ branch="update-version-${{ steps.draft.outputs.tag_name }}"
38+ # Delete remote branch if exists
39+ git push origin --delete "$branch" || echo "No remote branch to delete"
40+ git fetch origin main
41+ git checkout -b "$branch" origin/main
42+ # Write VERSION file and timestamp to ensure a diff
43+ version="${{ steps.draft.outputs.tag_name }}"
44+ echo "$version" | sed 's/^v//' > VERSION
45+ echo "# generated at $(date +%s)" >> VERSION
46+ git add VERSION
47+ git config user.name "github-actions[bot]"
48+ git config user.email "github-actions[bot]@users.noreply.github.com"
49+ git commit -m "chore: add VERSION $version" --allow-empty
50+ git push --set-upstream origin "$branch"
6051
52+
53+ - name : Create PR with GitHub CLI
54+ id : pr
55+ run : |
56+ pr_number=$(gh pr create \
57+ --base main \
58+ --head update-version-${{ steps.draft.outputs.tag_name }} \
59+ --title "chore: add VERSION ${{ steps.draft.outputs.tag_name }}" \
60+ --body "Adds VERSION file for release ${{ steps.draft.outputs.tag_name }}" \
61+ --label automated \
62+ --json number \
63+ --jq '.number')
64+ echo $pr_number
65+ echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
66+ env :
67+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6168
69+
6270 - name : Auto-merge PR
6371 uses : peter-evans/enable-pull-request-automerge@v2
6472 with :
6573 token : ${{ secrets.GITHUB_TOKEN }}
66- pull-request-number : ${{ steps.pr.outputs.pull-request-number }}
74+ pull-request-number : ${{ steps.pr.outputs.pr_number }}
6775 merge-method : squash
6876
77+
6978 - name : Wait for PR merge
7079 uses : actions/github-script@v7
7180 with :
7281 script : |
73- const prNum = parseInt("${{ steps.pr.outputs.pull-request-number }}")
82+ const prNum = parseInt("${{ steps.pr.outputs.pr_number }}")
7483 let merged = false
7584 const maxRetries = 20
7685 let tries = 0
0 commit comments