-
Notifications
You must be signed in to change notification settings - Fork 14
153 lines (136 loc) · 4.75 KB
/
python-check.yaml
File metadata and controls
153 lines (136 loc) · 4.75 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 Check
run-name: "${{ github.actor }} checking Python code"
permissions:
contents: read
pull-requests: read
on:
pull_request:
branches: [ main, develop ]
workflow_dispatch:
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
skip-relevance-check:
description: "Bypass relevance check"
required: false
type: boolean
default: false
pr-base-sha:
description: "Base SHA of the PR for relevance check"
required: false
type: string
pr-head-sha:
description: "Head SHA of the PR for relevance check"
required: false
type: string
env:
local_checkout_path: ${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src', github.event.repository.name) }}
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.detect_act.outputs.is_act }}
steps:
- name: Detect act environment
id: detect_act
uses: Framework-R-D/phlex/.github/actions/detect-act-env@main
detect-changes:
needs: pre-check
if: >
github.event_name != 'workflow_dispatch' &&
(github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') &&
needs.pre-check.outputs.is_act != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 0
path: ${{ env.local_checkout_path }}
- name: Detect Python changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
with:
repo-path: ${{ env.local_checkout_path }}
base-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-base-sha) || github.event.pull_request.base.sha || github.event.before }}
head-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-head-sha) || github.event.pull_request.head.sha || github.sha }}
file-type: python
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No python check relevant changes detected; job will be skipped."
else
echo "::group::Python check relevant files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
python-check:
needs: [pre-check, detect-changes]
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_call' && inputs.skip-relevance-check == 'true') ||
needs.pre-check.outputs.is_act == 'true' ||
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
path: ${{ env.local_checkout_path }}
- name: Set up Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
pip install ruff mypy
- name: Run ruff and mypy checks
working-directory: ${{ env.local_checkout_path }}
env:
FORCE_COLOR: 1 # `ruff`/`colored` crate
run: |
failed=0
echo "➡️ Checking Python code with ruff..."
echo "::group::Running ruff check"
if ! ruff check; then
failed=1
echo "::endgroup::"
echo "::error:: Ruff check failed."
else
echo "::endgroup::"
echo "✅ Ruff check passed."
fi
echo "➡️ Checking Python code with mypy..."
echo "::group::Running mypy"
if ! mypy --color-output .; then
failed=1
echo "::endgroup::"
echo "::error:: MyPy check failed."
else
echo "::endgroup::"
echo "✅ MyPy check passed."
fi
exit $failed
python-check-skipped:
needs: [pre-check, detect-changes]
if: >
github.event_name != 'workflow_dispatch' &&
(github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') &&
needs.pre-check.outputs.is_act != 'true' &&
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes != 'true')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: No relevant Python changes detected
run: echo "No Python relevant changes detected; check skipped."