-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
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: 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 ::set-env name=PROJECT_VERSION::$(echo ${GITHUB_REF##*/} | awk '{sub(/^master$/, "latest"); print}') | ||
echo ::set-env name=GH_PAGES_BRANCH::$([ $(git ls-remote --quiet --heads origin gh-pages | wc -l) -ne 0 ] && echo 'gh-pages') | ||
- name: Initialize the gh-pages branch | ||
if: ${{!env.GH_PAGES_BRANCH}} | ||
run: | | ||
echo ::set-env name=GH_PAGES_BRANCH::gh-pages | ||
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 ::set-output name=value::$(git diff-index --cached --quiet HEAD; echo $?) | ||
|
||
- 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 |