Skip to content

Commit 69e9f8b

Browse files
committed
rewrite java CI to add integration test
1 parent 2f5e159 commit 69e9f8b

File tree

9 files changed

+136
-71
lines changed

9 files changed

+136
-71
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: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,102 @@
88
name: Java CI
99

1010
on: [push, pull_request]
11-
env:
12-
MVN_USR: ${{ secrets.MVN_USR }}
13-
MVN_PWD: ${{ secrets.MVN_PWD }}
1411

1512
jobs:
16-
13+
1714
build:
1815
permissions:
1916
packages: read
2017
runs-on: ubuntu-latest
21-
name: Java 17 CI
18+
strategy:
19+
matrix:
20+
java: [ '17', '21' ]
21+
name: Java ${{ matrix.Java }} CI
2222
steps:
23+
# the latest version at https://github.com/marketplace/actions/checkout
2324
- name: Check out repository code
24-
uses: actions/checkout@v2
25+
uses: actions/checkout@v4
2526
with:
2627
fetch-depth: 0
28+
# the latest version at https://github.com/marketplace/actions/setup-java-jdk
2729
- name: Setup java
28-
uses: actions/setup-java@v2
30+
uses: actions/setup-java@v4
2931
with:
3032
distribution: 'adopt'
31-
java-version: 17
32-
- name: Cache Maven packages
33+
java-version: ${{ matrix.java }}
34+
cache: 'maven'
35+
# the latest version at https://github.com/actions/cache
36+
- name: Cache target folders
3337
uses: actions/cache@v4
3438
with:
35-
path: ~/.m2
36-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
37-
restore-keys: ${{ runner.os }}-m2
39+
path: "**/target/"
40+
key: ${{ runner.os }}-cache-java-${{ matrix.java }}-${{ github.sha }}
3841
- name: Build with Maven
39-
run: mvn -B clean test package -s settings.xml
40-
42+
run: mvn -B clean install -s settings.xml
43+
env:
44+
MVN_USR: dummy
45+
MVN_PWD: ${{ secrets.GITHUB_TOKEN }}
46+
4147
code-analysis:
4248
permissions:
4349
packages: read
44-
runs-on: ubuntu-latest
50+
runs-on: ubuntu-latest
51+
needs: build
4552
name: SonarCloud Code Analysis
4653
# It's not possible to launch an analysis on external pull requests
47-
if: ${{ github.repository_owner == 'cnescatlab' }}
54+
# if: ${{ github.repository_owner == 'cnescatlab' }}
4855
steps:
56+
# the latest version at https://github.com/marketplace/actions/checkout
4957
- 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
58+
uses: actions/checkout@v4
5559
with:
56-
distribution: 'adopt'
57-
java-version: '17'
58-
- name: Cache Maven packages
59-
uses: actions/cache@v4
60+
fetch-depth: 0
61+
# the latest version at https://github.com/actions/cache
62+
- name: Restore cache
63+
uses: actions/cache/restore@v4
6064
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
65+
path: "**/target/"
66+
fail-on-cache-miss: true
67+
key: ${{ runner.os }}-cache-java-21-${{ github.sha }}
68+
# the latest version at https://github.com/marketplace/actions/official-sonarqube-scan
69+
# Triggering SonarQube analysis as results of it are required by Quality Gate check.
70+
- name: SonarQube Scan
71+
uses: SonarSource/sonarqube-scan-action@v6
6672
with:
67-
path: ~/.sonar/cache
68-
key: ${{ runner.os }}-sonar
69-
restore-keys: ${{ runner.os }}-sonar
70-
- name: Build and analyze
73+
args: >
74+
-Dsonar.qualitygate.wait=true
75+
-Dsonar.qualitygate.timeout=600
7176
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/
7577
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
78+
79+
integration-test:
80+
permissions:
81+
packages: read
82+
runs-on: ubuntu-latest
83+
needs: build
84+
name: TI for SonarQube ${{ matrix.sonarQube }}
85+
strategy:
86+
matrix:
87+
sonarQube: [ '25.1.0.102122-community', 'community']
88+
steps:
89+
# the latest version at https://github.com/marketplace/actions/docker-setup-compose
90+
- name: Set up Docker Compose
91+
uses: docker/setup-compose-action@v1
92+
with:
93+
version: latest
94+
# the latest version at https://github.com/marketplace/actions/checkout
95+
- name: Check out repository code
96+
uses: actions/checkout@v4
97+
with:
98+
fetch-depth: 0
99+
# the latest version at https://github.com/actions/cache
100+
- name: Restore cache
101+
uses: actions/cache/restore@v4
102+
with:
103+
path: "**/target/"
104+
fail-on-cache-miss: true
105+
key: ${{ runner.os }}-cache-java-21-${{ github.sha }}
106+
- name: Integration test
107+
run: |
108+
cd it
109+
./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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
sonar.projectKey=fr.cnes.sonar.plugins:sonar-icode-cnes-plugin
2+
sonar.projectName=Sonar i-Code CNES plugin
3+
sonar.projectDescription=i-Code CNES plugin for SonarQube
4+
sonar.sources=src/main/java
5+
sonar.tests=src/test
6+
sonar.java.binaries=target
7+
sonar.organization=lequal
8+

0 commit comments

Comments
 (0)