Repository navigation
168 lines (149 loc) · 5.66 KB
/
Copy pathtest.yml
File metadata and controls
168 lines (149 loc) · 5.66 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# Copyright 2026 ABSA Group Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Static analysis & tests"
on:
push:
branches: [ "master" ]
pull_request:
types: [ opened, synchronize, reopened ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
detect:
name: Detect Python Changes
runs-on: ubuntu-latest
outputs:
python_changed: ${{ steps.changes.outputs.python_changed }}
docs_changed: ${{ steps.changes.outputs.docs_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Check whether Python-related files changed
id: changes
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "python_changed=true" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
changed_files=$(gh api \
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
--paginate --jq '.[] | .filename, (.previous_filename // empty)')
else
changed_files=$(git diff --name-only --no-renames "${{ github.sha }}~1" "${{ github.sha }}")
fi
if echo "$changed_files" | grep -E '(\.py$|(^|/)requirements(-dev)?\.txt$|(^|/)pyproject\.toml$|(^|/)tests/fixtures/|[-.]schema\.json$|^Makefile$|^action\.yml$|^\.github/workflows/test\.yml$)' > /dev/null; then
echo "python_changed=true" >> "$GITHUB_OUTPUT"
else
echo "python_changed=false" >> "$GITHUB_OUTPUT"
fi
# A Markdown, `action.yml` or other non-Python file the pages anchor runs the tests job too: tests/docs/
# checks every tracked page, its anchors, examples and option lists against `action.yml`, and the root tests
# read `action.yml`, the shell script and its example configuration. tests/docs/test_ci_filter.py keeps this
# list complete.
if echo "$changed_files" | grep -E '(\.([Mm][Dd]|[Mm][Aa][Rr][Kk][Dd][Oo][Ww][Nn])$|^action\.yml$|\.sh$|\.example$|^\.github/(dependabot\.yml|workflows/[^/]+\.ya?ml)$)' > /dev/null; then
echo "docs_changed=true" >> "$GITHUB_OUTPUT"
else
echo "docs_changed=false" >> "$GITHUB_OUTPUT"
fi
static-checks:
needs: detect
if: needs.detect.outputs.python_changed == 'true'
runs-on: ubuntu-latest
name: ${{ matrix.task.name }} (Python 3.10)
strategy:
fail-fast: false
matrix:
task:
- name: Black Format Check
target: format-check
- name: Ruff and Pylint Analysis
target: lint
- name: Mypy Type Check
target: types
- name: Undeclared Imports (deptry)
target: deptry
- name: No Vendored Schemas
target: no-vendored-schemas
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.10"
cache: 'pip'
cache-dependency-path: |
requirements*.txt
packages/**/pyproject.toml
apps/**/pyproject.toml
- name: Install dependencies
run: make install
- name: Run ${{ matrix.task.name }}
run: make ${{ matrix.task.target }}
tests:
needs: detect
if: needs.detect.outputs.python_changed == 'true' || needs.detect.outputs.docs_changed == 'true'
runs-on: ubuntu-latest
name: Python Tests (Python ${{ matrix.python-version }})
strategy:
fail-fast: false
matrix:
python-version: [ "3.10", "3.11", "3.12", "3.13", "3.14" ]
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
packages/**/pyproject.toml
apps/**/pyproject.toml
- name: Install dependencies
run: make install
- name: Run tests with coverage
run: make coverage
qa-gate:
needs: [ detect, static-checks, tests ]
if: always()
runs-on: ubuntu-latest
name: QA Gate
steps:
- name: Fail if any required job failed or was cancelled
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
echo "::error::a required job failed or was cancelled."
exit 1