-
Notifications
You must be signed in to change notification settings - Fork 10
152 lines (132 loc) · 4.49 KB
/
build.yaml
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
name: CI
on:
pull_request:
types:
- opened
- reopened
- synchronize
paths-ignore:
- "**.md"
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
pre-commit:
if: always()
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt --use-deprecated=legacy-resolver
- name: Run black
shell: bash
run: pre-commit run black --all-files
- name: Run flake8
shell: bash
run: pre-commit run flake8 --all-files
build-and-test:
name: "Build and Test Python 3.9"
runs-on: ubuntu-latest
if: always()
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.9"
cache: "pip"
- name: Install Dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install pytest-github-actions-annotate-failures
- name: Download NLTK dependencies
run: |
python -m nltk.downloader punkt wordnet stopwords omw-1.4
- name: PyTest with code coverage
continue-on-error: true
run: |
pytest --junitxml pytest.xml --cov=. --cov-report=term-missing --cov-report=xml --cov-branch | tee pytest-coverage.txt
- name: Upload Coverage Results txt
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-results-txt
path: ./pytest-coverage.txt
- name: Upload Coverage Results xml
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-results-xml
path: ./coverage.xml
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v3
with:
name: unit-test-py39
path: ./pytest.xml
publish-test-results:
name: "Publish Unit Tests Results"
needs: build-and-test
runs-on: ubuntu-latest
if: always()
timeout-minutes: 20
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: artifacts/unit-test-py39/*.xml
comment_mode: off
- name: Get the Coverage
shell: bash
run: |
regex='<coverage.+line-rate="([0-9).[0-9]+)".+>'
line=$(grep -oP $regex artifacts/coverage-results-xml/coverage.xml)
[[ $line =~ $regex ]]
coverage=$( bc <<< ${BASH_REMATCH[1]}*100 )
if (( $(echo "$coverage > 90" |bc -l) )); then
COLOR=green
else
COLOR=red
fi
echo "COVERAGE=${coverage%.*}%" >> $GITHUB_ENV
echo "COLOR=$COLOR" >> $GITHUB_ENV
- name: Create the Badge
uses: schneegans/dynamic-badges-action@v1.6.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 4f783c1a3358dbd1e01d44f9656676a0
filename: coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json
label: coverage
message: ${{ env.COVERAGE }}
color: ${{ env.COLOR }}
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Current Branch | Main Branch |
- name: Create coverage comment
uses: peter-evans/create-or-update-comment@v2.1.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Current Branch | Main Branch |
| ------ | ------ |
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/IKostric/4f783c1a3358dbd1e01d44f9656676a0/raw/coverage.${{ env.REPO_NAME }}.${{ github.event.number }}.json) | ![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/IKostric/4f783c1a3358dbd1e01d44f9656676a0/raw/coverage.${{ env.REPO_NAME }}.main.json) |
edit-mode: replace