Skip to content

Commit 794b28b

Browse files
authored
Merge branch 'main' into revert-16952-revert-16947-optimize-sitetree
2 parents 969c8d5 + d6e854b commit 794b28b

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

.github/workflows/repo-sync.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ jobs:
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()

0 commit comments

Comments
 (0)