From df694ce3b417501a70109ac7eaa99232c72210bb Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 30 Jan 2021 12:50:24 -0600 Subject: [PATCH] ci(publish-docs): Only publish if docs changed --- .github/workflows/publish-docs.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index ece6167d9cd..736325455b7 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -17,6 +17,22 @@ jobs: run: | git config --global user.name 'travis-ci' git config --global user.email 'travis@nowhere.edu' + - name: Filter changed file paths to outputs + uses: dorny/paths-filter@v2.7.0 + id: changes + with: + filters: | + root_docs: + - CHANGES + - README.* + docs: + - 'docs/**/*.rst' + - 'docs/**/*.md' + python_files: + - 'tmuxp/**' + - name: Should publish + if: steps.changes.outputs.docs == 'true' || steps.changes.outputs.root_docs == 'true' || steps.changes.outputs.python_files == 'true' + run: echo "PUBLISH=$(echo true)" >> $GITHUB_ENV - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v1 with: @@ -24,10 +40,12 @@ jobs: - name: Get full Python version id: full-python-version + if: env.PUBLISH == 'true' shell: bash run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") - name: Install poetry + if: env.PUBLISH == 'true' run: | curl -O -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py python get-poetry.py -y --version 1.0.10 @@ -35,11 +53,13 @@ jobs: rm get-poetry.py - name: Get poetry cache paths from config + if: env.PUBLISH == 'true' run: | echo "poetry_cache_dir=$(poetry config --list | sed -n 's/.*cache-dir = //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV - name: Configure poetry + if: env.PUBLISH == 'true' shell: bash run: poetry config virtualenvs.in-project true @@ -54,22 +74,26 @@ jobs: key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} - name: Ensure cache is healthy - if: steps.cache.outputs.cache-hit == 'true' + if: steps.cache.outputs.cache-hit == 'true' && env.PUBLISH == 'true' shell: bash run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv - name: Upgrade pip shell: bash + if: env.PUBLISH == 'true' run: poetry run python -m pip install pip -U - name: Install dependencies [w/ docs] + if: env.PUBLISH == 'true' run: poetry install --extras "docs lint" - name: Build documentation + if: env.PUBLISH == 'true' run: | pushd docs; make SPHINXBUILD='poetry run sphinx-build' html; popd - name: Push documentation to S3 + if: env.PUBLISH == 'true' uses: jakejarvis/s3-sync-action@master with: args: --acl public-read --follow-symlinks --delete @@ -81,6 +105,7 @@ jobs: SOURCE_DIR: 'docs/_build/html' # optional: defaults to entire repository - name: Generate list of changed files for CloudFront to invalidate + if: env.PUBLISH == 'true' run: | pushd docs/_build/html; FILES=$(find . -name \* -print | grep html | cut -c2- | sort | uniq | tr '\n' ' '); popd for file in $FILES; do @@ -91,6 +116,7 @@ jobs: - name: Invalidate on CloudFront uses: chetan/invalidate-cloudfront-action@master + if: env.PUBLISH == 'true' env: DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION }} AWS_REGION: 'us-east-1'