Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/shared-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Checkout uid2-shared-actions repo
uses: actions/checkout@v4
with:
ref: kcc-UID2-3858-verify-no-of-tests-run
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to v3 before merging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the checkout of the repo necessary? Is it possible to use a reusable workflow instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was required for testing. Keep it here as Abu is doing some refactoring laster on so that we don't need to specify the branch name every where when we are testing in the future.

repository: IABTechLab/uid2-shared-actions
path: uid2-shared-actions

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

- name: Build and run unit tests
if: ${{ inputs.vulnerability_scan_only == 'false' }}
run: mvn -B clean compile test
working-directory: ${{ inputs.working_dir }}
run: |
bash uid2-shared-actions/scripts/compile_java_test_and_verify.sh

- name: Generate code coverage
if: ${{ inputs.vulnerability_scan_only == 'false' }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/shared-publish-to-maven-versioned.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ jobs:
with:
fetch-depth: 0

- name: Checkout uid2-shared-actions repo
uses: actions/checkout@v4
with:
ref: kcc-UID2-3858-verify-no-of-tests-run
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to v3 before merging

repository: IABTechLab/uid2-shared-actions
path: uid2-shared-actions

- name: Set up JDK
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -113,9 +120,11 @@ jobs:

- name: Compile
if: ${{ inputs.publish_to_maven != true }}
env:
EXTRA_FLAGS: "-s settings.xml -Dgpg.passphrase=\"${{ secrets.GPG_PASSPHRASE }}\""
run: |
cd ./${{ inputs.working_dir }}
mvn -B -s settings.xml -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" clean compile test
bash uid2-shared-actions/scripts/compile_java_test_and_verify.sh -s settings.xml -D gpg.passphrase="${{ secrets.GPG_PASSPHRASE }}"

- name: Commit pom.xml and version.json
if: ${{ steps.checkRelease.outputs.is_release != 'true' }}
Expand Down
70 changes: 70 additions & 0 deletions scripts/compile_java_test_and_verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash

# Function to display usage instructions
usage() {
echo "Usage: $0 [-s SETTINGS_FILE] [-D NAME=VALUE]"
echo " -s SETTINGS_FILE Specify Maven settings file"
echo " -D NAME=VALUE Set a system property (can be used multiple times)"
echo "Any remaining arguments will be passed directly to Maven."
exit 1
}

# Initialize variables
settings_file=""
system_properties=() # Use an array for multiple -D options

# Parse command-line options
while getopts "s:D:" opt; do
case $opt in
s)
settings_file="-s $OPTARG"
;;
D)
system_properties+=("-D$OPTARG")
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done

# Shift off the processed options, leaving only the remaining arguments
shift "$((OPTIND-1))"

# Construct Maven command
mvn_command="mvn -B ${settings_file}"

# Add system properties to the command
for prop in "${system_properties[@]}"; do
mvn_command+=" ${prop}"
done

# Append any remaining arguments to the Maven command
mvn_command+=" $@"

# Add the fixed part of the Maven command
mvn_command+=" clean compile test"

echo "DEBUG: Executing Maven command: ${mvn_command}"
${mvn_command} | tee build.log

tests_run=$(cat build.log | grep "Tests run:" | tail -n 1 | sed 's/.*Tests run: \([0-9]*\).*/\1/')

echo "DEBUG: tests_run = $tests_run"

if [ -z "$tests_run" ]; then
echo "WARNING: Could not determine the number of tests run."
exit 1
fi

if [ "$tests_run" -eq 0 ]; then
echo "ERROR: No tests were run!"
exit 1
fi

echo "INFO: $tests_run tests were run!"
Loading