|
| 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.10' ] |
| 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 '[email protected]' |
| 21 | +
|
| 22 | + - name: Filter changed file paths to outputs |
| 23 | + |
| 24 | + id: changes |
| 25 | + with: |
| 26 | + filters: | |
| 27 | + root_docs: |
| 28 | + - CHANGES |
| 29 | + - README.* |
| 30 | + docs: |
| 31 | + - 'docs/**/*.rst' |
| 32 | + - 'docs/**/*.md' |
| 33 | + - 'examples/**' |
| 34 | + python_files: |
| 35 | + - 'tmuxp/**' |
| 36 | +
|
| 37 | + - name: Should publish |
| 38 | + if: steps.changes.outputs.docs == 'true' || steps.changes.outputs.root_docs == 'true' || steps.changes.outputs.python_files == 'true' |
| 39 | + run: echo "PUBLISH=$(echo true)" >> $GITHUB_ENV |
| 40 | + |
| 41 | + - name: Set up Python ${{ matrix.python-version }} |
| 42 | + uses: actions/setup-python@v1 |
| 43 | + with: |
| 44 | + python-version: ${{ matrix.python-version }} |
| 45 | + |
| 46 | + - name: Get full Python version |
| 47 | + id: full-python-version |
| 48 | + if: env.PUBLISH == 'true' |
| 49 | + shell: bash |
| 50 | + run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") |
| 51 | + |
| 52 | + - name: Install poetry |
| 53 | + if: env.PUBLISH == 'true' |
| 54 | + run: | |
| 55 | + curl -O -sSL https://install.python-poetry.org/install-poetry.py |
| 56 | + python install-poetry.py -y --version 1.1.12 |
| 57 | + echo "PATH=${HOME}/.poetry/bin:${PATH}" >> $GITHUB_ENV |
| 58 | + rm install-poetry.py |
| 59 | +
|
| 60 | + - name: Add ~/.local/bin to PATH |
| 61 | + run: echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 62 | + |
| 63 | + - name: Get poetry cache paths from config |
| 64 | + if: env.PUBLISH == 'true' |
| 65 | + run: | |
| 66 | + echo "poetry_cache_dir=$(poetry config --list | sed -n 's/.*cache-dir = //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV |
| 67 | + echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV |
| 68 | +
|
| 69 | + - name: Configure poetry |
| 70 | + if: env.PUBLISH == 'true' |
| 71 | + shell: bash |
| 72 | + run: poetry config virtualenvs.in-project true |
| 73 | + |
| 74 | + - name: Set up cache |
| 75 | + uses: actions/cache@v2 |
| 76 | + id: cache |
| 77 | + with: |
| 78 | + path: | |
| 79 | + .venv |
| 80 | + {{ env.poetry_cache_dir }} |
| 81 | + {{ env.poetry_virtualenvs_path }} |
| 82 | + key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} |
| 83 | + |
| 84 | + - name: Ensure cache is healthy |
| 85 | + if: steps.cache.outputs.cache-hit == 'true' && env.PUBLISH == 'true' |
| 86 | + shell: bash |
| 87 | + run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv |
| 88 | + |
| 89 | + - name: Upgrade pip |
| 90 | + shell: bash |
| 91 | + if: env.PUBLISH == 'true' |
| 92 | + run: poetry run python -m pip install pip -U |
| 93 | + |
| 94 | + - name: Install dependencies [w/ docs] |
| 95 | + if: env.PUBLISH == 'true' |
| 96 | + run: poetry install --extras "docs lint" |
| 97 | + |
| 98 | + - name: Build documentation |
| 99 | + if: env.PUBLISH == 'true' |
| 100 | + run: | |
| 101 | + pushd docs; make SPHINXBUILD='poetry run sphinx-build' html; popd |
| 102 | +
|
| 103 | + - name: Push documentation to S3 |
| 104 | + if: env.PUBLISH == 'true' |
| 105 | + uses: jakejarvis/s3-sync-action@master |
| 106 | + with: |
| 107 | + args: --acl public-read --follow-symlinks --delete |
| 108 | + env: |
| 109 | + AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} |
| 110 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 111 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 112 | + AWS_REGION: 'us-west-1' # optional: defaults to us-east-1 |
| 113 | + SOURCE_DIR: 'docs/_build/html' # optional: defaults to entire repository |
| 114 | + |
| 115 | + - name: Generate list of changed files for CloudFront to invalidate |
| 116 | + if: env.PUBLISH == 'true' |
| 117 | + run: | |
| 118 | + pushd docs/_build/html; FILES=$(find . -name \* -print | grep html | cut -c2- | sort | uniq | tr '\n' ' '); popd |
| 119 | + for file in $FILES; do |
| 120 | + echo $file |
| 121 | + # add bare directory to list of updated paths when we see index.html |
| 122 | + [[ "$file" == *"/index.html" ]] && echo $file | sed -e 's/\/index.html$/\//' |
| 123 | + done | sort | uniq | tr '\n' ' ' > .updated_files |
| 124 | +
|
| 125 | + - name: Invalidate on CloudFront |
| 126 | + uses: chetan/invalidate-cloudfront-action@master |
| 127 | + if: env.PUBLISH == 'true' |
| 128 | + env: |
| 129 | + DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION }} |
| 130 | + AWS_REGION: 'us-east-1' |
| 131 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 132 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 133 | + PATHS_FROM: .updated_files |
0 commit comments