Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Merge pull request #131 from jhlegarreta/AddRefsToREADME #77

Merge pull request #131 from jhlegarreta/AddRefsToREADME

Merge pull request #131 from jhlegarreta/AddRefsToREADME #77

name: Build & update docs
on:
push:
branches: [ 'doc/*', 'docs/*', main, "maint/*" ]
tags: [ '*' ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
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
run: |
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends graphviz
- name: Install dependencies
run: |
pip install --no-cache-dir "setuptools >= 45.0" "setuptools_scm[toml] >= 6.2"
pip install -r docs/requirements.txt
- name: Build docs
run: |
python -m setuptools_scm # Generate _version.py file
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 "main" docs to gh-pages after a push to main (typically, a PR merge).
if: github.ref == 'refs/heads/main'
run: |
if [[ "${CURBRANCH}" != "main" ]]; then
echo "$CURBRANCH is not the default development branch"
exit 1
fi
git checkout -b gh-pages origin/gh-pages
git rm -r main/ || true
# It is fundamental that the directory does not exist at all.
rm -rf main
cp -r $HOME/docs/$CURBRANCH $PWD/main
git add main
git commit -am "docs(main): Update docs of development line" || true
git push