Skip to content

Commit 65a23e2

Browse files
authored
Merge pull request #50 from dscho/reinstate-the-release-branch-if-necessary
release-git: handle missing `release` branch gracefully
2 parents 8cb6677 + 2190c56 commit 65a23e2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

.github/workflows/release-git.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ jobs:
3434
uses: actions/github-script@v6
3535
with:
3636
script: |
37-
const { data: { object: { sha } } } = await github.rest.git.getRef({
38-
owner: context.repo.owner,
39-
repo: context.repo.repo,
40-
ref: 'heads/release'
41-
})
37+
const sha = await (async () => {
38+
try {
39+
return (await github.rest.git.getRef({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
ref: 'heads/release'
43+
})).data.object.sha
44+
} catch (e) {
45+
// If the ref does not exist, use an undefined `sha`
46+
if (e?.status === 404) return undefined
47+
throw e
48+
}
49+
})()
4250
4351
if (sha !== '${{ github.sha }}') {
4452
console.log(`Trying to update the 'release' branch by fast-forwarding to 'main' in ${context.repo.owner}/${context.repo.repo}`)

0 commit comments

Comments
 (0)