Skip to content

Commit a844855

Browse files
authored
UID2-3858 verify no of tests run (#141)
* Add check for the number of tests run * Add tests for number of tests run * Extract scripts * Add checkout uid2-shared-actions step * Exit when tests_run doesn't have value * Use parameter to pass in values * Change kcc-UID2-3858-verify-no-of-tests-run to v3
1 parent 9305ba2 commit a844855

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

.github/workflows/shared-build-and-test.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ jobs:
2828
steps:
2929
- name: Checkout repo
3030
uses: actions/checkout@v4
31+
32+
- name: Checkout uid2-shared-actions repo
33+
uses: actions/checkout@v4
34+
with:
35+
ref: v3
36+
repository: IABTechLab/uid2-shared-actions
37+
path: uid2-shared-actions
3138

3239
- name: Set up JDK
3340
if: ${{ inputs.vulnerability_scan_only == 'false' }}
@@ -38,8 +45,9 @@ jobs:
3845

3946
- name: Build and run unit tests
4047
if: ${{ inputs.vulnerability_scan_only == 'false' }}
41-
run: mvn -B clean compile test
4248
working-directory: ${{ inputs.working_dir }}
49+
run: |
50+
bash uid2-shared-actions/scripts/compile_java_test_and_verify.sh
4351
4452
- name: Generate code coverage
4553
if: ${{ inputs.vulnerability_scan_only == 'false' }}

.github/workflows/shared-publish-to-maven-versioned.yaml

+10-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ jobs:
5959
with:
6060
fetch-depth: 0
6161

62+
- name: Checkout uid2-shared-actions repo
63+
uses: actions/checkout@v4
64+
with:
65+
ref: v3
66+
repository: IABTechLab/uid2-shared-actions
67+
path: uid2-shared-actions
68+
6269
- name: Set up JDK
6370
uses: actions/setup-java@v4
6471
with:
@@ -113,9 +120,11 @@ jobs:
113120
114121
- name: Compile
115122
if: ${{ inputs.publish_to_maven != true }}
123+
env:
124+
EXTRA_FLAGS: "-s settings.xml -Dgpg.passphrase=\"${{ secrets.GPG_PASSPHRASE }}\""
116125
run: |
117126
cd ./${{ inputs.working_dir }}
118-
mvn -B -s settings.xml -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" clean compile test
127+
bash uid2-shared-actions/scripts/compile_java_test_and_verify.sh -s settings.xml -D gpg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
119128
120129
- name: Commit pom.xml and version.json
121130
if: ${{ steps.checkRelease.outputs.is_release != 'true' }}
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
# Function to display usage instructions
4+
usage() {
5+
echo "Usage: $0 [-s SETTINGS_FILE] [-D NAME=VALUE]"
6+
echo " -s SETTINGS_FILE Specify Maven settings file"
7+
echo " -D NAME=VALUE Set a system property (can be used multiple times)"
8+
echo "Any remaining arguments will be passed directly to Maven."
9+
exit 1
10+
}
11+
12+
# Initialize variables
13+
settings_file=""
14+
system_properties=() # Use an array for multiple -D options
15+
16+
# Parse command-line options
17+
while getopts "s:D:" opt; do
18+
case $opt in
19+
s)
20+
settings_file="-s $OPTARG"
21+
;;
22+
D)
23+
system_properties+=("-D$OPTARG")
24+
;;
25+
\?)
26+
echo "Invalid option: -$OPTARG" >&2
27+
usage
28+
;;
29+
:)
30+
echo "Option -$OPTARG requires an argument." >&2
31+
usage
32+
;;
33+
esac
34+
done
35+
36+
# Shift off the processed options, leaving only the remaining arguments
37+
shift "$((OPTIND-1))"
38+
39+
# Construct Maven command
40+
mvn_command="mvn -B ${settings_file}"
41+
42+
# Add system properties to the command
43+
for prop in "${system_properties[@]}"; do
44+
mvn_command+=" ${prop}"
45+
done
46+
47+
# Append any remaining arguments to the Maven command
48+
mvn_command+=" $@"
49+
50+
# Add the fixed part of the Maven command
51+
mvn_command+=" clean compile test"
52+
53+
echo "DEBUG: Executing Maven command: ${mvn_command}"
54+
${mvn_command} | tee build.log
55+
56+
tests_run=$(cat build.log | grep "Tests run:" | tail -n 1 | sed 's/.*Tests run: \([0-9]*\).*/\1/')
57+
58+
echo "DEBUG: tests_run = $tests_run"
59+
60+
if [ -z "$tests_run" ]; then
61+
echo "WARNING: Could not determine the number of tests run."
62+
exit 1
63+
fi
64+
65+
if [ "$tests_run" -eq 0 ]; then
66+
echo "ERROR: No tests were run!"
67+
exit 1
68+
fi
69+
70+
echo "INFO: $tests_run tests were run!"

0 commit comments

Comments
 (0)