-
Notifications
You must be signed in to change notification settings - Fork 27
95 lines (82 loc) · 3.27 KB
/
docs-build-update.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Build & update docs
on:
push:
branches: [ 'doc/*', 'docs/*', master, "maint/*" ]
tags: [ '*' ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ssh-key: "${{ secrets.NIPREPS_DEPLOY }}"
fetch-depth: 0
- name: Determine current branch/tag name & set-up git author
run: |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
CURBRANCH=${GITHUB_REF##*/}
elif [[ "$GITHUB_REF" == refs/pull/* ]]; then
CURBRANCH=${GITHUB_REF%/*}
CURBRANCH=${CURBRANCH##*/}
elif [[ "$GITHUB_REF" == refs/heads/* ]]; then
CURBRANCH=${GITHUB_REF##*/}
fi
# Remove forward slashes
CURBRANCH=$( echo $CURBRANCH | sed 's+/+_+g' )
echo "Building branch/tag ${CURBRANCH:-<unkwown>}, from git ref <$GITHUB_REF>"
echo "CURBRANCH=${CURBRANCH}" >> ${GITHUB_ENV}
# Pacify git if we were to commit something
git config user.email "[email protected]"
git config user.name "NiPreps Bot"
- name: Install GraphViz & pandoc
run: |
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends graphviz pandoc
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: 3
- name: Install dependencies
run: |
python -m pip install -U build hatch hatchling pip docutils
python -m pip install -r docs/requirements.txt
python -m hatch version | tail -n1 | xargs
- name: Build docs
run: |
make -C docs/ SPHINXOPTS="-W" BUILDDIR="$HOME/docs" OUTDIR="${CURBRANCH:-html}" html
- name: Push created tag to gh-pages
if: startsWith(github.ref, 'refs/tags/')
run: |
MAJOR_MINOR=${CURBRANCH%.*}
if [[ "${MAJOR_MINOR}" == "" ]]; then
echo "Could not identify release series"
exit 1
fi
git checkout -b gh-pages origin/gh-pages
git rm -r ${MAJOR_MINOR}/ || true
# It is fundamental that the directory does not exist at all.
rm -rf ${MAJOR_MINOR}
cp -r $HOME/docs/$CURBRANCH $PWD/${MAJOR_MINOR}
git add ${MAJOR_MINOR}
python -c "from pathlib import Path; import json; f=Path('versions.json'); d=json.loads(f.read_text()); d['tags'].append(\"${MAJOR_MINOR}\"); d['tags'] = list(sorted(set(d['tags']))); f.write_text(json.dumps(d, indent=4)); print('Updated versions.json')"
git add versions.json
git commit -m "rel(${CURBRANCH}): Update docs of ${MAJOR_MINOR} series" || true
git push
- name: Push "master" docs to gh-pages after a push to master (typically, a PR merge).
if: github.ref == 'refs/heads/master'
run: |
if [[ "${CURBRANCH}" != "master" ]]; then
echo "$CURBRANCH is not the default development branch"
exit 1
fi
git checkout -b gh-pages origin/gh-pages
git rm -r master/ || true
# It is fundamental that the directory does not exist at all.
rm -rf master
cp -r $HOME/docs/$CURBRANCH $PWD/master
git add master
git commit -am "docs(master): Update docs of development line" || true
git push