Skip to content

Commit ad3b332

Browse files
committed
Introducing warning and error counts to the build process.
1 parent 1947085 commit ad3b332

2 files changed

Lines changed: 117 additions & 1 deletion

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Full Build Metrics
2+
description: Count Maven warnings/errors, compare against latest successful baseline, and persist current metrics artifact
3+
4+
inputs:
5+
log-file:
6+
description: Path to the captured build log
7+
required: false
8+
default: full-build-base.log
9+
artifact-name:
10+
description: Artifact name used to store metrics
11+
required: false
12+
default: full-build-base-metrics
13+
baseline-branch:
14+
description: Branch to fetch the latest successful baseline metrics from
15+
required: false
16+
default: master
17+
workflow-file:
18+
description: Workflow filename to query for baseline artifacts
19+
required: false
20+
default: ci.yml
21+
retention-days:
22+
description: Artifact retention period in days
23+
required: false
24+
default: "90"
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- name: Download previous metrics artifact
30+
uses: dawidd6/action-download-artifact@v9
31+
with:
32+
workflow: ${{ inputs.workflow-file }}
33+
workflow_conclusion: success
34+
branch: ${{ inputs.baseline-branch }}
35+
name: ${{ inputs.artifact-name }}
36+
path: previous-metrics
37+
if_no_artifact_found: warn
38+
39+
- name: Count warnings/errors and compare
40+
shell: bash
41+
run: |
42+
if [ -f "${{ inputs.log-file }}" ]; then
43+
warnings_count=$(grep -c "^\[WARNING\]" "${{ inputs.log-file }}" || true)
44+
errors_count=$(grep -c "^\[ERROR\]" "${{ inputs.log-file }}" || true)
45+
else
46+
warnings_count=9999999
47+
errors_count=9999999
48+
fi
49+
50+
previous_warnings=""
51+
previous_errors=""
52+
if [ -f previous-metrics/build-metrics.env ]; then
53+
# shellcheck disable=SC1091
54+
. previous-metrics/build-metrics.env
55+
previous_warnings="${WARNINGS:-}"
56+
previous_errors="${ERRORS:-}"
57+
fi
58+
59+
echo "full-build-base warnings: ${warnings_count}"
60+
echo "full-build-base errors: ${errors_count}"
61+
62+
regression=false
63+
if [ -n "${previous_warnings}" ] && [ -n "${previous_errors}" ]; then
64+
warnings_delta=$((warnings_count - previous_warnings))
65+
errors_delta=$((errors_count - previous_errors))
66+
echo "delta warnings vs last successful ${{ inputs.baseline-branch }} run: ${warnings_delta}"
67+
echo "delta errors vs last successful ${{ inputs.baseline-branch }} run: ${errors_delta}"
68+
if [ "${warnings_count}" -le "${previous_warnings}" ] && [ "${errors_count}" -le "${previous_errors}" ]; then
69+
echo "Result: green (no increase in warnings or errors)."
70+
else
71+
echo "Result: yellow (warnings or errors increased)."
72+
regression=true
73+
fi
74+
else
75+
echo "No previous metrics artifact found on ${{ inputs.baseline-branch }} for comparison."
76+
echo "Result: green (no baseline available)."
77+
fi
78+
79+
printf "WARNINGS=%s\nERRORS=%s\n" "${warnings_count}" "${errors_count}" > build-metrics.env
80+
81+
{
82+
echo "full-build-base warnings: ${warnings_count}"
83+
echo "full-build-base errors: ${errors_count}"
84+
if [ -n "${previous_warnings}" ] && [ -n "${previous_errors}" ]; then
85+
echo "delta warnings vs last successful ${{ inputs.baseline-branch }} run: ${warnings_delta}"
86+
echo "delta errors vs last successful ${{ inputs.baseline-branch }} run: ${errors_delta}"
87+
else
88+
echo "No previous metrics artifact found on ${{ inputs.baseline-branch }} for comparison."
89+
fi
90+
} >> "$GITHUB_STEP_SUMMARY"
91+
92+
if [ "${regression}" = "true" ]; then
93+
exit 1
94+
fi
95+
96+
- name: Upload current metrics artifact
97+
uses: actions/upload-artifact@v4
98+
with:
99+
name: ${{ inputs.artifact-name }}
100+
path: build-metrics.env
101+
retention-days: ${{ inputs.retention-days }}
102+
if-no-files-found: error

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,23 @@ jobs:
109109
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
110110
restore-keys: ${{ runner.os }}-m2
111111
- name: Build with Maven
112-
run: mvn clean verify --fae
112+
# the set command makes the build fail if mvn command fails (no change in behavior)
113+
run: |
114+
set -o pipefail
115+
mvn clean verify --fae 2>&1 | tee full-build-base.log
113116
env:
114117
CI_env: GithubAction
118+
- name: Analyze and persist full-build-base metrics
119+
if: success()
120+
continue-on-error: true
121+
uses: ./.github/actions/full-build-metrics
122+
with:
123+
log-file: full-build-base.log
124+
artifact-name: full-build-base-metrics
125+
baseline-branch: master
126+
workflow-file: ci.yml
127+
#These are metrics occupy very little space, increasing the retention so they are not lost if nothing is merged to master in a while
128+
retention-days: 90
115129
- name: Upload evomaster.jar
116130
uses: actions/upload-artifact@v4
117131
with:

0 commit comments

Comments
 (0)