forked from usdot-jpo-ode/jpo-cvmanager
-
Notifications
You must be signed in to change notification settings - Fork 3
223 lines (192 loc) · 6.88 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
216
217
218
219
220
221
222
223
name: cv-manager
on:
push:
branches:
- develop
- cdot-release*
pull_request:
branches:
- '**' # Run on PRs to any branch
jobs:
build_api:
runs-on: ubuntu-latest
container:
image: python:3.12.2
options: --user root
steps:
- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v4
- name: Install Dependencies
run: |
apt-get update
apt-get -y install python3-coverage python3-pip python3-pytest
- name: Install Python Requirements
run: python3 -m pip install -r $GITHUB_WORKSPACE/services/requirements.txt
- name: Run Tests and Generate Coverage
continue-on-error: false
run: |
# Set PYTHONPATH and navigate to the tests directory
export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages
cd $GITHUB_WORKSPACE/services
# Run tests and generate coverage report
python3 -m coverage run -m pytest
python3 -m coverage xml --omit="/opt/*,/root/*,/tmp/*,/usr/*,/var/*,**/__init__.py"
- name: Archive Code Coverage Results
uses: actions/upload-artifact@v4
with:
name: build_api
path: services/coverage.xml
- name: Find coverage.xml
shell: bash
run: |
find "$GITHUB_WORKSPACE/services" -name "coverage.xml"
webapp:
runs-on: ubuntu-latest
container:
image: node:16.16.0
options: --user root
env:
CI: true
steps:
- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v4
- name: Build Web Application
continue-on-error: false
run: |
# Navigate to the webapp directory and perform necessary setup
cd $GITHUB_WORKSPACE/webapp
npm install -g nodemon
npm init -y
npm install --force
# Run tests with coverage and suppress failures
npm test -- --coverage
- name: Archive Code Coverage Results
uses: actions/upload-artifact@v4
with:
name: webapp
path: webapp/coverage/*
- name: Find lcov.info
shell: bash
run: |
find "$GITHUB_WORKSPACE" -name "lcov.info"
build_keycloak_provider:
runs-on: ubuntu-latest
container:
image: maven:3.9.9-eclipse-temurin-21
options: --user root
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '21'
- name: Build and Test with Maven
run: |
cd $GITHUB_WORKSPACE/resources/keycloak/custom-user-provider
mvn clean install
- name: Archive Test Results
uses: actions/upload-artifact@v4
with:
name: keycloak-user-provider-test-results
path: $GITHUB_WORKSPACE/resources/keycloak/custom-user-provider/target/surefire-reports
build_intersection_api:
runs-on: ubuntu-latest
container:
image: maven:3.9.9-eclipse-temurin-21
options: --user root
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('**/settings.xml') }}-${{ runner.os }}-java-21
restore-keys: |
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}-${{ runner.os }}-java-21
${{ runner.os }}-maven-${{ runner.os }}-java-21
${{ runner.os }}-maven
- name: Install Dependencies
env:
MAVEN_GITHUB_TOKEN: ${{ secrets.MAVEN_GITHUB_TOKEN }}
MAVEN_GITHUB_ORG: 'usdot-jpo-ode'
run: |
cd $GITHUB_WORKSPACE/services/intersection-api/api
mvn clean install -DskipTests -s ./settings.xml
mvn dependency:go-offline -s ./settings.xml
- name: Run tests
env:
MAVEN_GITHUB_TOKEN: ${{ secrets.MAVEN_GITHUB_TOKEN }}
MAVEN_GITHUB_ORG: 'usdot-jpo-ode'
run: |
cd $GITHUB_WORKSPACE/services/intersection-api/api
mvn verify -s ./settings.xml
- name: Archive Test Results
uses: actions/upload-artifact@v4
with:
name: intersection-api-test-results
path: $GITHUB_WORKSPACE/services/intersection-api/api/target/surefire-reports
- name: Clean up
run: |
rm -rf $GITHUB_WORKSPACE/services/intersection-api/api/target
sonar:
needs: [build_api, webapp]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download code coverage results
uses: actions/download-artifact@v4
continue-on-error: false
with:
name: build_api
path: services/coverage.xml
- name: Download Code Coverage Results
uses: actions/download-artifact@v4
with:
name: webapp
path: webapp
- name: Find coverage.xml
shell: bash
run: |
find "$GITHUB_WORKSPACE" -name "coverage.xml"
- name: Find lcov.info
shell: bash
run: |
find "$GITHUB_WORKSPACE" -name "lcov.info"
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Setup SonarScanner
uses: warchant/setup-sonar-scanner@v7
- name: Generate Sonar Properties File
run: |
cat <<EOF > /tmp/sonar-scanner.properties
sonar.host.url=https://sonarcloud.io
sonar.exclusions=**/__init__.py,**/*test*.py,**/test/**
sonar.coverage.exclusions=**/__init__.py,**/*test*.py,**/test/**
sonar.javascript.lcov.reportPaths=/home/runner/work/jpo-cvmanager/jpo-cvmanager/webapp/lcov.info
sonar.modules=api,webapp
sonar.organization=usdot-jpo-ode
sonar.projectBaseDir=$GITHUB_WORKSPACE
sonar.projectKey=usdot-jpo-ode_jpo-cvmanager
sonar.projectName=jpo-cvmanager
sonar.python.coverage.reportPaths=$GITHUB_WORKSPACE/services/coverage.xml
sonar.python.version=3.12.2
api.sonar.projectBaseDir=$GITHUB_WORKSPACE/services
api.sonar.sources=addons/images/count_metric,addons/images/firmware_manager,addons/images/iss_health_check,addons/images/rsu_status_check,api/src,common/pgquery.py
api.sonar.tests=addons/tests,api/tests,common/tests
webapp.sonar.projectBaseDir=$GITHUB_WORKSPACE/webapp
webapp.sonar.sources=src
EOF
- name: Run SonarScanner
uses: usdot-fhwa-stol/actions/sonar-scanner@main
with:
sonar-properties-path: /tmp/sonar-scanner.properties
sonar-token: ${{ secrets.SONAR_TOKEN }}
working-dir: $GITHUB_WORKSPACE