Skip to content

Commit 2eaaf67

Browse files
Copilotjason810496
andcommitted
Fix coverage report race condition with separate upload job
Co-authored-by: jason810496 <[email protected]>
1 parent 4bf25ff commit 2eaaf67

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

.github/workflows/codecov.yml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
branches: [main, develop]
1010

1111
jobs:
12-
build:
12+
test:
1313

1414
runs-on: ubuntu-latest
1515
strategy:
@@ -34,14 +34,11 @@ jobs:
3434
echo "$HOME/.local/bin" >> $GITHUB_PATH
3535
- name: Install dependencies
3636
run: uv sync --extra dev
37-
- name: Start PostgreSQL (first time only)
37+
- name: Start PostgreSQL
3838
run: |
39-
# Only start if not already running
40-
if ! docker ps | grep -q pgmq_postgres; then
41-
cp pgmq_postgres.template.env pgmq_postgres.env
42-
cp pgmq_tests.template.env pgmq_tests.env
43-
make start-db
44-
fi
39+
cp pgmq_postgres.template.env pgmq_postgres.env
40+
cp pgmq_tests.template.env pgmq_tests.env
41+
make start-db
4542
- name: Setup unique database for this test run
4643
run: |
4744
# Normalize database name (remove dots and hyphens)
@@ -58,15 +55,40 @@ jobs:
5855
# Normalize database name (remove dots and hyphens)
5956
export DB_NAME=$(echo "$DB_NAME_RAW" | sed 's/\.//g' | sed 's/-/_/g')
6057
61-
uv run pytest tests --driver=${{ matrix.driver }} --db-name=${DB_NAME} --cov=pgmq_sqlalchemy.queue --cov-report=xml
58+
# Create unique coverage file name
59+
export COVERAGE_FILE=".coverage.py${{ matrix.python-version }}.${{ matrix.driver }}"
60+
61+
uv run pytest tests --driver=${{ matrix.driver }} --db-name=${DB_NAME} --cov=pgmq_sqlalchemy.queue --cov-report=xml:coverage-py${{ matrix.python-version }}-${{ matrix.driver }}.xml
6262
continue-on-error: true
63-
- name: Upload coverage reports to Codecov with GitHub Action
64-
uses: codecov/[email protected]
65-
env:
66-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
63+
- name: Upload coverage artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: coverage-py${{ matrix.python-version }}-${{ matrix.driver }}
67+
path: coverage-py${{ matrix.python-version }}-${{ matrix.driver }}.xml
68+
retention-days: 1
6769
- name: Cleanup database
6870
if: always()
6971
run: |
7072
# Normalize database name (remove dots and hyphens)
7173
export DB_NAME=$(echo "$DB_NAME_RAW" | sed 's/\.//g' | sed 's/-/_/g')
72-
docker compose exec -T pgmq_postgres psql -U postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};" || true
74+
docker compose exec -T pgmq_postgres psql -U postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};" || true
75+
76+
upload-coverage:
77+
needs: test
78+
runs-on: ubuntu-latest
79+
name: Upload coverage to Codecov
80+
steps:
81+
- uses: actions/checkout@v4
82+
- name: Download all coverage artifacts
83+
uses: actions/download-artifact@v4
84+
with:
85+
path: coverage-reports
86+
pattern: coverage-*
87+
merge-multiple: true
88+
- name: Upload coverage reports to Codecov
89+
uses: codecov/[email protected]
90+
with:
91+
directory: ./coverage-reports
92+
fail_ci_if_error: false
93+
env:
94+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)