Skip to content

Commit 0b3d9fa

Browse files
authored
Merge pull request #428 from tomschr/gh-succeed-if-no-py
GH Action: Don't block when only doc files are modified
2 parents c5c779a + 8ac99bd commit 0b3d9fa

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

.github/workflows/python-testing.yml

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,83 @@
11
---
22
name: Python
33

4+
# HINT: Sync this paths with the egrep in step check_files
45
on:
56
push:
67
branches: [ "master", "main" ]
78
paths:
89
- 'pyproject.toml'
10+
- 'setup.cfg'
911
- '**.py'
10-
- '.github/workflows/python-testing.yml'
12+
- '.github/workflows/*.yml'
1113

1214
pull_request:
1315
branches: [ "master", "main" ]
1416
paths:
1517
- 'pyproject.toml'
18+
- 'setup.cfg'
1619
- '**.py'
17-
- '.github/workflows/python-testing.yml'
20+
- '.github/workflows/*.yml'
1821

1922
permissions:
2023
contents: read
2124

2225
concurrency:
2326
# only cancel in-progress runs of the same workflow
2427
group: ${{ github.workflow }}-${{ github.ref }}
25-
# ${{ github.head_ref || github.run_id }}
2628
cancel-in-progress: true
2729

2830

2931
jobs:
32+
check-files:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
can_run: ${{ steps.check_files.outputs.can_run }}
36+
37+
steps:
38+
- uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 0
41+
42+
- name: GitHub variables
43+
id: gh-vars
44+
run: |
45+
for var in GITHUB_WORKFLOW GITHUB_ACTION GITHUB_ACTIONS GITHUB_REPOSITORY GITHUB_EVEN_NAME GITHUB_EVENT_PATH GITHUB_WORKSPACE GITHUB_SHA GITHUB_REF GITHUB_HEAD_REF GITHUB_BASE_REF; do
46+
echo "$var = ${!var}"
47+
done
48+
49+
- name: Check for file changes
50+
id: check_files
51+
run: |
52+
# ${{ github.event.after }} ${{ github.event.before }}
53+
can_run=$(git diff --name-only HEAD~1 HEAD | \
54+
egrep -q '.github/workflows/|pyproject.toml|setup.cfg|\.py$' && echo 1 || echo 0)
55+
echo "can_run=$can_run"
56+
echo "can_run=$can_run" >> $GITHUB_OUTPUT
57+
58+
skip_test:
59+
runs-on: ubuntu-latest
60+
needs: check-files
61+
timeout-minutes: 2
62+
if: ${{ needs.check-files.outputs.can_run == '0' }}
63+
64+
steps:
65+
- name: Skip test
66+
run: |
67+
echo "Nothing to do as no TOML, Python, or YAML file has been changed.
68+
"
69+
echo "Skipping."
70+
3071
check:
3172
runs-on: ubuntu-latest
73+
needs: check-files
3274
# Timout of 15min
3375
timeout-minutes: 15
76+
# needs.check-files.outputs.can_run
77+
if: ${{ needs.check-files.outputs.can_run == '1' }}
3478

3579
steps:
3680
- uses: actions/checkout@v3
37-
- name: Output env variables
38-
run: |
39-
echo "Default branch=${default-branch}"
40-
echo "GITHUB_WORKFLOW=${GITHUB_WORKFLOW}"
41-
echo "GITHUB_ACTION=$GITHUB_ACTION"
42-
echo "GITHUB_ACTIONS=$GITHUB_ACTIONS"
43-
echo "GITHUB_ACTOR=$GITHUB_ACTOR"
44-
echo "GITHUB_REPOSITORY=$GITHUB_REPOSITORY"
45-
echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME"
46-
echo "GITHUB_EVENT_PATH=$GITHUB_EVENT_PATH"
47-
echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
48-
echo "GITHUB_SHA=$GITHUB_SHA"
49-
echo "GITHUB_REF=$GITHUB_REF"
50-
echo "GITHUB_HEAD_REF=$GITHUB_HEAD_REF"
51-
echo "GITHUB_BASE_REF=$GITHUB_BASE_REF"
52-
echo "::debug::---Start content of file $GITHUB_EVENT_PATH"
53-
cat $GITHUB_EVENT_PATH
54-
echo "\n"
55-
echo "::debug::---end"
5681
- name: Set up Python ${{ matrix.python-version }}
5782
uses: actions/setup-python@v4
5883
with:

0 commit comments

Comments
 (0)