Skip to content

Commit 258376e

Browse files
MrSidimsjsji
authored andcommitted
Add post-commit job to cleanup backport branches (#3176)
Signed-off-by: Sidorov, Dmitry <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@c846c0516e3ff64
1 parent 8c0becb commit 258376e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Cleanup Backport Branches
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup:
12+
if: >
13+
github.event.pull_request.head.repo.full_name == github.repository &&
14+
startsWith(github.event.pull_request.head.ref, 'backport/pr-')
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Delete branch
19+
uses: actions/github-script@v7
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
script: |
23+
const branch = context.payload.pull_request.head.ref;
24+
try {
25+
await github.rest.git.deleteRef({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
ref: `heads/${branch}`
29+
});
30+
console.log(`Success. Deleted '${branch}'`);
31+
} catch (error) {
32+
if (error.status === 422) {
33+
console.log(`Branch '${branch}' not found`);
34+
}
35+
} else {
36+
throw error;
37+
}
38+
}

0 commit comments

Comments
 (0)