Skip to content

Commit 4e3f2f0

Browse files
committed
rewrite java CI to add integration test
1 parent 2f5e159 commit 4e3f2f0

File tree

9 files changed

+141
-69
lines changed

9 files changed

+141
-69
lines changed

.github/dependatbot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#schedule-
6+
schedule:
7+
interval: "monthly"
8+
9+
- package-ecosystem: "maven"
10+
directory: "/"
11+
schedule:
12+
interval: "monthly"

.github/workflows/java-continuous-integration.yml

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,105 @@
88
name: Java CI
99

1010
on: [push, pull_request]
11-
env:
11+
env:
1212
MVN_USR: ${{ secrets.MVN_USR }}
1313
MVN_PWD: ${{ secrets.MVN_PWD }}
1414

1515
jobs:
16-
16+
1717
build:
1818
permissions:
1919
packages: read
2020
runs-on: ubuntu-latest
21-
name: Java 17 CI
21+
strategy:
22+
matrix:
23+
java: [ '17', '21' ]
24+
name: Java ${{ matrix.Java }} CI
2225
steps:
26+
# the latest version at https://github.com/marketplace/actions/checkout
2327
- name: Check out repository code
24-
uses: actions/checkout@v2
28+
uses: actions/checkout@v4
2529
with:
2630
fetch-depth: 0
31+
# the latest version at https://github.com/marketplace/actions/setup-java-jdk
2732
- name: Setup java
28-
uses: actions/setup-java@v2
33+
uses: actions/setup-java@v4
2934
with:
3035
distribution: 'adopt'
31-
java-version: 17
32-
- name: Cache Maven packages
36+
java-version: ${{ matrix.java }}
37+
cache: 'maven'
38+
# the latest version at https://github.com/actions/cache
39+
- name: Cache target folders
3340
uses: actions/cache@v4
3441
with:
35-
path: ~/.m2
36-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
37-
restore-keys: ${{ runner.os }}-m2
42+
path: "**/target/"
43+
key: ${{ runner.os }}-cache-java-${{ matrix.java }}-${{ github.sha }}
3844
- name: Build with Maven
39-
run: mvn -B clean test package -s settings.xml
40-
45+
run: mvn -B clean install -s settings.xml
46+
env:
47+
MVN_USR: dummy
48+
MVN_PWD: ${{ secrets.GITHUB_TOKEN }}
49+
4150
code-analysis:
4251
permissions:
4352
packages: read
44-
runs-on: ubuntu-latest
53+
runs-on: ubuntu-latest
54+
needs: build
4555
name: SonarCloud Code Analysis
4656
# It's not possible to launch an analysis on external pull requests
47-
if: ${{ github.repository_owner == 'cnescatlab' }}
57+
# if: ${{ github.repository_owner == 'cnescatlab' }}
4858
steps:
59+
# the latest version at https://github.com/marketplace/actions/checkout
4960
- name: Check out repository code
50-
uses: actions/checkout@v2
51-
with:
52-
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
53-
- name: Setup java
54-
uses: actions/setup-java@v2
61+
uses: actions/checkout@v4
5562
with:
56-
distribution: 'adopt'
57-
java-version: '17'
58-
- name: Cache Maven packages
59-
uses: actions/cache@v4
63+
fetch-depth: 0
64+
# the latest version at https://github.com/actions/cache
65+
- name: Restore cache
66+
uses: actions/cache/restore@v4
6067
with:
61-
path: ~/.m2
62-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
63-
restore-keys: ${{ runner.os }}-m2
64-
- name: Cache SonarCloud packages
65-
uses: actions/cache@v4
68+
path: "**/target/"
69+
fail-on-cache-miss: true
70+
key: ${{ runner.os }}-cache-java-21-${{ github.sha }}
71+
# the latest version at https://github.com/marketplace/actions/official-sonarqube-scan
72+
# Triggering SonarQube analysis as results of it are required by Quality Gate check.
73+
- name: SonarQube Scan
74+
uses: SonarSource/sonarqube-scan-action@v6
6675
with:
67-
path: ~/.sonar/cache
68-
key: ${{ runner.os }}-sonar
69-
restore-keys: ${{ runner.os }}-sonar
70-
- name: Build and analyze
76+
args: >
77+
-Dsonar.qualitygate.wait=true
78+
-Dsonar.qualitygate.timeout=600
7179
env:
72-
# Needed to get some information about the pull request, if any
73-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
7580
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
76-
run: mvn clean -s settings.xml org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.organization=lequal -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
81+
82+
integration-test:
83+
permissions:
84+
packages: read
85+
runs-on: ubuntu-latest
86+
needs: build
87+
name: TI for SonarQube ${{ matrix.sonarQube }}
88+
strategy:
89+
matrix:
90+
sonarQube: [ '25.1.0.102122-community', 'community']
91+
steps:
92+
# the latest version at https://github.com/marketplace/actions/docker-setup-compose
93+
- name: Set up Docker Compose
94+
uses: docker/setup-compose-action@v1
95+
with:
96+
version: latest
97+
# the latest version at https://github.com/marketplace/actions/checkout
98+
- name: Check out repository code
99+
uses: actions/checkout@v4
100+
with:
101+
fetch-depth: 0
102+
# the latest version at https://github.com/actions/cache
103+
- name: Restore cache
104+
uses: actions/cache/restore@v4
105+
with:
106+
path: "**/target/"
107+
fail-on-cache-miss: true
108+
key: ${{ runner.os }}-cache-java-21-${{ github.sha }}
109+
- name: Integration test
110+
run: |
111+
cd it
112+
./it.sh -S ${{ matrix.sonarQube }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Here is the compatibility matrix of the plugin:
3838
| 3.1.1 | 4.1.2 | 7.9 -> 9.9 | Fortran |
3939
| 3.1.2 | 5.1.0 | 7.9 -> 9.9 | Fortran |
4040
| 5.1.0 | 5.1.0 | 7.9 -> 9.9 | Fortran |
41-
| 5.2.0 | 5.1.0 | 25.1.0 -> 25.9.0 | Fortran |
41+
| 5.2.0 | 5.1.0 | 25.1.0 -> 25.9.0 | Fortran |
4242

4343
*Notice: Since 5.X this plugins will follow I-Code versionning. There is no breaking changes between 3.X and 5.X*
4444

it/audit.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ echo $SONAR_TOKEN
2929
# Audit code
3030
echo "Launching scanner..."
3131
cd /usr/src/myapp/it
32-
sonar-scanner -X -Dsonar.qualitygate.wait 2>&1 | tee /tmp/scanner.log
32+
sonar-scanner -Dsonar.log.level=DEBUG -Dsonar.verbose=true -Dsonar.qualitygate.wait 2>&1 | tee /tmp/scanner.log
3333

3434
if [ $? -ne 0 ]
3535
then
@@ -64,26 +64,32 @@ if r.status_code != 200:
6464
6565
data = r.json()
6666
67-
if data['total'] != 100:
68-
print('Wrong total number of issues: ' + str(data['total']), file=sys.stderr)
69-
sys.exit(1)
70-
7167
issues = 0
7268
if 'f77-rules' in data['issues'][0]['rule'] and data['issues'][0]['line'] == 1:
7369
issues += 1
7470
71+
if data['total'] != 100:
72+
print('Wrong total number of issues: ' + str(data['total']), file=sys.stderr)
73+
sys.exit(1)
74+
else:
75+
print('Validation Fortran 77 OK. Issues found: ' + str(data['total']), file=sys.stdout)
76+
7577
r = requests.get('http://sonarqube:9000/api/issues/search?componentKeys=$SONAR_PROJECT_KEY:src/clanhb.f90&statuses=OPEN', auth=('$SONAR_ADMIN_LOGIN', '$SONAR_ADMIN_PWD'))
7678
if r.status_code != 200:
7779
print('Invalid server response: ' + str(r.status_code), file=sys.stderr)
7880
sys.exit(1)
7981
8082
data = r.json()
8183
84+
85+
if 'f90-rules' in data['issues'][0]['rule'] and data['issues'][0]['line'] == 1:
86+
issues += 1
87+
8288
if data['total'] != 197:
8389
print('Wrong total number of issues: ' + str(data['total']), file=sys.stderr)
8490
sys.exit(1)
85-
if 'f90-rules' in data['issues'][0]['rule'] and data['issues'][0]['line'] == 1:
86-
issues += 1
91+
else:
92+
print('Validation Fortran 90 OK. Issues found: ' + str(data['total']), file=sys.stdout)
8793
8894
8995
sys.exit(0 if issues == 2 else 1)

it/it.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export SCRIPT_DIR=`dirname $0`
3939

4040
# Clean-up if needed
4141
echo "Cleanup..."
42-
docker-compose -f $SCRIPT_DIR/docker-compose.yml down
42+
docker compose -f $SCRIPT_DIR/docker-compose.yml down
4343

4444
# Start containers
4545
echo "Starting SonarQube..."
46-
docker-compose -f $SCRIPT_DIR/docker-compose.yml up -d sonarqube
46+
docker compose -f $SCRIPT_DIR/docker-compose.yml up --quiet-pull -d sonarqube
4747
CONTAINER_NAME=$(docker ps --format "{{.Names}}" | grep 'it-sonarqube-1.*' | head -1)
4848
# Wait for SonarQube to be up
4949
grep -q "SonarQube is operational" <(docker logs --follow --tail 0 $CONTAINER_NAME)
@@ -54,7 +54,7 @@ MAVEN_VERSION=$(grep '<version>' $SCRIPT_DIR/../pom.xml | head -1 | sed 's/<\/\?
5454
echo "Installing the plugin Icode version $MAVEN_VERSION"
5555
docker cp $SCRIPT_DIR/../target/sonar-icode-cnes-plugin-$MAVEN_VERSION.jar $CONTAINER_NAME:/opt/sonarqube/extensions/plugins
5656
# Restart SonarQube
57-
docker-compose -f $SCRIPT_DIR/docker-compose.yml restart sonarqube
57+
docker compose -f $SCRIPT_DIR/docker-compose.yml restart sonarqube
5858
# Wait for SonarQube to be up
5959
grep -q "SonarQube is operational" <(docker logs --follow --tail 0 $CONTAINER_NAME)
6060
# Check plug-in installation
@@ -83,11 +83,11 @@ echo "Plugin successfully installed!"
8383

8484
# Audit code
8585
echo "Audit test scripts..."
86-
docker-compose -f $SCRIPT_DIR/docker-compose.yml up --build --exit-code-from auditor auditor
86+
docker compose -f $SCRIPT_DIR/docker-compose.yml up --quiet-pull --build --exit-code-from auditor auditor
8787
AUDIT_STATUS=$?
8888

8989
# Delete containers
9090
echo "Cleanup..."
91-
docker-compose -f $SCRIPT_DIR/docker-compose.yml down
91+
docker compose -f $SCRIPT_DIR/docker-compose.yml down
9292

9393
exit $AUDIT_STATUS

it/sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sonar.projectKey=icode
2-
sonar.projectName=I-Code
2+
sonar.projectName=I-Code TI
33
sonar.projectVersion=1.0
44
sonar.sources=src
55
sonar.scm.disabled=True

pom.xml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757

5858
<properties>
5959
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
60-
<maven.compiler.source>11</maven.compiler.source>
61-
<maven.compiler.target>23</maven.compiler.target>
60+
<!--
61+
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html -->
6262
<maven.compiler.release>17</maven.compiler.release>
6363
<surefire.version>3.5.3</surefire.version>
6464
<!-- Matrice: https://github.com/SonarSource/sonar-plugin-api -->
@@ -73,16 +73,6 @@
7373
<sonar.test>src/test/java</sonar.test>
7474
</properties>
7575

76-
<repositories>
77-
<repository>
78-
<id>github</id>
79-
<url>https://maven.pkg.github.com/cnescatlab/i-CodeCNES</url>
80-
<snapshots>
81-
<enabled>false</enabled>
82-
</snapshots>
83-
</repository>
84-
</repositories>
85-
8676
<dependencies>
8777
<dependency>
8878
<groupId>org.sonarsource.api.plugin</groupId>
@@ -104,6 +94,7 @@
10494
<groupId>org.sonarsource.sonarqube</groupId>
10595
<artifactId>sonar-plugin-api-impl</artifactId>
10696
<version>${sonar.version}</version>
97+
<scope>test</scope>
10798
</dependency>
10899
<dependency>
109100
<groupId>junit</groupId>
@@ -180,20 +171,19 @@
180171
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
181172
<artifactId>sonar-packaging-maven-plugin</artifactId>
182173
<extensions>true</extensions>
174+
<version>1.23.0.740</version>
183175
</plugin>
184176

185177
<plugin>
186178
<groupId>org.apache.maven.plugins</groupId>
187179
<artifactId>maven-compiler-plugin</artifactId>
188-
<configuration>
189-
<source>${jdk.min.version}</source>
190-
<target>${jdk.min.version}</target>
191-
</configuration>
180+
<version>3.14.1</version>
192181
</plugin>
193182

194183
<plugin>
195184
<groupId>org.apache.maven.plugins</groupId>
196185
<artifactId>maven-project-info-reports-plugin</artifactId>
186+
<version>3.9.0</version>
197187
<configuration>
198188
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
199189
</configuration>
@@ -202,6 +192,7 @@
202192
<plugin>
203193
<groupId>org.apache.maven.plugins</groupId>
204194
<artifactId>maven-surefire-plugin</artifactId>
195+
<version>3.5.4</version>
205196
<dependencies>
206197
<dependency>
207198
<groupId>org.apache.maven.surefire</groupId>
@@ -214,6 +205,7 @@
214205
<plugin>
215206
<groupId>org.jacoco</groupId>
216207
<artifactId>jacoco-maven-plugin</artifactId>
208+
<version>0.8.13</version>
217209
<executions>
218210
<execution>
219211
<id>prepare-agent</id>

settings.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4-
http://maven.apache.org/xsd/settings-1.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
54

65
<servers>
76
<server>
@@ -10,4 +9,19 @@
109
<password>${env.MVN_PWD}</password>
1110
</server>
1211
</servers>
13-
</settings>
12+
13+
<profiles>
14+
<profile>
15+
<id>github</id>
16+
<repositories>
17+
<repository>
18+
<id>github</id>
19+
<url>https://maven.pkg.github.com/cnescatlab/*</url>
20+
</repository>
21+
</repositories>
22+
</profile>
23+
</profiles>
24+
<activeProfiles>
25+
<activeProfile>github</activeProfile>
26+
</activeProfiles>
27+
</settings>

sonar-project.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# FIXME mettre lequal lorsque il y aura la PR
2+
# sonar.projectKey=fr.cnes.sonar.plugins:sonar-icode-cnes-plugin
3+
sonar.projectKey=Turiok_sonar-icode-cnes-plugin
4+
sonar.projectName=Sonar i-Code CNES plugin
5+
sonar.projectDescription=i-Code CNES plugin for SonarQube
6+
sonar.sources=src/main/java
7+
sonar.tests=src/test
8+
sonar.java.binaries=target
9+
# FIXME mettre lequal lorsque il y aura la PR
10+
# sonar.organization=lequal
11+
sonar.organization=turiok
12+

0 commit comments

Comments
 (0)