1- # From: https://github.com/coderefinery/sphinx-lesson/blob/master/.github/workflows/sphinx.yml
2-
31name : docs
4- on : [push, pull_request]
52
6- env :
7- DEFAULT_BRANCH : " main "
8- # SPHINXOPTS: "-W --keep-going -T"
9- # ^-- If these SPHINXOPTS are enabled, then be strict about the builds and fail on any warnings
3+ on :
4+ push :
5+ branches :
6+ - main
107
118jobs :
12- build-and-deploy :
13- name : Build and gh-pages
9+ build :
10+
1411 runs-on : ubuntu-latest
15- steps :
16- # https://github.com/marketplace/actions/checkout
17- - uses : actions/checkout@v2
18- with :
19- fetch-depth : 0
20- lfs : true
21- # https://github.com/marketplace/actions/setup-python
22- # ^-- This gives info on matrix testing.
23- - name : Install Python
24- uses : actions/setup-python@v2
25- with :
26- python-version : 3.8
27- # https://docs.github.com/en/actions/guides/building-and-testing-python#caching-dependencies
28- # ^-- How to set up caching for pip on Ubuntu
29- - name : Cache pip
30- uses : actions/cache@v2
31- with :
32- path : ~/.cache/pip
33- key : ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
34- restore-keys : |
35- ${{ runner.os }}-pip-
36- ${{ runner.os }}-
37- # https://docs.github.com/en/actions/guides/building-and-testing-python#installing-dependencies
38- # ^-- This gives info on installing dependencies with pip
39- - name : Install dependencies
40- run : |
41- python -m pip install --upgrade pip
42- pip install -r requirements-docs.txt
43- - name : Debugging information
44- run : |
45- echo "github.ref:" ${{github.ref}}
46- echo "github.event_name:" ${{github.event_name}}
47- echo "github.head_ref:" ${{github.head_ref}}
48- echo "github.base_ref:" ${{github.base_ref}}
49- set -x
50- git rev-parse --abbrev-ref HEAD
51- git branch
52- git branch -a
53- git remote -v
54- python -V
55- pip list --not-required
56- pip list
57- # Build
58- - uses : ammaraskar/sphinx-problem-matcher@master
59- - name : Build Sphinx docs
60- run : |
61- make dirhtml
62- # This fixes broken copy button icons, as explained in
63- # https://github.com/coderefinery/sphinx-lesson/issues/50
64- # https://github.com/executablebooks/sphinx-copybutton/issues/110
65- # This can be removed once these PRs are accepted (but the
66- # fixes also need to propagate to other themes):
67- # https://github.com/sphinx-doc/sphinx/pull/8524
68- # https://github.com/readthedocs/sphinx_rtd_theme/pull/1025
69- sed -i 's/url_root="#"/url_root=""/' _build/dirhtml/index.html || true
70- # The following supports building all branches and combining on
71- # gh-pages
7212
73- # Clone and set up the old gh-pages branch
74- - name : Clone old gh-pages
75- if : ${{ github.event_name == 'push' }}
76- run : |
77- set -x
78- git fetch
79- ( git branch gh-pages remotes/origin/gh-pages && git clone . --branch=gh-pages _gh-pages/ ) || mkdir _gh-pages
80- rm -rf _gh-pages/.git/
81- mkdir -p _gh-pages/branch/
82- # If a push and default branch, copy build to _gh-pages/ as the "main"
83- # deployment.
84- - name : Copy new build (default branch)
85- if : |
86- contains(github.event_name, 'push') &&
87- contains(github.ref, env.DEFAULT_BRANCH)
88- run : |
89- set -x
90- # Delete everything under _gh-pages/ that is from the
91- # primary branch deployment. Eicludes the other branches
92- # _gh-pages/branch-* paths, and not including
93- # _gh-pages itself.
94- find _gh-pages/ -mindepth 1 ! -path '_gh-pages/branch*' -delete
95- rsync -a _build/dirhtml/ _gh-pages/
96- # If a push and not on default branch, then copy the build to
97- # _gh-pages/branch/$brname (transforming '/' into '--')
98- - name : Copy new build (branch)
99- if : |
100- contains(github.event_name, 'push') &&
101- !contains(github.ref, env.DEFAULT_BRANCH)
102- run : |
103- set -x
104- #brname=$(git rev-parse --abbrev-ref HEAD)
105- brname="${{github.ref}}"
106- brname="${brname##refs/heads/}"
107- brdir=${brname//\//--} # replace '/' with '--'
108- rm -rf _gh-pages/branch/${brdir}
109- rsync -a _build/dirhtml/ _gh-pages/branch/${brdir}
110- # Go through each branch in _gh-pages/branch/, if it's not a
111- # ref, then delete it.
112- - name : Delete old feature branches
113- if : ${{ github.event_name == 'push' }}
114- run : |
115- set -x
116- for brdir in `ls _gh-pages/branch/` ; do
117- brname=${brdir//--/\/} # replace '--' with '/'
118- if ! git show-ref remotes/origin/$brname ; then
119- echo "Removing $brdir"
120- rm -r _gh-pages/branch/$brdir/
121- fi
122- done
123- # Add the .nojekyll file
124- - name : nojekyll
125- if : ${{ github.event_name == 'push' }}
126- run : |
127- touch _gh-pages/.nojekyll
128- # Deploy
129- # https://github.com/peaceiris/actions-gh-pages
130- - name : Deploy
131- uses : peaceiris/actions-gh-pages@v3
132- if : ${{ github.event_name == 'push' }}
133- # if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/$defaultBranch' }}
134- with :
135- publish_branch : gh-pages
136- github_token : ${{ secrets.GITHUB_TOKEN }}
137- publish_dir : _gh-pages/
138- force_orphan : true
13+ steps :
14+ - uses : actions/checkout@v1
15+ # Standard drop-in approach that should work for most people.
16+ - uses : ammaraskar/sphinx-action@master
17+ with :
18+ docs-folder : " docs/"
19+ # ===============================
20+ - name : Commit documentation changes
21+ run : |
22+ git clone https://github.com/ammaraskar/sphinx-action-test.git --branch gh-pages --single-branch gh-pages
23+ cp -r docs/build/html/* gh-pages/
24+ cd gh-pages
25+ touch .nojekyll
26+ git config --local user.email "action@github.com"
27+ git config --local user.name "GitHub Action"
28+ git add .
29+ git commit -m "Update documentation" -a || true
30+ # The above command will fail if no changes were present, so we ignore
31+ # that.
32+ - name : Push changes
33+ uses : ad-m/github-push-action@master
34+ with :
35+ branch : gh-pages
36+ directory : gh-pages
37+ github_token : ${{ secrets.GITHUB_TOKEN }}
38+ # ===============================
0 commit comments