1010jobs :
1111 UnitTest :
1212 runs-on : ubuntu-latest
13-
1413 env :
1514 DATABASE_NAME : test_database
1615
1716 steps :
1817 - name : Checkout code
19- uses : actions/checkout@v2
18+ uses : actions/checkout@v4
2019
2120 - name : Set up Python
22- uses : actions/setup-python@v2
21+ uses : actions/setup-python@v5
2322 with :
2423 python-version : ' 3.10'
2524
@@ -30,46 +29,60 @@ jobs:
3029
3130 - name : Determine output folder
3231 id : set_output_folder
32+ shell : bash
3333 run : |
34- if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then
35- branch_name=$GITHUB_BASE_REF
36- else
37- branch_name=$GITHUB_REF_NAME
38- fi
39-
40- if [[ $branch_name == "main" ]]; then
41- echo "output_folder=prod" >> $GITHUB_ENV
42- elif [[ $branch_name == "stage" ]]; then
43- echo "output_folder=stage" >> $GITHUB_ENV
44- elif [[ $branch_name == "dev" ]]; then
45- echo "output_folder=dev" >> $GITHUB_ENV
34+ if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
35+ branch_name="$GITHUB_BASE_REF"
4636 else
47- echo "Unknown branch: $branch_name"
48- exit 1
37+ branch_name="$GITHUB_REF_NAME"
4938 fi
5039
51- - name : Run tests with coverage
40+ case "$branch_name" in
41+ main) echo "output_folder=prod" >> "$GITHUB_ENV" ;;
42+ stage) echo "output_folder=stage" >> "$GITHUB_ENV" ;;
43+ dev) echo "output_folder=dev" >> "$GITHUB_ENV" ;;
44+ *) echo "Unknown branch: $branch_name"; exit 1 ;;
45+ esac
46+
47+ - name : Run tests with coverage (show failures in logs)
48+ shell : bash
5249 run : |
53- timestamp=$(date '+%Y-%m-%d_%H-%M-%S')
50+ set -o pipefail
51+ timestamp="$(date '+%Y-%m-%d_%H-%M-%S')"
5452 mkdir -p test_results
5553 log_file="test_results/${timestamp}_report.log"
56- echo -e "\nTest Cases Report Report\n" >> $log_file
57- # Run the tests and append output to the log file
58- python -m coverage run --source=src -m unittest discover -s tests/unit_tests >> $log_file 2>&1
59- echo -e "\nCoverage Report\n" >> $log_file
60- coverage report >> $log_file
54+
55+ {
56+ echo
57+ echo "Test Cases Report"
58+ echo
59+ } | tee -a "$log_file"
60+
61+ # Run unittest in verbose mode; mirror output to console and file
62+ python -m coverage run --source=src -m unittest discover -s tests/unit_tests -v 2>&1 | tee -a "$log_file"
63+ test_status=${PIPESTATUS[0]}
64+
65+ echo -e "\nCoverage Report\n" | tee -a "$log_file"
66+ coverage report 2>&1 | tee -a "$log_file"
67+
68+ exit $test_status
6169
6270 - name : Check coverage
63- run : |
64- coverage report --fail-under=85
71+ run : coverage report --fail-under=85
72+
73+ # Optional: keep the log as a build artifact for easy download
74+ - name : Upload test log artifact
75+ uses : actions/upload-artifact@v4
76+ with :
77+ name : unit-test-log
78+ path : test_results/
6579
6680 - name : Upload report to Azure
6781 uses : LanceMcCarthy/Action-AzureBlobUpload@v2
6882 with :
6983 source_folder : ' test_results'
7084 destination_folder : ' ${{ env.output_folder }}'
7185 connection_string : ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}
72- container_name : ' osw-validation-service '
86+ container_name : ' osw-validation-service'
7387 clean_destination_folder : false
7488 delete_if_exists : false
75-
0 commit comments