Skip to content

Commit 316e064

Browse files
committed
build(publish-docs): Add doc builder gh action
1 parent 4c50f75 commit 316e064

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/publish-docs.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Publish Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [ '3.x' ]
14+
steps:
15+
- uses: actions/checkout@v1
16+
- name: Configure git
17+
run: |
18+
git config --global user.name 'travis-ci'
19+
git config --global user.email 'travis@nowhere.edu'
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v1
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Get full Python version
26+
id: full-python-version
27+
shell: bash
28+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
29+
30+
- name: Install poetry
31+
run: |
32+
curl -O -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
33+
python get-poetry.py -y
34+
echo "::set-env name=PATH::$HOME/.poetry/bin:$PATH"
35+
rm get-poetry.py
36+
37+
- name: Get poetry cache paths from config
38+
run: |
39+
echo ::set-env name=poetry_cache_dir::$(poetry config --list | sed -n 's/.*cache-dir = //p' | sed -e 's/^"//' -e 's/"$//')
40+
echo ::set-env name=poetry_virtualenvs_path::$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^"//' -e 's/"$//')
41+
42+
- name: Configure poetry
43+
shell: bash
44+
run: poetry config virtualenvs.in-project true
45+
46+
- name: Set up cache
47+
uses: actions/cache@v2
48+
id: cache
49+
with:
50+
path: |
51+
.venv
52+
{{ env.poetry_cache_dir }}
53+
{{ env.poetry_virtualenvs_path }}
54+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
55+
56+
- name: Ensure cache is healthy
57+
if: steps.cache.outputs.cache-hit == 'true'
58+
shell: bash
59+
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
60+
61+
- name: Upgrade pip
62+
shell: bash
63+
run: poetry run python -m pip install pip -U
64+
65+
- name: Install dependencies [w/ docs]
66+
run: poetry install --extras "docs lint"
67+
68+
- name: Build documentation
69+
run: |
70+
pushd docs; make SPHINXBUILD='poetry run sphinx-build' html; popd
71+
72+
- name: Push documentation to S3
73+
uses: jakejarvis/s3-sync-action@master
74+
with:
75+
args: --acl public-read --follow-symlinks --delete
76+
env:
77+
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
78+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
79+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
80+
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
81+
SOURCE_DIR: 'docs/_build/html' # optional: defaults to entire repository
82+
83+
- name: Generate list of changed files for CloudFront to invalidate
84+
run: |
85+
pushd docs/_build/html; FILES=$(find . -name \* -print | grep html | cut -c2- | sort | uniq | tr '\n' ' '); popd
86+
for file in $FILES; do
87+
echo $file
88+
# add bare directory to list of updated paths when we see index.html
89+
[[ "$file" == *"/index.html" ]] && echo $file | sed -e 's/\/index.html$/\//'
90+
done | sort | uniq | tr '\n' ' ' > .updated_files
91+
92+
- name: Invalidate on CloudFront
93+
uses: chetan/invalidate-cloudfront-action@master
94+
env:
95+
DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION }}
96+
AWS_REGION: 'us-east-1'
97+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
98+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
99+
PATHS_FROM: .updated_files

0 commit comments

Comments
 (0)