Skip to content

Commit dc6cd44

Browse files
committed
build(publish-docs): Add docs github action
1 parent 043d32f commit dc6cd44

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

.github/workflows/publish-docs.yml

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

0 commit comments

Comments
 (0)