Merge pull request #920 from nipreps/dependabot/github_actions/astral… #347
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/*', master, "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:-<unknown>}, from git ref <$GITHUB_REF>" | |
echo "CURBRANCH=${CURBRANCH}" >> ${GITHUB_ENV} | |
# Pacify git if we were to commit something | |
git config user.email "nipreps@gmail.com" | |
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 -r docs/requirements.txt | |
- 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 PR is merged | |
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 |