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