From ec2dab863531ed0e49aac45049e09acfadb4b9fa Mon Sep 17 00:00:00 2001 From: Christopher Byrd Date: Mon, 29 Apr 2024 15:43:53 -0700 Subject: [PATCH] nit --- .github/workflows/main.yml | 144 +++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3761389..ce03dd4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,14 +6,15 @@ on: workflow_dispatch: jobs: - build: + build_feature_branch: runs-on: ubuntu-latest + services: postgres: image: postgis/postgis:13-3.0 env: POSTGRES_PASSWORD: postgis - POSTGRES_DB: arches_rdm_example_project + POSTGRES_DB: ${{ github.event.repository.name }} ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 @@ -25,6 +26,7 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -41,10 +43,89 @@ jobs: run: | python -m pip install --upgrade pip pip install . - pip install -r arches_rdm_example_project/install/requirements.txt - pip install -r arches_rdm_example_project/install/requirements_dev.txt + 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: Webpack frontend files + run: | + echo "Removing yarn.lock due to yarn v1 package resolution issues" + echo "https://github.com/iarna/wide-align/issues/63" + rm yarn.lock + yarn && yarn build_test + + - name: Check for missing migrations + run: | + python manage.py makemigrations --check + + - name: Ensure previous coverage data is erased + run: | + coverage erase + + - name: Run unit tests + run: | + python -W default::DeprecationWarning -m coverage run manage.py test tests --settings="tests.test_settings" + + - name: Generate report coverage + run: | + coverage report + coverage json + mv coverage.json feature_branch_coverage.json + + - name: Upload coverage report as artifact + uses: actions/upload-artifact@v4 + with: + name: feature-branch-coverage-report + path: feature_branch_coverage.json + overwrite: true + + build_target_branch: + runs-on: ubuntu-latest + + services: + postgres: + image: postgis/postgis:13-3.0 + env: + POSTGRES_PASSWORD: postgis + POSTGRES_DB: ${{ github.event.repository.name }} + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + strategy: + fail-fast: false + matrix: + # python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.base.ref }} + + - 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: @@ -61,10 +142,61 @@ jobs: run: | python manage.py makemigrations --check - - name: Run Arches unit tests + - name: Ensure previous coverage data is erased + run: | + coverage erase + + - name: Run unit tests run: | python -W default::DeprecationWarning -m coverage run manage.py test tests --settings="tests.test_settings" - - name: Report coverage + - name: Generate report coverage run: | coverage report + coverage json + mv coverage.json target_branch_coverage.json + + - name: Upload coverage report as artifact + uses: actions/upload-artifact@v4 + with: + name: target-branch-coverage-report + path: target_branch_coverage.json + overwrite: true + + check_coverage: + runs-on: ubuntu-latest + needs: [build_feature_branch, build_target_branch] + 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 feature branch coverage report artifact + uses: actions/download-artifact@v4 + with: + name: feature-branch-coverage-report + path: . + + - name: Download target branch coverage report artifact + uses: actions/download-artifact@v4 + with: + name: target-branch-coverage-report + path: . + + - name: Compare coverage with baseline + if: github.event_name == 'pull_request' + run: | + feature_branch_coverage=$(cat feature_branch_coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}') + target_branch_coverage=$(cat target_branch_coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}') + + # Compare current coverage with baseline coverage using floating-point comparison + if awk -v feature="$feature_branch_coverage" -v target="$target_branch_coverage" 'BEGIN { exit (feature < target) ? 0 : 1 }'; then + echo "Coverage decreased from $target_branch_coverage% to $feature_branch_coverage%" + exit 1 + else + echo "Feature branch coverage ($feature_branch_coverage%) >= Target branch coverage ($target_branch_coverage%)." + fi