|
| 1 | + |
| 2 | +name: Build & update docs |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ 'doc/*', 'docs/*', master, "maint/*" ] |
| 7 | + tags: [ '*' ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + with: |
| 16 | + ssh-key: "${{ secrets.NIPREPS_DEPLOY }}" |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Determine current branch/tag name & set-up git author |
| 20 | + run: | |
| 21 | + if [[ "$GITHUB_REF" == refs/tags/* ]]; then |
| 22 | + CURBRANCH=${GITHUB_REF##*/} |
| 23 | + elif [[ "$GITHUB_REF" == refs/pull/* ]]; then |
| 24 | + CURBRANCH=${GITHUB_REF%/*} |
| 25 | + CURBRANCH=${CURBRANCH##*/} |
| 26 | + elif [[ "$GITHUB_REF" == refs/heads/* ]]; then |
| 27 | + CURBRANCH=${GITHUB_REF##*/} |
| 28 | + fi |
| 29 | +
|
| 30 | + # Remove forward slashes |
| 31 | + CURBRANCH=$( echo $CURBRANCH | sed 's+/+_+g' ) |
| 32 | + echo "Building branch/tag ${CURBRANCH:-<unkwown>}, from git ref <$GITHUB_REF>" |
| 33 | + echo "CURBRANCH=${CURBRANCH}" >> ${GITHUB_ENV} |
| 34 | +
|
| 35 | + # Pacify git if we were to commit something |
| 36 | + git config user.email "[email protected]" |
| 37 | + git config user.name "NiPreps Bot" |
| 38 | + - name: Install GraphViz |
| 39 | + run: | |
| 40 | + sudo apt-get update -y |
| 41 | + sudo apt-get install -y --no-install-recommends graphviz |
| 42 | +
|
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + pip install -r docs/requirements.txt |
| 46 | +
|
| 47 | + - name: Build docs |
| 48 | + run: | |
| 49 | + make -C docs/ SPHINXOPTS="-W" BUILDDIR="$HOME/docs" OUTDIR="${CURBRANCH:-html}" html |
| 50 | +
|
| 51 | + - name: Push created tag to gh-pages |
| 52 | + if: startsWith(github.ref, 'refs/tags/') |
| 53 | + run: | |
| 54 | + MAJOR_MINOR=${CURBRANCH%.*} |
| 55 | + if [[ "${MAJOR_MINOR}" == "" ]]; then |
| 56 | + echo "Could not identify release series" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + git checkout -b gh-pages origin/gh-pages |
| 60 | + git rm -r ${MAJOR_MINOR}/ || true |
| 61 | + # It is fundamental that the directory does not exist at all. |
| 62 | + rm -rf ${MAJOR_MINOR} |
| 63 | + cp -r $HOME/docs/$CURBRANCH $PWD/${MAJOR_MINOR} |
| 64 | + git add ${MAJOR_MINOR} |
| 65 | + 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')" |
| 66 | + git add versions.json |
| 67 | + git commit -m "rel(${CURBRANCH}): Update docs of ${MAJOR_MINOR} series" || true |
| 68 | + git push |
| 69 | +
|
| 70 | + - name: Push "master" docs to gh-pages after a PR is merged |
| 71 | + if: github.ref == 'refs/heads/master' |
| 72 | + run: | |
| 73 | + if [[ "${CURBRANCH}" != "master" ]]; then |
| 74 | + echo "$CURBRANCH is not the default development branch" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + git checkout -b gh-pages origin/gh-pages |
| 78 | + git rm -r master/ || true |
| 79 | + # It is fundamental that the directory does not exist at all. |
| 80 | + rm -rf master |
| 81 | + cp -r $HOME/docs/$CURBRANCH $PWD/master |
| 82 | + git add master |
| 83 | + git commit -am "docs(master): Update docs of development line" || true |
| 84 | + git push |
0 commit comments