-
Notifications
You must be signed in to change notification settings - Fork 35
130 lines (109 loc) · 4.27 KB
/
gh-ci.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
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
name: mda_gh_ci
on:
push:
branches:
- develop
tags:
- "release-*"
pull_request:
branches:
- develop
schedule:
# 3 am Tuesdays and Fridays
- cron: "0 3 * * 2,5"
concurrency:
# Probably overly cautious group naming.
# Commits to develop will cancel each other, but PRs will only cancel
# commits within the same PR
group: "${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}"
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
env:
SPHINX_DIR: "doc/"
HTML_DIR: "doc/build/html"
jobs:
build_docs:
runs-on: ubuntu-latest
env:
CYTHON_TRACE_NOGIL: 1
MPLBACKEND: agg
steps:
- uses: actions/checkout@v3
- name: Get current date
id: date
run: echo "date=$(date +%Y-%m-%d)" >> "${GITHUB_OUTPUT}"
- name: setup micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
environment-name: mda-user-guide
cache-environment: true
cache-downloads: true
cache-environment-key: environment-${{ steps.date.outputs.date }}
cache-downloads-key: downloads-${{ steps.date.outputs.date }}
- name: install_deps
run: |
jupyter-nbextension enable nglview --py --sys-prefix
- name: install_released_mda
# If it's a release, pick up the latest version of MDAnalysis/Tests and deploy that
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/release'))
run: python -m pip install MDAnalysis MDAnalysisTests -U --force-reinstall
- name: build_docs
run: |
make -C ${SPHINX_DIR} html
- name: deploy_docs
if: github.event_name != 'pull_request'
env:
GH_USER: github-actions
GH_EMAIL: "[email protected]"
GH_REPOSITORY: "github.com/${{ github.repository }}.git"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
URL: https://userguide.mdanalysis.org
run: |
# set up environment variables
# cannot execute bash to make variables in env section
# export URL for the Python script $UPDATE_JSON
export URL
export VERSION=$(python -c "import MDAnalysis; print(MDAnalysis.__version__)")
UPDATE_JSON=$(pwd)/maintainer/update_json_stubs_sitemap.py
BRANCH="${GITHUB_REF#refs/heads/}"
# the below turns off non-blocking as it causes large writes to stdout to fail
# (see https://github.com/travis-ci/travis-ci/issues/4704)
# commented out as this is not a problem with gh-actions
# python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
cd ${{ env.HTML_DIR }}
# move docs into version subfolder
mkdir ../${VERSION} && mv * ../${VERSION} && mv ../${VERSION} $VERSION
# set up git
REV=$(git rev-parse --short HEAD)
git init
git config user.name $GH_USER
git config user.email $GH_EMAIL
git remote add upstream "https://${GH_USER}:${GH_TOKEN}@${GH_REPOSITORY}"
git fetch --depth 50 upstream $BRANCH gh-pages
git reset upstream/gh-pages
# redirects and copies
mkdir latest
python $UPDATE_JSON
touch .
touch .nojekyll
git add -A ${VERSION}/
git add .nojekyll versions.json *.xml *.html index.html latest
for dirname in dev stable ; do
if [ -d $dirname ]; then git add $dirname; fi
done
# add redirect html files if they're generated
if [ "$(ls *.html | wc -l)" -ge "1" ]; then
# get list of directories and files present in the latest version
cd $VERSION && mdfiles=$(ls -d *) && cd -
for item in $mdfiles ; do
# if the directory/file exists in top level, add it
if [[ -f $item ]] || [[ -d $item ]]; then git add $item; fi
done
fi
# check for anything to commit
# https://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
git diff-index --quiet HEAD -- || git commit -m "rebuilt html docs for version ${VERSION} from branch ${BRANCH} with sphinx at ${REV}"
git push -q upstream HEAD:gh-pages