Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 85 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,30 +338,22 @@ jobs:
env:
TOOLKIT_VERSION: ${{ steps.version.outputs.VERSION }}
PYTHON_VERSION: ${{ matrix.python-version }}
COVERAGE_FILE: coverage/.coverage.${{ matrix.python-version }}
COVERAGE_FILE: .coverage.${{ matrix.python-version }}
run: |
set -euo pipefail

# Create coverage directory
mkdir -p coverage

# Run tests with coverage
poetry run pytest tests/unit \
--cov=deepnote_toolkit \
--cov=installer \
--cov=deepnote_core \
--cov-branch \
--cov-report=term-missing:skip-covered \
--cov-report=xml:coverage/coverage-${PYTHON_VERSION}.xml \
--cov-report=json:coverage/coverage-${PYTHON_VERSION}.json \
--junitxml=junit.xml \
-o junit_family=legacy

# Check if coverage file was generated
if [ -f "coverage/.coverage.${PYTHON_VERSION}" ]; then
if [ -f ".coverage.${PYTHON_VERSION}" ]; then
echo "coverage_generated=true" >> $GITHUB_OUTPUT
echo "Coverage files found:"
ls -la coverage/
else
echo "coverage_generated=false" >> $GITHUB_OUTPUT
echo "Warning: No coverage file generated"
Expand All @@ -373,7 +365,7 @@ jobs:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
echo "## Python ${PYTHON_VERSION} Coverage" >> $GITHUB_STEP_SUMMARY
poetry run coverage report --data-file=coverage/.coverage.${PYTHON_VERSION} --format=markdown >> $GITHUB_STEP_SUMMARY
poetry run coverage report --data-file=.coverage.${PYTHON_VERSION} --format=markdown >> $GITHUB_STEP_SUMMARY

- name: Upload test results to Codecov (these are results not coverage reports)
if: ${{ !cancelled() }}
Expand All @@ -382,14 +374,93 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
flags: python-${{ matrix.python-version }}

- name: Upload coverage to Codecov
- name: Upload coverage artifacts
if: steps.test-unit.outputs.coverage_generated == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: coverage-${{ matrix.python-version }}
path: .coverage.${{ matrix.python-version }}
retention-days: 1

coverage-combine:
name: Combine and Upload Coverage
runs-on: ubuntu-latest
needs: tests-unit
if: always()
steps:
- name: Checkout code
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: '3.11'

- name: Install coverage
run: pip install coverage[toml]

- name: Download all coverage artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
continue-on-error: true
with:
pattern: coverage-*
path: coverage-data/
merge-multiple: true

- name: Combine coverage files
id: combine
run: |
set -euo pipefail

if [ ! -d "coverage-data" ] || [ -z "$(ls -A coverage-data 2>/dev/null)" ]; then
echo "No coverage artifacts were downloaded. All tests may have failed before generating coverage."
echo "success=false" >> $GITHUB_OUTPUT
exit 0
fi

echo "Downloaded coverage files:"
ls -la coverage-data/

shopt -s nullglob
coverage_files=(coverage-data/.coverage.*)
if [ ${#coverage_files[@]} -eq 0 ]; then
echo "No .coverage.* files found to combine"
echo "success=false" >> $GITHUB_OUTPUT
exit 0
fi

echo "Found ${#coverage_files[@]} coverage file(s) to combine"

cd coverage-data
coverage combine
coverage xml -o coverage.xml
coverage report

echo "## Combined Coverage Report" >> $GITHUB_STEP_SUMMARY
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY

echo "success=true" >> $GITHUB_OUTPUT

- name: Upload combined coverage to Codecov
if: steps.combine.outputs.success == 'true'
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: deepnote/deepnote-toolkit
files: ./coverage/coverage-${{ matrix.python-version }}.xml
slug: ${{ github.repository }}
files: ./coverage-data/coverage.xml
flags: combined
fail_ci_if_error: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' }}

- name: Upload combined coverage report
if: steps.combine.outputs.success == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: coverage-combined-report
path: coverage-data/coverage.xml
retention-days: 30

audit-prod:
name: Audit - Production
runs-on: ubuntu-latest
Expand Down
Loading