Stage to Prod #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Unit Tests | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches-ignore: | |
| - '**' | |
| pull_request: | |
| branches: [ main, dev, stage ] | |
| jobs: | |
| UnitTest: | |
| runs-on: ubuntu-latest | |
| env: | |
| DATABASE_NAME: test_database | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Determine output folder | |
| id: set_output_folder | |
| run: | | |
| if [[ $GITHUB_EVENT_NAME == "pull_request" ]]; then | |
| branch_name=$GITHUB_BASE_REF | |
| else | |
| branch_name=$GITHUB_REF_NAME | |
| fi | |
| if [[ $branch_name == "main" ]]; then | |
| echo "output_folder=prod" >> $GITHUB_ENV | |
| elif [[ $branch_name == "stage" ]]; then | |
| echo "output_folder=stage" >> $GITHUB_ENV | |
| elif [[ $branch_name == "dev" ]]; then | |
| echo "output_folder=dev" >> $GITHUB_ENV | |
| else | |
| echo "Unknown branch: $branch_name" | |
| exit 1 | |
| fi | |
| - name: Run tests with coverage | |
| run: | | |
| timestamp=$(date '+%Y-%m-%d_%H-%M-%S') | |
| mkdir -p test_results | |
| log_file="test_results/${timestamp}_report.log" | |
| echo -e "\nTest Cases Report Report\n" >> $log_file | |
| # Run the tests and append output to the log file | |
| python -m coverage run --source=src -m unittest discover -s tests/unit_tests >> $log_file 2>&1 | |
| echo -e "\nCoverage Report\n" >> $log_file | |
| coverage report >> $log_file | |
| - name: Check coverage | |
| run: | | |
| coverage report --fail-under=85 | |
| - name: Upload report to Azure | |
| uses: LanceMcCarthy/Action-AzureBlobUpload@v2 | |
| with: | |
| source_folder: 'test_results' | |
| destination_folder: '${{ env.output_folder }}' | |
| connection_string: ${{ secrets.AZURE_STORAGE_CONNECTION_STRING }} | |
| container_name: 'osw-validation-service ' | |
| clean_destination_folder: false | |
| delete_if_exists: false | |