diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8ba10b3..f3c0eb5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,95 +25,53 @@ jobs: python-version: ["3.12"] steps: - - uses: actions/checkout@v4 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - check-latest: true - - - name: Install Java, GDAL, and other system dependencies - run: | - sudo apt update - sudo apt-get install libxml2-dev libpq-dev openjdk-8-jdk libgdal-dev libxslt-dev - echo Postgres and ES dependencies installed - - - name: Install python packages - run: | - python -m pip install --upgrade pip - pip install . - pip install -r ${{ github.event.repository.name }}/install/requirements.txt - pip install -r ${{ github.event.repository.name }}/install/requirements_dev.txt - echo Python packages installed - - - uses: ankane/setup-elasticsearch@v1 - with: - elasticsearch-version: 8 - - - name: Check for missing migrations - run: | - python manage.py makemigrations --check - - - name: Run unit tests - run: | - python -W default::DeprecationWarning -m coverage run manage.py test tests --pattern="*.py" --settings="tests.test_settings" - - - name: Generate report coverage - run: | - coverage json - - - name: Upload coverage report as artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ github.event.pull_request.head.ref }}-coverage-report - path: coverage.json - overwrite: true - - check-coverage: - needs: [build] - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' # Use the latest available version - check-latest: true - - - name: Download current branch coverage report artifact - uses: actions/download-artifact@v4 + - <<: *foo-steps with: - name: ${{ github.event.pull_request.head.ref }}-coverage-report - path: . - - - name: Report coverage - run: | - cat coverage.json - - - name: Rename coverage.json -> current_branch_coverage.json - run: | - mv coverage.json current_branch_coverage.json - - - name: Download target branch coverage report artifact - uses: actions/download-artifact@v4 - with: - name: ${{ github.event.pull_request.base.ref }}-coverage-report - github-token: ${{ secrets.GH_PAT }} - path: . - - - name: Compare coverage with baseline - if: github.event_name == 'pull_request' - run: | - current_coverage=$(cat current_branch_coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}') - target_coverage=$(cat coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}') - - # Compare current coverage with target coverage using floating-point comparison - if awk -v current="$current_coverage" -v baseline="$baseline_coverage" 'BEGIN { exit (current < baseline) ? 0 : 1 }'; then - echo "Coverage decreased from $baseline_coverage% to $current_coverage%" - exit 1 - else - echo "$baseline_coverage% == $current_coverage%, Coverage didn't decrease." - fi + branch: ${{ github.event.pull_request.head.ref }} + + +foo-steps: &foo-steps + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + check-latest: true + + - name: Install Java, GDAL, and other system dependencies + run: | + sudo apt update + sudo apt-get install libxml2-dev libpq-dev openjdk-8-jdk libgdal-dev libxslt-dev + echo Postgres and ES dependencies installed + + - name: Install python packages + run: | + python -m pip install --upgrade pip + pip install . + pip install -r ${{ github.event.repository.name }}/install/requirements.txt + pip install -r ${{ github.event.repository.name }}/install/requirements_dev.txt + echo Python packages installed + + - uses: ankane/setup-elasticsearch@v1 + with: + elasticsearch-version: 8 + + - name: Check for missing migrations + run: | + python manage.py makemigrations --check + + - name: Run unit tests + run: | + python -W default::DeprecationWarning -m coverage run manage.py test tests --pattern="*.py" --settings="tests.test_settings" + + - name: Generate report coverage + run: | + coverage json + + - name: Upload coverage report as artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ github.event.pull_request.head.ref }}-coverage-report + path: coverage.json + overwrite: true \ No newline at end of file