This repository has been archived by the owner on May 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (55 loc) · 2.01 KB
/
cleanup.yaml
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
58
59
60
61
62
63
64
65
name: Clean up
on:
# Enable "pull_request" for testing
# pull_request:
# daily jobs
schedule:
- cron: '0 0 * * *'
jobs:
cleanup:
name: Cleanup gh-pages
runs-on: ubuntu-latest
steps:
- name: Checkout the gh-pages branch
uses: actions/checkout@v3
with:
ref: gh-pages
fetch-depth: 0
- name: Install markdown tool
run: |
sudo apt-get update
sudo apt-get install markdown
- name: Cleanup, squash and push
run: |
# delete the documentation if the corresponding branch is deleted
for dir in $(find seismo-learn -mindepth 2 -maxdepth 2); do
# directory is "user/repository/branch"
repo=$(dirname $dir)
branch=$(basename $dir)
# the "git ls-remote" command return nothing if a branch is not found
if [[ ! $(git ls-remote --heads https://github.com/${repo} ${branch}) ]]; then
echo "Deleting directory $dir..."
rm -rvf $dir
fi
done
# Make some changes
touch .nojekyll
# generate TOC
echo "## List of sites for previewing changes in PR" > index.md
for branch in $(find seismo-learn -mindepth 2 -maxdepth 2); do
echo "- [$branch](https://seismo-learn.org/sitepreview/$branch)" >> index.md
done
# convert index.md to index.html
markdown index.md > index.html
rm -f index.md
# Configure git to be the GitHub Actions account
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# Commit changes
git add -A .
git status
git commit --allow-empty -m "Commit changes"
# Squash all commits into one
git reset $(git commit-tree HEAD^{tree} -m "Autosquash all commits by scheduled jobs")
# Push changes
git push -fq origin gh-pages 2>&1 > /dev/null