|
5 | 5 | branches-ignore: |
6 | 6 | - '**' |
7 | 7 | pull_request: |
8 | | - branches: [main, dev, stage] |
| 8 | + branches: [ main, dev, stage ] |
9 | 9 |
|
10 | 10 | jobs: |
11 | 11 | UnitTest: |
12 | 12 | runs-on: ubuntu-latest |
13 | 13 |
|
14 | 14 | steps: |
15 | | - - name: Checkout code |
16 | | - uses: actions/checkout@v2 |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v2 |
17 | 17 |
|
18 | | - - name: Set up Python |
19 | | - uses: actions/setup-python@v2 |
20 | | - with: |
21 | | - python-version: '3.10' |
| 18 | + - name: Set up Python |
| 19 | + uses: actions/setup-python@v2 |
| 20 | + with: |
| 21 | + python-version: '3.10' |
22 | 22 |
|
23 | | - - name: Install dependencies |
24 | | - run: | |
25 | | - python -m pip install --upgrade pip |
26 | | - pip install -r requirements.txt |
| 23 | + - name: Install dependencies |
| 24 | + run: | |
| 25 | + python -m pip install --upgrade pip |
| 26 | + pip install -r requirements.txt |
27 | 27 |
|
28 | | - - name: Determine output folder |
29 | | - id: set_output_folder |
30 | | - run: | |
31 | | - if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then |
32 | | - branch_name=$GITHUB_BASE_REF |
33 | | - else |
34 | | - branch_name=$GITHUB_REF_NAME |
35 | | - fi |
| 28 | + - name: Determine output folder |
| 29 | + id: set_output_folder |
| 30 | + run: | |
| 31 | + if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then |
| 32 | + branch_name=$GITHUB_BASE_REF |
| 33 | + else |
| 34 | + branch_name=$GITHUB_REF_NAME |
| 35 | + fi |
| 36 | + |
| 37 | + if [[ $branch_name == "main" ]]; then |
| 38 | + echo "output_folder=prod" >> $GITHUB_ENV |
| 39 | + elif [[ $branch_name == "stage" ]]; then |
| 40 | + echo "output_folder=stage" >> $GITHUB_ENV |
| 41 | + elif [[ $branch_name == "dev" ]]; then |
| 42 | + echo "output_folder=dev" >> $GITHUB_ENV |
| 43 | + else |
| 44 | + echo "Unknown branch: $branch_name" |
| 45 | + exit 1 |
| 46 | + fi |
36 | 47 |
|
37 | | - if [[ $branch_name == "main" ]]; then |
38 | | - echo "output_folder=prod" >> $GITHUB_ENV |
39 | | - elif [[ $branch_name == "stage" ]]; then |
40 | | - echo "output_folder=stage" >> $GITHUB_ENV |
41 | | - elif [[ $branch_name == "dev" ]]; then |
42 | | - echo "output_folder=dev" >> $GITHUB_ENV |
43 | | - else |
44 | | - echo "Unknown branch: $branch_name" |
45 | | - exit 1 |
46 | | - fi |
| 48 | + - name: Run tests with coverage |
| 49 | + run: | |
| 50 | + timestamp=$(date '+%Y-%m-%d_%H-%M-%S') |
| 51 | + mkdir -p test_results |
| 52 | + log_file="test_results/${timestamp}_report.log" |
| 53 | + echo -e "\nTest Cases Report Report\n" >> $log_file |
| 54 | + # Run the tests and append output to the log file |
| 55 | + PYTHONPATH=$(pwd) python -m coverage run --source=src -m unittest discover -v tests/ >> $log_file 2>&1 |
| 56 | + echo -e "\nCoverage Report\n" >> $log_file |
| 57 | + coverage report >> $log_file |
| 58 | + coverage xml |
47 | 59 |
|
48 | | - - name: Run tests with coverage |
49 | | - run: | |
50 | | - timestamp=$(date '+%Y-%m-%d_%H-%M-%S') |
51 | | - mkdir -p test_results |
52 | | - log_file="test_results/${timestamp}_report.log" |
53 | | - echo -e "\nTest Cases Report Report\n" >> $log_file |
54 | | - # Run the tests and append output to the log file |
55 | | - PYTHONPATH=$(pwd) python -m coverage run --source=src -m unittest discover -v tests/ >> $log_file 2>&1 |
56 | | - echo -e "\nCoverage Report\n" >> $log_file |
57 | | - coverage report >> $log_file |
| 60 | + - name: Check coverage |
| 61 | + run: | |
| 62 | + coverage report --fail-under=85 |
58 | 63 |
|
59 | | - - name: Upload report to Azure |
60 | | - uses: LanceMcCarthy/Action-AzureBlobUpload@v2 |
61 | | - with: |
62 | | - source_folder: 'test_results' |
63 | | - destination_folder: '${{ env.output_folder }}' |
64 | | - connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} |
65 | | - container_name: 'osw-quality-metric-service' |
66 | | - clean_destination_folder: false |
67 | | - delete_if_exists: false |
| 64 | + - name: Upload report to Azure |
| 65 | + uses: LanceMcCarthy/Action-AzureBlobUpload@v2 |
| 66 | + with: |
| 67 | + source_folder: 'test_results' |
| 68 | + destination_folder: '${{ env.output_folder }}' |
| 69 | + connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} |
| 70 | + container_name: 'osw-quality-metric-service' |
| 71 | + clean_destination_folder: false |
| 72 | + delete_if_exists: false |
0 commit comments