Skip to content

Commit 3bd746d

Browse files
authored
Merge pull request #2736 from canonical/ci-delete-bauer-output-branch
ci: cleanup bauer generated branch
2 parents 50e3a1d + 4b2ac7c commit 3bd746d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Delete generated output branch after merge
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup-output-branch:
12+
if: github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Delete Bauer parse-output branch after merge
17+
env:
18+
PR_BODY: ${{ github.event.pull_request.body }}
19+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
run: |
21+
# Detect the Bauer parse-output branch referenced in the PR body,
22+
# e.g. "bauer/doc-suggestions-<id>".
23+
BAUER_BRANCH=$(printf '%s' "$PR_BODY" \
24+
| grep -oE 'bauer/doc-suggestions-[A-Za-z0-9._-]+' \
25+
| head -n 1)
26+
27+
if [ -z "$BAUER_BRANCH" ]; then
28+
echo "No Bauer parse-output branch found in PR body, nothing to do."
29+
exit 0
30+
fi
31+
32+
echo "Deleting branch: $BAUER_BRANCH"
33+
gh api \
34+
-X DELETE \
35+
"repos/${{ github.repository }}/git/refs/heads/$BAUER_BRANCH"

0 commit comments

Comments
 (0)