Skip to content

Bugfix 3726

Bugfix 3726 #61

Workflow file for this run

name: Unit Tests
on:
workflow_dispatch:
push:
branches-ignore:
- '**'
pull_request:
branches: [ main, develop ]
jobs:
UnitTest:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Updating and installing GDAL
run: |
sudo apt update
sudo apt install gdal-bin libgdal-dev python3-gdal
- 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 GDAL==3.4.1
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 == "develop" ]]; 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/osm_osw_reformatter -m unittest discover -v 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: Generate coverage badge
run: |
pip install coverage-badge
mkdir -p badge-out
coverage-badge -f -o badge-out/coverage.svg
- name: Publish coverage badge to badges branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
cp badge-out/coverage.svg /tmp/coverage.svg
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch origin badges || true
if git show-ref --verify --quiet refs/remotes/origin/badges; then
git checkout badges
else
git checkout --orphan badges
git rm -rf . >/dev/null 2>&1 || true
fi
cp /tmp/coverage.svg coverage.svg
git add coverage.svg
if ! git diff --cached --quiet; then
git commit -m "chore: update coverage badge"
git push "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" HEAD:badges
else
echo "No badge changes to commit."
fi
- 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: 'osm-osw-reformatter-package'
clean_destination_folder: false
delete_if_exists: false