-
-
Notifications
You must be signed in to change notification settings - Fork 156
183 lines (168 loc) · 7.53 KB
/
main.yml
File metadata and controls
183 lines (168 loc) · 7.53 KB
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
name: Build and Deploy Snapshot
on:
push:
branches: ['3.*']
paths-ignore:
- "README.md"
- "release-notes/*"
pull_request:
branches:
paths-ignore:
- "README.md"
- "release-notes/*"
permissions:
contents: read
pull-requests: write
jobs:
build:
runs-on: 'ubuntu-24.04'
strategy:
fail-fast: false
matrix:
java_version: ['17', '21', '25']
include:
- java_version: '17'
release_build: 'R'
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java_version }}
cache: 'maven'
server-id: central-snapshots
server-username: CI_DEPLOY_USERNAME
server-password: CI_DEPLOY_PASSWORD
# See https://github.com/actions/setup-java/blob/v2/docs/advanced-usage.md#Publishing-using-Apache-Maven
# gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
# gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Build
run: ./mvnw -B -q -ff -ntp verify
- name: Extract project Maven version
id: projectVersion
run: echo "version=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.5.1:evaluate -DforceStdout -Dexpression=project.version -q)" >> $GITHUB_OUTPUT
- name: Deploy snapshot
if: ${{ matrix.release_build && github.event_name != 'pull_request' && endsWith(steps.projectVersion.outputs.version, '-SNAPSHOT') }}
env:
CI_DEPLOY_USERNAME: ${{ secrets.CENTRAL_DEPLOY_USERNAME }}
CI_DEPLOY_PASSWORD: ${{ secrets.CENTRAL_DEPLOY_PASSWORD }}
# MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
run: ./mvnw -B -q -ff -DskipTests -ntp source:jar deploy
- name: Generate code coverage
if: ${{ matrix.release_build }}
run: ./mvnw -B -q -ff -ntp test jacoco:report
- name: Publish code coverage
if: ${{ matrix.release_build && github.event_name != 'pull_request' }}
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./csv/target/site/jacoco/jacoco.xml,./properties/target/site/jacoco/jacoco.xml,./yaml/target/site/jacoco/jacoco.xml,./toml/target/site/jacoco/jacoco.xml
flags: unittests
- name: Merge JaCoCo CSV reports
if: ${{ matrix.release_build }}
run: |
# Merge all module JaCoCo CSV reports into one file
mkdir -p target
head -1 csv/target/site/jacoco/jacoco.csv > target/jacoco-merged.csv
for module in csv properties yaml toml; do
tail -n +2 "${module}/target/site/jacoco/jacoco.csv" >> target/jacoco-merged.csv
done
- name: Upload coverage report as artifact
if: ${{ matrix.release_build && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: jacoco-report
path: target/jacoco-merged.csv
retention-days: 30
- name: Download base branch coverage
if: ${{ matrix.release_build && github.event_name == 'pull_request' }}
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
continue-on-error: true
with:
workflow: main.yml
branch: ${{ github.event.pull_request.base.ref }}
name: jacoco-report
path: base-coverage/
- name: Generate coverage comment
if: ${{ matrix.release_build && github.event_name == 'pull_request' }}
run: |
# Parse JaCoCo CSV to compute coverage percentage
# Columns: GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED(4),INSTRUCTION_COVERED(5),BRANCH_MISSED(6),BRANCH_COVERED(7),...
parse_coverage() {
local csv_file=$1 col_missed=$2 col_covered=$3
awk -F',' -v m="$col_missed" -v c="$col_covered" \
'NR>1 {
total_missed += $m;
total_covered += $c;
}
END {
if (total_missed + total_covered > 0)
printf "%.2f", (total_covered * 100.0) / (total_missed + total_covered)
}' "$csv_file"
}
format_delta() {
local delta=$1
if awk -v d="$delta" 'BEGIN { exit (d >= 0) ? 0 : 1 }'; then
echo "+${delta}%|📈"
else
echo "${delta}%|📉"
fi
}
get_color() {
awk -v v="$1" 'BEGIN {
if (v >= 80) print "brightgreen"
else if (v >= 60) print "green"
else if (v >= 40) print "yellow"
else print "red"
}'
}
# Compute current coverage from JaCoCo CSV
COVERAGE=$(parse_coverage "target/jacoco-merged.csv" 4 5)
BRANCHES=$(parse_coverage "target/jacoco-merged.csv" 6 7)
# Check if base coverage artifact was downloaded and calculate deltas
HAS_DELTA=false
if [ -f "base-coverage/jacoco-merged.csv" ]; then
echo "Found base branch coverage from artifact"
BASE_COVERAGE=$(parse_coverage "base-coverage/jacoco-merged.csv" 4 5)
BASE_BRANCHES=$(parse_coverage "base-coverage/jacoco-merged.csv" 6 7)
if [ -n "$BASE_COVERAGE" ] && [ -n "$BASE_BRANCHES" ]; then
COV_DELTA=$(awk -v curr="$COVERAGE" -v base="$BASE_COVERAGE" 'BEGIN { printf "%.3f", curr - base }')
BR_DELTA=$(awk -v curr="$BRANCHES" -v base="$BASE_BRANCHES" 'BEGIN { printf "%.3f", curr - base }')
IFS='|' read -r COV_DELTA_STR COV_DELTA_EMOJI <<< "$(format_delta "$COV_DELTA")"
IFS='|' read -r BR_DELTA_STR BR_DELTA_EMOJI <<< "$(format_delta "$BR_DELTA")"
HAS_DELTA=true
fi
fi
# Determine badge colors
COV_COLOR=$(get_color "$COVERAGE")
BR_COLOR=$(get_color "$BRANCHES")
# Build coverage table with or without deltas
if [ "$HAS_DELTA" = "true" ]; then
COVERAGE_TABLE="| Metric | Coverage | Change |
|--------|----------|--------|
| **Instructions** |  **${COVERAGE}%** | ${COV_DELTA_EMOJI} **${COV_DELTA_STR}** |
| **Branches** |  **${BRANCHES}%** | ${BR_DELTA_EMOJI} **${BR_DELTA_STR}** |"
else
COVERAGE_TABLE="| Metric | Coverage |
|--------|----------|
| **Instructions** |  **${COVERAGE}%** |
| **Branches** |  **${BRANCHES}%** |"
fi
COMMENT_BODY="## :test_tube: Code Coverage Report
$COVERAGE_TABLE
> Coverage data generated from JaCoCo test results
<!-- jacoco-coverage-comment -->"
# Save comment for the workflow_run
mkdir -p pr-comment
echo "${{ github.event.pull_request.number }}" > pr-comment/pr-number.txt
echo "$COMMENT_BODY" > pr-comment/comment-body.txt
- name: Upload PR comment
if: ${{ matrix.release_build && github.event_name == 'pull_request' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-comment
path: pr-comment/
retention-days: 1