-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (130 loc) · 4.55 KB
/
build_test.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
name: Building and Testing
on:
#triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]
paths-ignore:
- '**/.md'
- '**/.yml'
- '**/.ipynb'
- 'docs/**/*'
- LICENSE
- .gitignore
pull_request:
branches: [ main ]
#allow for workflow to be manually triggered from the Actions tab
workflow_dispatch:
#build and test iso3166_2
jobs:
#build job
test:
name: Setup environment
timeout-minutes: 15
runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-latest, windows-latest] #testing on multiple OS's, macos-latest
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10"] #testing on multiple python versions
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
#install all required modules and dependancies using pip and setup.py installation
- name: Install dependencies
run: |
python -m pip install pip
python3 -m pip install setuptools wheel twine
pip install flake8 pytest
pip install pytest
pip install codecov
pip install pytest-cov
pip install bandit
pip install safety
pip install importlib-metadata
pip install iso3166-2
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
python3 setup.py install
#create artifacts dir
- name: Artifacts mkdir
run: mkdir artifacts
#package vulnerability check
- name: Package safety check
run: |
echo "Running package safety check"
python3 -m safety check > artifacts/package_safety_output.txt
cat artifacts/package_safety_output.txt
continue-on-error: true
#run Bandit security check for any known vulnerabilities in code
- name: Bandit
run: |
echo "Running Bandit"
python3 -m bandit -r iso3166_2 > artifacts/bandit_output.txt
cat artifacts/bandit_output.txt
continue-on-error: true
#unit tests using pytest, unittest, flake8 and bandit frameworks
- name: Testing with unittest
env:
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }}
run: |
echo "Testing using unittest..."
python3 -m unittest discover tests -b
#create coverage report using pytest package
- name: Generate Coverage Report
run: |
pytest --cov=./ --cov-report=xml
codecov
#upload to Code Coverage, only if matrix python version is 3.9
- name: Upload Coverage Report to Codecov
if: ${{ matrix.python-version == '3.9' }}
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: iso3166_2_workflow
#upload test artifacts to workflow
- name: Upload Test Artifacts
uses: actions/upload-artifact@v3
with:
name: test_artifacts
path: |
artifacts/package_safety_output.txt
artifacts/bandit_output.txt
artifacts/coverage.txt
if-no-files-found: error
#linter check on repo
linter:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"] #testing on multiple python versions
steps:
#checkout repo
- name: Checkout repo
uses: actions/checkout@v3
# install all required modules and dependancies using pip installation
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
#create temp artifacts repo
- name: Artifacts mkdir
run: mkdir flake8_artifacts
#linting with flake8
- name: Lint with flake8
run: |
echo "Testing using flake8..."
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics > flake8_artifacts/flake8_output.txt
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics >> flake8_artifacts/flake8_output.txt
continue-on-error: true
#upload artifacts to repo
- name: Upload flake8 Artifact
uses: actions/upload-artifact@v3
with:
name: flake8_artifact
path: flake8_artifacts/flake8_output.txt
if-no-files-found: error