-
Notifications
You must be signed in to change notification settings - Fork 92
136 lines (116 loc) · 4.7 KB
/
docs.yml
File metadata and controls
136 lines (116 loc) · 4.7 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
name: Build Docs
on:
pull_request_target:
push:
branches: [main]
tags:
- '*'
env:
BUILD_GSL: true
COMMIT_EMAIL: ben.jeffery.well+adminbot@gmail.com
MAKE_TARGET: cmodule
OWNER: tskit-dev
REPO: msprime
jobs:
build-deploy-docs:
name: Docs
runs-on: ubuntu-18.04
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
# As we are using pull-request-target which uses the workflow from the base
# of the PR, we need to be specific
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions/cache@v2
id: cache
with:
path: venv
key: docs-venv-v2-${{ hashFiles('requirements/CI-docs/requirements.txt') }}
- name: Build virtualenv
if: steps.cache.outputs.cache-hit != 'true'
run: python -m venv venv
- name: Install deps
run: venv/bin/activate && pip install -r requirements/CI-docs/requirements.txt
- name: Install GSL
if: env.BUILD_GSL == 'true'
run: sudo apt-get install -y libgsl0-dev
- name: Build C module
if: env.MAKE_TARGET
run: venv/bin/activate && make $MAKE_TARGET
- name: Build Docs
run: venv/bin/activate && make -C docs
- name: Wait for others to finish
uses: softprops/turnstyle@v1
with:
same-branch-only: false
env:
GITHUB_TOKEN: ${{ secrets.ADMINBOT_TOKEN }}
- name: Checkout docs site
if: github.repository_owner == env.OWNER
uses: actions/checkout@v2
with:
repository: ${{ env.OWNER }}/${{ env.REPO }}-docs
token: ${{ secrets.ADMINBOT_TOKEN }}
path: ${{ env.REPO }}-docs
- name: Check for diff compared to main branch
if: github.repository_owner == env.OWNER && github.event.pull_request
id: diff
#The html contains commit hashes which we don't want to count as a change
run: |
diff -x .buildinfo -r ${{ env.REPO }}-docs/main docs/_build/html | grep "^[<>]" | grep -v "<title>\|VERSION:" | grep -Ev "\.(css|js)\?" | grep -v "Search\.setIndex" | grep . && echo "::set-output name=change_detected::true" || echo "NO CHANGES"
- name: Copy our docs to the PR specific location
if: github.repository_owner == env.OWNER && github.event.pull_request && steps.diff.outputs.change_detected
working-directory: ${{ env.REPO }}-docs
run: |
rm -rf ${{ github.event.pull_request.number }}
cp -r ../docs/_build/html PR-${{ github.event.pull_request.number }}
- name: Copy our docs to the tag specific location
if: github.repository_owner == env.OWNER && !github.event.pull_request
working-directory: ${{ env.REPO }}-docs
run: |
export DEST=`echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g" | sed -e "s/refs\/tags\///g"`
rm -rf $DEST
cp -r ../docs/_build/html $DEST
- name: Delete closed PRs
if: github.repository_owner == env.OWNER
shell: python
working-directory: ${{ env.REPO }}-docs
run : |
from github import Github
import os
import shutil
g = Github()
repo = g.get_repo("${{ env.OWNER }}/${{ env.REPO }}")
open_prs = [f"PR-{pr.number}" for pr in repo.get_pulls(state="open")]
for name in os.listdir("."):
if name.startswith('PR') and name not in open_prs:
print("Delete:", name)
shutil.rmtree(name)
else:
print("Keep:", name)
- name: Commit --amend docs
if: github.repository_owner == env.OWNER && (steps.diff.outputs.change_detected || (!github.event.pull_request))
working-directory: ${{ env.REPO }}-docs
run: |
git config user.name AdminBOT
git config user.email $COMMIT_EMAIL
git add .
git diff-index --quiet HEAD || git commit --amend --no-edit
git push -f origin main
- name: Comment on PR
if: github.repository_owner == env.OWNER && github.event.pull_request && steps.diff.outputs.change_detected
uses: mshick/add-pr-comment@v1
with:
message: |
📖 Docs for this PR can be previewed [here](https://${{ env.OWNER }}.github.io/${{ env.REPO }}-docs/PR-${{ github.event.pull_request.number }}/)
allow-repeats: false
repo-token: ${{ secrets.ADMINBOT_TOKEN }}