This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
Merge pull request #154 from esavary/style-correction #93
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & update docs | |
on: | |
push: | |
branches: [ 'doc/*', 'docs/*', main, "maint/*" ] | |
tags: [ '*' ] | |
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 | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y --no-install-recommends graphviz | |
- name: Install dependencies | |
run: | | |
pip install -U build hatch pip | |
pip install .[doc] | |
python -m hatch version | tail -n1 | |
- name: Build docs | |
run: | | |
python -m hatch build --hooks-only | |
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 |