-
Notifications
You must be signed in to change notification settings - Fork 36
154 lines (125 loc) · 4.56 KB
/
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
148
149
150
151
152
153
154
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 2 * * *'
jobs:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
release_test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade PIP
run: |
# windows requires update pip via python module
python -m pip install --upgrade pip
- name: Install application
run: |
pip install .
- name: Remove sources dir to check installation
if: runner.os != 'Windows'
run: rm -rf credsweeper
- name: Remove sources dir to check installation WINDOWS PowerShell
if: runner.os == 'Windows'
run: Remove-Item -Path credsweeper -Force -Recurse
- name: CLI tool check
run: |
credsweeper --help
- name: Install test framework dependencies
run: |
pip install pytest pytest-random-order deepdiff
- name: UnitTest with pytest
run: |
# put the command into one line to use in various OS to avoid processing differences in new line char sequence
pytest --random-order --random-order-bucket=global tests
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
development_test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
run: |
python -m pip install --upgrade pip
python -m pip install --requirement requirements.txt
- name: UnitTest with pytest and coverage
run: |
mkdir -vp xmlcov
python -m \
pytest \
--random-order \
--random-order-bucket=global \
--ignore=docs \
--ignore=experiment \
--ignore=fuzz \
--ignore=tests/test_app.py \
--cov=credsweeper \
--cov-report html:coverage_html/ \
--cov-report xml:xmlcov/coverage.xml \
tests \
;
- name: ApplicationTest with pytest
run: |
python -m \
pytest \
--random-order \
--random-order-bucket=global \
tests/test_app.py \
;
- name: Check unit-test coverage
run: |
if [ ! -f xmlcov/coverage.xml ]; then echo "xmlcov/coverage.xml does not exist"; exit 1; fi
COVERED=$(grep '<coverage .*>' xmlcov/coverage.xml | sed 's/.* lines-covered="\([0-9]\+\)" .*/\1/')
echo "COVERED=${COVERED}"
VALID=$(grep '<coverage .*>' xmlcov/coverage.xml | sed 's/.* lines-valid="\([0-9]\+\)" .*/\1/')
echo "VALID=${VALID}"
if [ -z "${COVERED}" ] || [ -z "${VALID}" ] || [ ${VALID} -eq 0 ]; then echo "'${VALID}' or '${COVERED}' fail"; exit 1; fi
COVERAGE=$(python -c "print (round(100 * ${COVERED} / ${VALID}, 2))")
DESCRIPTION="Coverage of lines: ${COVERED} : ${VALID} = ${COVERAGE}%"
echo "${DESCRIPTION}"
if [ $(( 1000 * ${COVERED} / ${VALID} )) -lt 800 ]; then
echo "Coverage should be not less than 80% !"
exit 1
else
echo "Satisfied coverage"
fi
- name: HTML coverage reports
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage_html-${{ matrix.python-version }}
path: coverage_html
- name: Upload coverage reports to Codecov
if: ${{ matrix.python-version == '3.8' }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: xmlcov/coverage.xml
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #