-
Notifications
You must be signed in to change notification settings - Fork 1
57 lines (49 loc) · 1.54 KB
/
cleanup-pages.yml
File metadata and controls
57 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Cleanup Pages
on:
delete:
pull_request:
types: [closed]
permissions:
contents: write
jobs:
cleanup-branch:
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v5
with:
ref: gh-pages
fetch-depth: 0
- name: Remove branch folder
shell: bash
run: |
BRANCH="${{ github.event.ref }}"
SAFE="$(echo "$BRANCH" | tr '[:upper:]' '[:lower:]' | sed -E 's#[^a-z0-9._-]+#-#g')"
DIR="branches/$SAFE"
rm -rf "$DIR"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Remove Pages preview for deleted branch: $BRANCH" || exit 0
git push
cleanup-pr:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v5
with:
ref: gh-pages
fetch-depth: 0
- name: Remove PR folder
shell: bash
run: |
PR="${{ github.event.pull_request.number }}"
DIR="pull/$PR"
rm -rf "$DIR"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Remove Pages preview for closed PR: #$PR" || exit 0
git push