-
Notifications
You must be signed in to change notification settings - Fork 134
215 lines (193 loc) · 7.62 KB
/
ci.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
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
name: CI
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
concurrency:
group: ci-${{ github.workflow }}-${{ github.actor }}-${{ github.sha }}
cancel-in-progress: true
jobs:
static-analysis:
name: Prospector Static Analysis
runs-on: ubuntu-22.04
env:
DJANGO_SETTINGS_MODULE: onadata.settings.github_actions_test
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"
architecture: "x64"
cache: "pip"
cache-dependency-path: |
requirements/base.pip
requirements/dev.pip
requirements/azure.pip
- name: Update apt sources
run: sudo apt-get update
- name: Install APT requirements
run: sudo apt-get install -y --no-install-recommends libjpeg-dev zlib1g-dev software-properties-common ghostscript libxslt1-dev binutils libproj-dev gdal-bin memcached libmemcached-dev libxml2-dev libxslt-dev
- name: Install Pip requirements
run: |
pip install -U pip
pip install wheel
pip install -r requirements/base.pip
pip install -r requirements/dev.pip
pip install -r requirements/azure.pip
- name: Install linting tools
run: pip install prospector==1.7.7 pylint==2.14.5
- name: Run Prospector
run: prospector -X -s veryhigh onadata
unit-tests:
strategy:
fail-fast: false
matrix:
test_path:
- [" Django Unit Tests (Libraries, Main, RestServices, SMS Support, Viewer, Messaging)", "python manage.py test onadata/libs onadata/apps/main onadata/apps/restservice onadata/apps/sms_support onadata/apps/viewer onadata/apps/messaging --noinput --timing --settings=onadata.settings.github_actions_test --verbosity=2 --parallel=4"]
- ["Django Unit Tests API", "python manage.py test onadata/apps/api --noinput --timing --settings=onadata.settings.github_actions_test --verbosity=2 --parallel=4"]
- ["Django Unit Tests Logger", "python manage.py test onadata/apps/logger --noinput --timing --settings=onadata.settings.github_actions_test --verbosity=2 --parallel=4"]
name: "${{ matrix.test_path[0] }}"
runs-on: ubuntu-22.04
needs: static-analysis
env:
DJANGO_SETTINGS_MODULE: onadata.settings.github_actions_test
services:
postgres:
image: postgis/postgis:13-3.0
env:
POSTGRES_PASSWORD: onadata
POSTGRES_DB: onadata
POSTGRES_USER: onadata
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: "adopt"
java-version: "8"
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"
architecture: "x64"
cache: "pip"
cache-dependency-path: |
requirements/base.pip
requirements/dev.pip
requirements/azure.pip
- name: Update apt sources
run: sudo apt-get update
- name: Install APT requirements
run: sudo apt-get install -y --no-install-recommends libjpeg-dev zlib1g-dev software-properties-common ghostscript libxslt1-dev binutils libproj-dev gdal-bin memcached libmemcached-dev libxml2-dev libxslt-dev
- name: Install Pip requirements
run: |
pip install -U pip
pip install -r requirements/base.pip
pip install -r requirements/dev.pip
pip install -r requirements/azure.pip
- name: Run tests
run: |
${{ matrix.test_path[1] }}
security-check:
name: Trivy Security Checks
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Update apt sources
run: sudo apt-get update
- name: Get the branch name
id: get-branch-name
if: github.event_name == 'push'
run: echo "version=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/onadata-uwsgi/Dockerfile.ubuntu
platforms: linux/amd64
push: false
tags: |
onaio/onadata:${{ github.head_ref || github.base_ref || env.version }}
cache-from: type=registry,ref=onaio/onadata:${{ github.head_ref || github.base_ref || env.version }}
cache-to: type=inline
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
if: github.event_name == 'pull_request'
with:
image-ref: onaio/onadata:${{ github.head_ref || github.base_ref || env.version }}
format: sarif
ignore-unfixed: true
severity: "CRITICAL,HIGH"
output: "trivy_results.sarif"
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
if: github.event_name == 'push'
with:
image-ref: onaio/onadata:${{ github.head_ref || github.base_ref || env.version }}
format: sarif
ignore-unfixed: true
output: "trivy_results.sarif"
- name: Upload vulnerability scan results
uses: github/codeql-action/upload-sarif@v3
if: github.event_name == 'push' || github.event_name == 'pull_request'
with:
sarif_file: "trivy_results.sarif"
- name: Run Trivy vulnerability for Slack summary
uses: aquasecurity/trivy-action@master
if: github.event_name == 'push'
with:
image-ref: onaio/onadata:${{ github.head_ref || github.base_ref || env.version }}
format: json
ignore-unfixed: true
output: "trivy_results.json"
- name: Create summary of trivy issues
if: github.event_name == 'push'
run: |
summary=$(jq -r '.Results[] | select(.Vulnerabilities) | .Vulnerabilities | group_by(.Severity) | map({Severity: .[0].Severity, Count: length}) | .[] | [.Severity, .Count] | join(": ")' trivy_results.json | awk 'NR > 1 { printf(" | ") } {printf "%s",$0}')
if [ -z $summary ]
then
summary="0 Issues"
fi
echo "SUMMARY=$summary" >> $GITHUB_ENV
- name: Send Slack Notification
uses: slackapi/[email protected]
if: github.event_name == 'push'
with:
payload: |
{
"text": "Trivy scan results for ${{ github.head_ref || github.base_ref || env.version }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "[Ona Data] Trivy scan results for ${{ github.head_ref || github.base_ref || env.version }}: ${{ env.SUMMARY }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "View scan results: https://github.com/${{ github.repository }}/security/code-scanning?query=branch:${{ github.head_ref || github.base_ref || env.version }}+is:open++"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK