-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (70 loc) · 2.34 KB
/
docs_cleanup.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: documentation cleanup
on:
schedule:
- cron: '0 1 * * *'
jobs:
docs-cleanup:
runs-on: ubuntu-latest
if: github.repository == 'cvc5/cvc5'
steps:
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-jinja2
- name: Setup Deploy Key
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.CVC5_DOCS_TOKEN }}"
- name: Clone docs repo
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
git config --global user.email "docbot@cvc5"
git config --global user.name "DocBot"
git clone git@github.com:cvc5/docs-ci.git target/
- name: Remove stale docs
run: |
cd target
for file in `find ./ -maxdepth 1 -name "docs-*"`; do
mod=`git log -1 HEAD --pretty="%ai" $file`
touch -d "$mod" $file
done
find ./ -maxdepth 1 -name "docs-*" -mtime +7 -exec git rm --quiet -r {} +
find ./ -maxdepth 1 -name "docs-*" -xtype l -exec git rm --quiet {} +
git commit -m "Prune docs" --quiet || echo "Nothing to prune"
- name: Squash old commits
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
cd target
first=`git rev-list --max-parents=0 HEAD`
cutoff=`date -d "-1 month" +%Y-%m-%d`
last=`git log --pretty='%as %H' | awk -v cutoff=$cutoff '$1 < cutoff { print $2 }' | head -n1`
if [ -n "$last" ]; then
git checkout $last
ts=`git log -1 --format=%ct`
git reset --soft $first
if git diff --cached --quiet --exit-code
then
echo "Nothing to squash"
else
git commit -m "Squash old history" --date=$ts --quiet
fi
git cherry-pick $last..main > /dev/null
fi
- name: Push
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
cd target
python3 genindex.py
git add README.md
if git diff --cached --exit-code
then
echo "Nothing changed"
else
git commit -m "Update README.md"
fi
git push -f origin HEAD:main