-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (136 loc) · 5.15 KB
/
Copy pathpython-quality-checks.yml
File metadata and controls
153 lines (136 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Python Quality Checks
on:
workflow_call:
inputs:
workflow-path:
description: Workflow file used for change detection.
required: false
type: string
working-directory:
description: Relative path under $GITHUB_WORKSPACE where the project is located.
required: false
type: string
type-checks-only-changed-files:
description: Run type check only on changed files
required: false
type: boolean
default: false
default-branch:
description: "Default branch to compute changed files"
required: false
type: string
default: ${{ github.event.repository.default_branch }}
checks:
description: |
List of enabled checks separated by comma
default: type_check,code_style,unit_tests
available checks: type_check,code_style,unit_tests
required: false
type: string
default: "type_check,code_style,unit_tests"
jobs:
pre-checks:
name: Pre-checks
runs-on: ubuntu-latest
outputs:
should-skip: ${{ steps.skip-check.outputs.should_skip }}
steps:
- name: Skip Check
id: skip-check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5
with:
concurrent_skipping: same_content
do_not_skip: >-
[
"push",
"schedule",
"workflow_dispatch"
]
paths: >-
[
".tool-versions",
"${{ inputs.workflow-path }}",
"${{ inputs.working-directory }}/**"
]
skip_after_successful_duplicate: true
setup:
name: Setup
needs: [ pre-checks ]
if: ${{ needs.pre_checks.outputs.should-skip != 'true' }}
runs-on: ubuntu-latest
outputs:
dependencies-manager: ${{ steps.setup-python.outputs.dependencies-manager }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- name: Setup Python
id: setup-python
uses: equisoft-actions/setup-python@v2
unit-tests:
name: Unit tests
if: contains(inputs.checks, 'unit_tests')
needs: [ setup ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- name: Setup Python
uses: equisoft-actions/setup-python@v2
- name: Run pytest
working-directory: ${{ inputs.working-directory }}
run: ${{ needs.setup.outputs.dependencies-manager }} run pytest -v
type-check:
name: Type check
needs: [ setup ]
if: contains(inputs.checks, 'type_check')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 1000
- name: Setup Python
uses: equisoft-actions/setup-python@v2
- name: Run pytype
working-directory: ${{ inputs.working-directory }}
run: |
if [[ "${{ inputs.type-checks-only-changed-files }}" == "true" ]] ; then
git fetch --no-tags --prune --depth=1000 origin
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$CURRENT_BRANCH" == "${{ inputs.default-branch }}" ]] ; then
echo "Running pytype on all files"
${{ needs.setup.outputs.dependencies-manager }} run pytype
else
if [[ -n "${GITHUB_BASE_REF}" ]]; then
DIFF_TARGET="origin/$GITHUB_BASE_REF..."
else
DIFF_TARGET="origin/${{ inputs.default-branch }}..."
fi
# Allow to fail early if DIFF_TARGET not found on repo
git rev-parse $DIFF_TARGET > /dev/null 2>&1 || { echo "Diff target not found '$DIFF_TARGET'. You probably miss a git fetch step." > /dev/stderr; exit 1; }
CHANGED_FILES=$(git diff $DIFF_TARGET --name-only --diff-filter=AM | grep '\.py$' || :)
NUM_CHANGED_FILES=$(echo "$CHANGED_FILES" | grep -v -e '^\s*$' | wc -l || :)
if [[ $NUM_CHANGED_FILES -le 0 ]] ; then
echo "No file changes. Skip"
else
echo "Running pytype on changed files"
echo "$CHANGED_FILES"
${{ needs.setup.outputs.dependencies-manager }} run pytype $CHANGED_FILES
fi
fi
else
${{ needs.setup.outputs.dependencies-manager }} run pytype
fi
code-style:
name: Code style
needs: [ setup ]
runs-on: ubuntu-latest
if: contains(inputs.checks, 'code_style')
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- name: Setup Python
uses: equisoft-actions/setup-python@v2
- name: Run codestyle
working-directory: ${{ inputs.working-directory }}
run: ${{ needs.setup.outputs.dependencies-manager }} run ruff check --select ANN --select E --select F --select I --select N --select PD --select W --ignore ANN101 --ignore ANN102 --ignore ANN401 --ignore PD015 --ignore PD901 --statistics ./