-
Notifications
You must be signed in to change notification settings - Fork 25
160 lines (154 loc) · 5.5 KB
/
python.yml
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
name: Python
on:
pull_request:
branches:
- main
- release-*
- feature/*
push:
branches:
- main
- release-*
- feature/*
jobs:
check-python-changes:
name: Check whether tests need to be run based on diff
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: antrea-io/has-changes@v2
id: check_diff
with:
paths: plugins/policy-recommendation/* plugins/anomaly-detection/*
outputs:
has_changes: ${{ steps.check_diff.outputs.has_changes }}
python-lint:
needs: check-python-changes
if: ${{ needs.check-python-changes.outputs.has_changes == 'yes' }}
name: Python Lint
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9"]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Check-out code
uses: actions/checkout@v4
# H106: Don't put vim configuration in source files
# H203: Use assertIs(Not)None to check for None
# H204: Use assert(Not)Equal to check for equality
# H205: Use assert(Greater|Less)(Equal) for comparison
# E125 continuation line does not distinguish itself from next logical line
# E126 continuation line over-indented for hanging indent
# E128 continuation line under-indented for visual indent
# E129 visually indented line with same indent as next logical line
# E265 block comment should start with '#'
# H305 imports not grouped correctly
# H307 like imports should be grouped together
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
# I202 Additional newline in a group of imports
# H904 Wrap long lines in parentheses instead of a backslash
# TODO(dougwig) -- uncomment this to test for remaining linkages
# N530 direct neutron imports not allowed
# N531 translations hints
# W504 line break after binary operator
- name: Install Lint dependencies with flake8
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8 on policy-recommendation
run: |
flake8 --ignore E125,E126,E128,E129,E265,H305,H307,H404,H405,H904,N530,N531,W504,I202 \
--enable-extensions H106,H203,H204,H205 \
--show-source \
--count \
--statistic \
plugins/policy-recommendation/
- name: Lint with flake8 on anomaly-detection
run: |
flake8 --ignore E125,E126,E128,E129,E265,H305,H307,H404,H405,H904,N530,N531,W504,I202 \
--enable-extensions H106,H203,H204,H205 \
--show-source \
--count \
--statistic \
plugins/anomaly-detection/
test-unit:
needs: check-python-changes
if: ${{ needs.check-python-changes.outputs.has_changes == 'yes' }}
name: Unit test
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9"]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Check-out code
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest-cov
python -m pip install -r plugins/policy-recommendation/requirements.txt
python -m pip install -r plugins/anomaly-detection/requirements.txt
- name: Run policy-recommendation unit tests
run: |
cd plugins/policy-recommendation/
pytest -vv --cov . --cov-report xml
- name: Run anomaly-detection unit tests
run: |
cd plugins/anomaly-detection/
pytest -vv --cov . --cov-report xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: plugins/policy-recommendation/coverage.xml,plugins/anomaly-detection/coverage.xml
flags: python-coverage
check-udf-changes:
name: Check whether udf tests need to be run based on diff
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: antrea-io/has-changes@v2
id: check_diff
with:
paths: snowflake/udfs/udfs/*
outputs:
has_changes: ${{ steps.check_diff.outputs.has_changes }}
test-udf:
needs: check-udf-changes
if: ${{ needs.check-udf-changes.outputs.has_changes == 'yes' }}
name: Udf test
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9"]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Check-out code
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install six psutil python-dateutil urllib3 requests pyyaml pandas
wget https://downloads.antrea.io/artifacts/snowflake-udf/k8s-client-python-v24.2.0.zip
unzip k8s-client-python-v24.2.0.zip -d snowflake/udfs/udfs/
- name: Run udf tests
run: |
make -C snowflake/udfs/udfs check