Skip to content

ci(publish-docs): Only publish if docs changed #662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,49 @@ 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:
python-version: ${{ matrix.python-version }}

- 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
echo "PATH=$HOME/.poetry/bin:$PATH" >> $GITHUB_ENV
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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand Down