-
Notifications
You must be signed in to change notification settings - Fork 47
47 lines (41 loc) · 1.49 KB
/
closePR.yml
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
# Github action to cleanup a PR preview
# Runs on dispatch or weekly schedule and deletes closed PR previews that are older than 7 days
#
name: PR Preview Cleanup
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * 1"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Iterate and Check PRs
id: pr_check
run: |
pr_folders=($(cd pr && ls -d */))
closed_pr=()
for pr_folder in "${pr_folders[@]}"; do
pr_status=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-X GET "https://api.github.com/repos/${{ github.repository }}/pulls/${pr_folder::-1}" \
| jq -r '.state')
echo "PR ${pr_folder::-1} is $pr_status"
if [ "$pr_status" != "open" ]; then
rm -rf "pr/${pr_folder::-1}"
closed_pr+=("${pr_folder::-1}")
echo "Removed folder pr/${pr_folder::-1} for closed PR ${pr_folder::-1}"
fi
done
echo "${closed_pr[*]}" >> $GITHUB_STATE
- name: Commit and push to gh-pages
uses: EndBug/[email protected]
with:
committer_email: [email protected]
committer_name: Fortran
message: "Sphinx build cleanup pr/${{ steps.pr_check.outputs.closed_pr }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}