Skip to content

Commit b5b165a

Browse files
authored
ci(publish-docs): Only publish if docs changed (#662)
1 parent 37568de commit b5b165a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

.github/workflows/publish-docs.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,49 @@ jobs:
1717
run: |
1818
git config --global user.name 'travis-ci'
1919
git config --global user.email 'travis@nowhere.edu'
20+
- name: Filter changed file paths to outputs
21+
uses: dorny/paths-filter@v2.7.0
22+
id: changes
23+
with:
24+
filters: |
25+
root_docs:
26+
- CHANGES
27+
- README.*
28+
docs:
29+
- 'docs/**/*.rst'
30+
- 'docs/**/*.md'
31+
python_files:
32+
- 'tmuxp/**'
33+
- name: Should publish
34+
if: steps.changes.outputs.docs == 'true' || steps.changes.outputs.root_docs == 'true' || steps.changes.outputs.python_files == 'true'
35+
run: echo "PUBLISH=$(echo true)" >> $GITHUB_ENV
2036
- name: Set up Python ${{ matrix.python-version }}
2137
uses: actions/setup-python@v1
2238
with:
2339
python-version: ${{ matrix.python-version }}
2440

2541
- name: Get full Python version
2642
id: full-python-version
43+
if: env.PUBLISH == 'true'
2744
shell: bash
2845
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
2946

3047
- name: Install poetry
48+
if: env.PUBLISH == 'true'
3149
run: |
3250
curl -O -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
3351
python get-poetry.py -y --version 1.0.10
3452
echo "PATH=$HOME/.poetry/bin:$PATH" >> $GITHUB_ENV
3553
rm get-poetry.py
3654
3755
- name: Get poetry cache paths from config
56+
if: env.PUBLISH == 'true'
3857
run: |
3958
echo "poetry_cache_dir=$(poetry config --list | sed -n 's/.*cache-dir = //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
4059
echo "poetry_virtualenvs_path=$(poetry config --list | sed -n 's/.*virtualenvs.path = .* # //p' | sed -e 's/^\"//' -e 's/\"$//')" >> $GITHUB_ENV
4160
4261
- name: Configure poetry
62+
if: env.PUBLISH == 'true'
4363
shell: bash
4464
run: poetry config virtualenvs.in-project true
4565

@@ -54,22 +74,26 @@ jobs:
5474
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
5575

5676
- name: Ensure cache is healthy
57-
if: steps.cache.outputs.cache-hit == 'true'
77+
if: steps.cache.outputs.cache-hit == 'true' && env.PUBLISH == 'true'
5878
shell: bash
5979
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
6080

6181
- name: Upgrade pip
6282
shell: bash
83+
if: env.PUBLISH == 'true'
6384
run: poetry run python -m pip install pip -U
6485

6586
- name: Install dependencies [w/ docs]
87+
if: env.PUBLISH == 'true'
6688
run: poetry install --extras "docs lint"
6789

6890
- name: Build documentation
91+
if: env.PUBLISH == 'true'
6992
run: |
7093
pushd docs; make SPHINXBUILD='poetry run sphinx-build' html; popd
7194
7295
- name: Push documentation to S3
96+
if: env.PUBLISH == 'true'
7397
uses: jakejarvis/s3-sync-action@master
7498
with:
7599
args: --acl public-read --follow-symlinks --delete
@@ -81,6 +105,7 @@ jobs:
81105
SOURCE_DIR: 'docs/_build/html' # optional: defaults to entire repository
82106

83107
- name: Generate list of changed files for CloudFront to invalidate
108+
if: env.PUBLISH == 'true'
84109
run: |
85110
pushd docs/_build/html; FILES=$(find . -name \* -print | grep html | cut -c2- | sort | uniq | tr '\n' ' '); popd
86111
for file in $FILES; do
@@ -91,6 +116,7 @@ jobs:
91116
92117
- name: Invalidate on CloudFront
93118
uses: chetan/invalidate-cloudfront-action@master
119+
if: env.PUBLISH == 'true'
94120
env:
95121
DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION }}
96122
AWS_REGION: 'us-east-1'

0 commit comments

Comments
 (0)