Skip to content

Commit dd591fc

Browse files
Create actions (#46)
* Create maven.yml * Update maven.yml * Update maven.yml * Update maven.yml * Update maven.yml * Update and rename maven.yml to javaCI.yml * Update and rename javaCI.yml to maven.yml * Create runTests.yml * Update maven.yml * Update maven.yml * Update maven.yml * Delete runTests.yml * Update dependencies in pom.xml * Update: unsafe dependency * add java code coverage * Update maven.yml * Update maven.yml * Update maven.yml
1 parent ef29a75 commit dd591fc

2 files changed

Lines changed: 96 additions & 5 deletions

File tree

.github/workflows/maven.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
3+
name: Java CI with Maven, Run Tests, Coverage Report and Badge
4+
5+
on:
6+
push:
7+
branches: [ "master" ]
8+
pull_request:
9+
branches: [ "master" ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Setup Java Development Kits
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: 17
23+
distribution: microsoft
24+
cache: maven
25+
26+
- name: Build with Maven
27+
run: mvn -B package --file pom.xml
28+
29+
- name: Generate JavaCodeCoverage badge
30+
id: jacoco
31+
uses: cicirello/jacoco-badge-generator@v2
32+
with:
33+
badges-directory: badges
34+
generate-branches-badge: true
35+
generate-summary: true
36+
37+
- name: Log coverage percentages to workflow output
38+
run: |
39+
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
40+
echo "branches = ${{ steps.jacoco.outputs.branches }}"
41+
42+
- name: Upload JaCoCo coverage report as a workflow artifact
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: jacoco-report
46+
path: target/site/jacoco/
47+
48+
- name: Commit and push the coverage badges and summary file
49+
if: ${{ github.event_name != 'pull_request' }}
50+
run: |
51+
cd badges
52+
if [[ `git status --porcelain *.svg *.json` ]]; then
53+
git config --global user.name 'github-actions'
54+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
55+
git add *.svg *.json
56+
git commit -m "Autogenerated JaCoCo coverage badges" *.svg *.json
57+
git push
58+
fi
59+
60+
- name: Comment on PR with coverage percentages
61+
if: ${{ github.event_name == 'pull_request' }}
62+
run: |
63+
REPORT=$(<badges/coverage-summary.json)
64+
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
65+
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
66+
NEWLINE=$'\n'
67+
BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
68+
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@
5555
<target>1.8</target>
5656
</configuration>
5757
</plugin>
58+
59+
<plugin>
60+
<groupId>org.jacoco</groupId>
61+
<artifactId>jacoco-maven-plugin</artifactId>
62+
<version>0.8.8</version>
63+
<executions>
64+
<execution>
65+
<id>prepare-agent</id>
66+
<goals>
67+
<goal>prepare-agent</goal>
68+
</goals>
69+
</execution>
70+
<execution>
71+
<id>report</id>
72+
<phase>test</phase>
73+
<goals>
74+
<goal>report</goal>
75+
</goals>
76+
</execution>
77+
</executions>
78+
</plugin>
5879
</plugins>
5980
</build>
6081

@@ -69,26 +90,26 @@
6990
<dependency>
7091
<groupId>com.squareup.okhttp3</groupId>
7192
<artifactId>okhttp</artifactId>
72-
<version>4.9.3</version>
93+
<version>4.10.0</version>
7394
</dependency>
7495

7596
<dependency>
7697
<groupId>com.google.code.gson</groupId>
7798
<artifactId>gson</artifactId>
78-
<version>2.9.0</version>
99+
<version>2.10</version>
79100
</dependency>
80101

81102
<dependency>
82103
<groupId>org.mock-server</groupId>
83-
<artifactId>mockserver-junit-rule</artifactId>
84-
<version>5.13.0</version>
104+
<artifactId>mockserver-netty-no-dependencies</artifactId>
105+
<version>5.14.0</version>
85106
<scope>test</scope>
86107
</dependency>
87108

88109
<dependency>
89110
<groupId>org.slf4j</groupId>
90111
<artifactId>slf4j-simple</artifactId>
91-
<version>1.7.36</version>
112+
<version>2.0.4</version>
92113
<scope>test</scope>
93114
</dependency>
94115
</dependencies>

0 commit comments

Comments
 (0)