Skip to content

Commit b77c86d

Browse files
committed
code coverage: simplified caching, JaCoCo ver as env var
Motivation: To improve maintainability and caching efficiency, the JaCoCo version is now configurable via an environment variable in build.yml, eliminating hardcoded values in scripts. The cache configuration was also updated to align paths and simplify version management. Modifications: Added JACOCO_VERSION as an environment variable in build.yml and updated both scripts (get-jacoco.sh and generate-jacoco-report.sh) to use it. Simplified the cache path and key in build.yml to depend on the environment variable, ensuring the cache is only invalidated when the version changes. Results: The JaCoCo version can now be updated in a single location, ensuring consistency across scripts and cache keys. The cache reliably restores the JaCoCo CLI when the version remains unchanged, reducing CI runtime. Testing: Validated locally and in CI by confirming the correct JaCoCo version is used in scripts and that the cache behaves as expected. Acked-by: Target: master Require-book: no Require-notes: no Committed:
1 parent 4e2eca2 commit b77c86d

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
pull_request:
66
types: [opened, reopened]
77

8+
env:
9+
JACOCO_VERSION: "0.8.14"
10+
811
jobs:
912
build:
1013
runs-on: ubuntu-latest
@@ -22,10 +25,8 @@ jobs:
2225
id: cache-jacoco
2326
uses: actions/cache@v4
2427
with:
25-
path: ~/jacoco-0.8.14
26-
key: ${{ runner.os }}-jacoco-cli-${{ hashFiles('generate-jacoco-report.sh') }}
27-
restore-keys: |
28-
${{ runner.os }}-jacoco-cli-
28+
path: ${{ github.workspace }}/jacoco-${{ env.JACOCO_VERSION }}
29+
key: ${{ runner.os }}-jacoco-cli-${{ env.JACOCO_VERSION }}
2930

3031
- name: Build with Maven
3132
run: mvn --batch-mode --update-snapshots package

generate-jacoco-report.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Define paths
44
PROJECT_ROOT="${PROJECT_ROOT:-$(pwd)}"
5-
JACOCO_VERSION="0.8.14"
5+
JACOCO_VERSION="${JACOCO_VERSION:-0.8.14}" #fallback to 0.8.14 if env var is unset
66
JACOCO_DIR="${PROJECT_ROOT}/jacoco-$JACOCO_VERSION"
77
JACOCO_CLI_JAR="$JACOCO_DIR/lib/jacococli.jar"
88
MERGED_EXEC="$PROJECT_ROOT/target/coverage-reports/merged.exec"

get-jacoco.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
# Define paths
44
PROJECT_ROOT="${PROJECT_ROOT:-$(pwd)}"
5-
JACOCO_VERSION="0.8.14"
5+
JACOCO_VERSION="${JACOCO_VERSION:-0.8.14}" #fallback to 0.8.14 if env var is unset
66
JACOCO_DIR="${PROJECT_ROOT}/jacoco-$JACOCO_VERSION"
77
JACOCO_CLI_JAR="$JACOCO_DIR/lib/jacococli.jar"
88

9-
# Debug: Print paths
10-
echo "DEBUG: JACOCO_CLI_JAR: $JACOCO_CLI_JAR"
119
echo "DEBUG: Checking if $JACOCO_CLI_JAR exists..."
1210

1311
# Check if JaCoCo CLI JAR exists in the cache directory

0 commit comments

Comments
 (0)