File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7070 github-token : ${{ secrets.GITHUB_TOKEN }}
7171 number : ${{ steps.find-pull-request.outputs.number }}
7272
73+ # There are cases where the branch becomes out-of-date in between the time this workflow began and when the pull request is created/updated
74+ - name : Update branch
75+ uses : actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
76+ with :
77+ github-token : ${{secrets.GITHUB_TOKEN}}
78+ script : |
79+ const mainHeadSha = await github.git.getRef({
80+ ...context.repo,
81+ ref: 'heads/main'
82+ })
83+ console.log(`heads/main sha: ${mainHeadSha.data.object.sha}`)
84+
85+ const pull = await github.pulls.get({
86+ ...context.repo,
87+ pull_number: ${{ steps.find-pull-request.outputs.number }}
88+ })
89+
90+ if (mainHeadSha.data.object.sha !== pull.data.base.sha) {
91+ const updateBranch = await github.pulls.updateBranch({
92+ ...context.repo,
93+ pull_number: ${{ steps.find-pull-request.outputs.number }}
94+ })
95+ console.log(updateBranch.data.message)
96+ } else {
97+ console.log(`Branch is already up-to-date`)
98+ }
99+
73100 - name : Send Slack notification if workflow fails
74101 uses : someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
75102 if : failure()
You can’t perform that action at this time.
0 commit comments