From 06ede6c0b82404fee7f654d670b0f3ba5863557e Mon Sep 17 00:00:00 2001 From: Tatiana Al-Chueyr Date: Tue, 15 Aug 2023 20:56:30 +0100 Subject: [PATCH] Change CI to run coverage after tests pass (#461) There are two benefits to this change: 1. The CI will wait for all the coverage to be collected, avoiding failing a build incorrectly because of code coverage that was not collected yet 2. Fewer requests to the third-party `codecov` service - we only worry about code coverage when/if tests pass --- .github/workflows/test.yml | 60 ++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f5f9d56c..b412df1c0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,10 +55,11 @@ jobs: run: | hatch run tests.py${{ matrix.python-version }}-${{ matrix.airflow-version }}:test-cov - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Upload coverage to Github + uses: actions/upload-artifact@v2 with: - token: ${{ secrets.CODECOV_TOKEN }} + name: coverage-unit-test-${{ matrix.python-version }}-${{ matrix.airflow-version }} + path: .coverage Run-Integration-Tests: needs: Authorize @@ -115,10 +116,11 @@ jobs: DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }} COSMOS_CONN_POSTGRES_PASSWORD: ${{ secrets.COSMOS_CONN_POSTGRES_PASSWORD }} - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + - name: Upload coverage to Github + uses: actions/upload-artifact@v2 with: - token: ${{ secrets.CODECOV_TOKEN }} + name: coverage-integration-test-${{ matrix.python-version }}-${{ matrix.airflow-version }} + path: .coverage @@ -154,9 +156,6 @@ jobs: .nox key: integration-expensive-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.airflow-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('cosmos/__init__.py') }} - - name: Checkout pull/${{ github.event.number }} - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -182,7 +181,50 @@ jobs: DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }} COSMOS_CONN_POSTGRES_PASSWORD: ${{ secrets.COSMOS_CONN_POSTGRES_PASSWORD }} + - name: Upload coverage to Github + uses: actions/upload-artifact@v2 + with: + name: coverage-integration-expensive-test-${{ matrix.python-version }}-${{ matrix.airflow-version }} + path: .coverage + + env: + AIRFLOW_HOME: /home/runner/work/astronomer-cosmos/astronomer-cosmos/ + AIRFLOW_CONN_AIRFLOW_DB: postgres://postgres:postgres@0.0.0.0:5432/postgres + PYTHONPATH: /home/runner/work/astronomer-cosmos/astronomer-cosmos/:$PYTHONPATH + AIRFLOW_CONN_DATABRICKS_DEFAULT: ${{ secrets.AIRFLOW_CONN_DATABRICKS_DEFAULT }} + DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }} + DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} + DATABRICKS_WAREHOUSE_ID: ${{ secrets.DATABRICKS_WAREHOUSE_ID }} + DATABRICKS_CLUSTER_ID: ${{ secrets.DATABRICKS_CLUSTER_ID }} + + Code-Coverage: + if: github.event.action != 'labeled' + needs: + - Run-Unit-Tests + - Run-Integration-Tests + - Run-Integration-Tests-Expensive + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: '3.10' + - name: Install coverage + run: | + pip3 install coverage + - name: Download all coverage artifacts + uses: actions/download-artifact@v2 + with: + path: ./coverage + - name: Combine coverage + run: | + coverage combine ./coverage/coverage*/.coverage + coverage report + coverage xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: + fail_ci_if_error: true token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml