-
Notifications
You must be signed in to change notification settings - Fork 0
238 lines (206 loc) · 7.08 KB
/
minimal_test.yml
File metadata and controls
238 lines (206 loc) · 7.08 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# TorchMeter, AGPL-3.0 license
# Author: Ahzyuan
# Repo: https://github.com/TorchMeter/torchmeter
# This workflow ensures quick code quality checks and code logic validation.
#
# Trigger Conditions:
# - PR events (open/review-ready/reopened/synchronize) with changes to:
# - Source code (/torchmeter)
# - Test cases (/tests)
# - Configuration files (default_cfg.yml, requirements.txt)
# - Manual trigger via GitHub UI:
# - PR number: the target PR number that needs to be tested
# - Select OS: ubuntu/macOS/windows
# - Choose Python version: 3.8~3.13
#
# Core functions:
# 1. Automated Linting & Formatting via Ruff
# 2. Dynamic Environment Testing:
# - Randomly selects OS and uses Python 3.8 for non-manual runs
# - Validates code across OS/Python combinations on manual runs
name: ✔ Minimal Test ✘
on:
pull_request:
types:
- opened
- ready_for_review
- synchronize
- reopened
paths:
- 'tests/**'
- 'torchmeter/**'
- 'default_cfg.yml'
- 'requirements.txt'
workflow_dispatch:
inputs:
pr_number:
description: 'Target PR Number'
required: true
type: number
chosen-os:
required: true
type: choice
options:
- ubuntu
- macOS
- windows
python-version:
required: true
type: choice
options:
- 3.8
- 3.9
- 3.10
- 3.11
- 3.12
- 3.13
env:
FORCE_COLOR: 1
GH_TOKEN: ${{ github.token }}
jobs:
Pick-OS-Python:
name: Determine OS & Python
runs-on: ubuntu-latest
outputs:
os: ${{ steps.set-env.outputs.os }}
short_os: ${{ steps.set-env.outputs.short_os }}
python_version: ${{ steps.set-env.outputs.python_version }}
steps:
- id: set-env
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
OS="${{ github.event.inputs.chosen-os }}"
FORMAL_OS="$OS-latest"
SHORT_OS="$(echo $OS | tr 'A-Z' 'a-z')"
PYTHON_VERSION="${{ github.event.inputs.python-version }}"
else
os_array=("ubuntu" "macOS" "windows")
pick_os_idx=$((RANDOM % ${#os_array[@]}))
OS="${os_array[pick_os_idx]}"
FORMAL_OS="$OS-latest"
SHORT_OS="$(echo $OS | tr 'A-Z' 'a-z')"
PYTHON_VERSION="3.8"
fi
echo -e "OS=$FORMAL_OS\nPYTHON-VERSION=$PYTHON_VERSION"
echo "os=$FORMAL_OS" >> $GITHUB_OUTPUT
echo "short_os=$SHORT_OS" >> $GITHUB_OUTPUT
echo "python_version=$PYTHON_VERSION" >> $GITHUB_OUTPUT
Lint-Format:
name: 🕵️♂️ Lint and Format 📝
needs: [Pick-OS-Python]
runs-on: ${{ needs.Pick-OS-Python.outputs.os }}
steps:
- name: Fetch Code
uses: actions/checkout@v4
- name: Checkout PR
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
gh pr checkout ${{ github.event.inputs.pr_number }}
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ needs.Pick-OS-Python.outputs.python_version }}
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install ruff>=0.6.0
ruff version
- name: Lint Code with Ruff
shell: bash
run: |
set +e
ruff check \
--preview \
--target-version=py38 \
--output-format=grouped \
--output-file=ruff_lint_output.log
exit_code=$?
set -e
if [[ $exit_code -eq 0 ]]; then
echo -e "\n✅ Linting passed! Code quality check successful! 🎉"
else
echo -e "\n❌ Linting failed! Some code does not meet the linting rules!" >&2
echo -e "💡 Detailed Report: artifacts/ruff-lint-output" >&2
exit 1
fi
- name: Upload Lint Report
if: always()
uses: actions/upload-artifact@v4
with:
name: ruff-lint-output
path: ruff_lint_output.log
overwrite: true
retention-days: 7
if-no-files-found: error
- name: Format Code with Ruff
shell: bash
run: |
set -o pipefail
set +e
ruff format \
--diff \
--preview \
--target-version=py38 > ruff_format_diff.log
exit_code=$?
# ruff format --preview --target-version=py38
set -e
if [[ $exit_code -eq 0 ]]; then
echo -e "\n✅ Formatting passed! All code is well-formated! 🎉"
else
echo -e "\n❌ Formatting failed! Some code does not meet the format requirements!" >&2
echo -e "💡 Detailed Report: artifacts/ruff-format-diff" >&2
exit 1
fi
- name: Upload Format Report
if: always()
uses: actions/upload-artifact@v4
with:
name: ruff-format-diff
path: ruff_format_diff.log
overwrite: true
retention-days: 7
if-no-files-found: error
Minimal-Test:
name: 🧩 Minimal Test 🧪
needs: [Pick-OS-Python, Lint-Format]
runs-on: ${{ needs.Pick-OS-Python.outputs.os }}
steps:
- name: Fetch Code
uses: actions/checkout@v4
- name: Checkout PR
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
gh pr checkout ${{ github.event.inputs.pr_number }}
fi
- name: Set up Python ${{ needs.Pick-OS-Python.outputs.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ needs.Pick-OS-Python.outputs.python_version }}
cache: 'pip'
cache-dependency-path: |
setup.cfg
requirements.txt
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[test]"
- name: Run Tests
shell: bash
run: |
set -o pipefail
pytest -q \
--cov-report "xml:coverage-${{ needs.Pick-OS-Python.outputs.short_os }}-${{ needs.Pick-OS-Python.outputs.python_version }}.xml" \
--junitxml=test-report--${{ needs.Pick-OS-Python.outputs.short_os }}-${{ needs.Pick-OS-Python.outputs.python_version }}.xml \
| tee pytest-output--${{ needs.Pick-OS-Python.outputs.short_os }}-${{ needs.Pick-OS-Python.outputs.python_version }}.log
- name: Upload Pytest Report
if: always()
uses: actions/upload-artifact@v4
with:
name: pytest-output--${{ needs.Pick-OS-Python.outputs.short_os }}-${{ needs.Pick-OS-Python.outputs.python_version }}
path: pytest-output--${{ needs.Pick-OS-Python.outputs.short_os }}-${{ needs.Pick-OS-Python.outputs.python_version }}.log
overwrite: true
retention-days: 7
if-no-files-found: error