Skip to content

Update documentation.yml #5

Update documentation.yml

Update documentation.yml #5

Workflow file for this run

name: docs
on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Config the local git repository
run: |
git config --local user.email "[email protected]"
git config --local user.name "Zentetsu"
- name: Set up Python
uses: actions/setup-python@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[docs]
# [ -f docs/requirements.txt ] && pip install -r docs/requirements.txt || pip install sphinx sphinx-rtd-theme
- name: Set environment variable
run: |
echo "PROJECT_VERSION=$(echo ${GITHUB_REF##*/} | awk '{sub(/^master$/, "latest"); print}')" >> $GITHUB_ENV
echo "GH_PAGES_BRANCH=$([ $(git ls-remote --quiet --heads origin gh-pages | wc -l) -ne 0 ] && echo 'gh-pages')" >> $GITHUB_ENV
- name: Initialize the gh-pages branch
if: ${{ !env.GH_PAGES_BRANCH }}
run: |
echo "GH_PAGES_BRANCH=gh-pages" >> $GITHUB_ENV
git checkout --orphan gh-pages
git rm -rf .
touch .nojekyll
echo "latest" > all_versions.txt
echo '<!DOCTYPE html>' > index.html
echo '<html>' >> index.html
echo ' <head>' >> index.html
echo ' <meta charset="utf-8">' >> index.html
echo ' <title>Redirecting to latest</title>' >> index.html
echo ' <meta http-equiv="refresh" content="0; URL=latest/index.html">' >> index.html
echo ' <link rel="canonical" href="latest/index.html">' >> index.html
echo ' </head>' >> index.html
echo '</html>' >> index.html
git add .nojekyll all_versions.txt index.html
git commit -m "Initial gh-pages commit"
git push "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" $GH_PAGES_BRANCH
git checkout ${GITHUB_REF##*/}
- name: Generate the documentation
run: |
cd docs
make html
cd ..
- name: Move the html files on gh-pages branches
run: |
git clean -df
git checkout $GH_PAGES_BRANCH
rm -rf $PROJECT_VERSION
mv docs/_build/html $PROJECT_VERSION
git add $PROJECT_VERSION
- name: Change the symlink of the stable release if necessary
if: startsWith(github.ref, 'refs/tags/v')
run: |
rm -f stable
ln -s $PROJECT_VERSION stable
git add stable
- name: Update the all_versions.txt file
if: startsWith(github.ref, 'refs/tags/v')
run: |
awk -v version=$PROJECT_VERSION 'NR==1 {print; print version}; NR!=1' all_versions.txt > ${{ runner.temp }}/tmp.txt
mv ${{ runner.temp }}/tmp.txt all_versions.txt
git add all_versions.txt
- name: Set the git status
id: git_status
run: echo "value=$(git diff-index --cached --quiet HEAD; echo $?)" >> $GITHUB_OUTPUT
- name: Commit and push changes
if: steps.git_status.outputs.value != '0'
run: |
git commit -m "$PROJECT_VERSION doc build"
git push "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" $GH_PAGES_BRANCH