-
Notifications
You must be signed in to change notification settings - Fork 26
180 lines (160 loc) · 5.97 KB
/
mkdocs.yml
File metadata and controls
180 lines (160 loc) · 5.97 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Make Documentation
on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]
types: [ opened, synchronize, reopened, closed ]
permissions:
contents: write
pull-requests: write
env:
REPO_METADATA_SHAS: repo-metadata-shas.txt
jobs:
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: apt install
uses: nick-invision/retry@v2.4.0
with:
max_attempts: 5
timeout_minutes: 15
command: |
sudo apt-get update
sudo apt-get install -yqq build-essential libxml2-dev zlib1g-dev bison flex libcairo2-dev pkg-config
- name: Set up Python install env
run: |
python3 -m venv venv
. venv/bin/activate
python -m pip install -U pip
echo "export MAKEFLAGS=\"PYTHON=$(which python) PIP_OPTS=-U\"" >> ~/.bashrc
- name: Install Python dependencies
uses: nick-invision/retry@v2.4.0
with:
max_attempts: 5
timeout_minutes: 15
command: |
. venv/bin/activate
pip install pygithub
make install
- name: Check and build
uses: nick-invision/retry@v2.4.0
with:
max_attempts: 5
timeout_minutes: 15
command: |
. venv/bin/activate
make check
export GITHUB_TOKEN=${{ github.token }}
make build
- name: Deploy branch preview
if: github.event_name == 'pull_request'
run: |
BRANCH_NAME="${{ github.head_ref }}"
SAFE_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g')
. venv/bin/activate
# Build with site_url set so navigation works in subdirectory
cat > mkdocs-preview.yml << EOF
INHERIT: mkdocs.yml
site_url: https://docs.openworm.org/preview/$SAFE_BRANCH/
EOF
python -m mkdocs build -f mkdocs-preview.yml --site-dir /tmp/site_preview
# Push to gh-pages under preview/<branch>/
git fetch origin gh-pages:gh-pages
git config user.name github-actions
git config user.email github-actions@github.com
git checkout gh-pages
mkdir -p preview/$SAFE_BRANCH
rm -rf preview/$SAFE_BRANCH/*
cp -r /tmp/site_preview/* preview/$SAFE_BRANCH/
git add preview/$SAFE_BRANCH
git commit -m "Deploy preview: $BRANCH_NAME @ ${GITHUB_SHA::7} [ci skip]" || echo "No changes to commit"
git remote set-url origin https://${{ github.token }}@github.com/${{ github.repository_owner }}/openworm_docs.git
git push origin gh-pages
- name: Comment preview URL on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const branch = '${{ github.head_ref }}'.replace(/[^a-zA-Z0-9-]/g, '-');
const url = `https://docs.openworm.org/preview/${branch}/`;
const marker = '<!-- preview-url -->';
const body = `${marker}\n**Preview:** ${url}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Archive production artifacts
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: built-site
path: site
- name: mkdocs gh-deploy
if: github.ref == 'refs/heads/master'
run: |
SHA="${{ github.sha }}"
set -x
git fetch origin gh-pages:gh-pages
git config user.name github-actions
git config user.email github-actions@github.com
. venv/bin/activate
mv $REPO_METADATA_SHAS $REPO_METADATA_SHAS.temp
git checkout gh-pages
cp $REPO_METADATA_SHAS.temp $REPO_METADATA_SHAS
LAST_BUILT_SHA=
if [[ -f ./last_build_sha ]] ; then
LAST_BUILT_SHA=$(cat last_build_sha)
fi
if [[ "$LAST_BUILT_SHA" = "$SHA" ]] && git diff origin/gh-pages --exit-code $REPO_METADATA_SHAS ; then
echo "No changes in repo metadata. Skipping deploy"
else
git checkout -
ghp-import -o -n site
git checkout gh-pages
echo -n $SHA > last_build_sha
git add last_build_sha
mv $REPO_METADATA_SHAS.temp $REPO_METADATA_SHAS
git commit --amend -m "Deploy master@$SHA [ci skip]"
git remote set-url origin https://${{ github.token }}@github.com/${{ github.repository_owner }}/openworm_docs.git
git push -f origin gh-pages
fi
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Remove preview from gh-pages
run: |
BRANCH_NAME="${{ github.head_ref }}"
SAFE_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g')
git fetch origin gh-pages:gh-pages
git config user.name github-actions
git config user.email github-actions@github.com
git checkout gh-pages
if [ -d "preview/$SAFE_BRANCH" ]; then
rm -rf preview/$SAFE_BRANCH
git add -A preview/
git commit -m "Remove preview: $BRANCH_NAME [ci skip]"
git remote set-url origin https://${{ github.token }}@github.com/${{ github.repository_owner }}/openworm_docs.git
git push origin gh-pages
fi