Skip to content

Commit 04e0a54

Browse files
chore: split unit tests from the main CI workflow and report combined coverage to Coveralls (#425)
1 parent c4d3188 commit 04e0a54

File tree

4 files changed

+186
-76
lines changed

4 files changed

+186
-76
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,19 @@ jobs:
3030
echo "::notice::CI checks will execute - the actor is not the release-please bot"
3131
fi
3232
33-
tests:
33+
code-quality:
3434
needs: should-run
3535
if: needs.should-run.outputs.run == 'true'
3636
runs-on: ubuntu-latest
37-
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }} + Doctrine Lexer ${{ matrix.doctrine-lexer }}"
38-
strategy:
39-
fail-fast: false
40-
matrix:
41-
php: ['8.1', '8.2', '8.3', '8.4']
42-
doctrine-lexer: ['2.1', '3.0', 'latest']
43-
doctrine-orm: ['2.14', '2.18', '3.0', 'latest']
44-
include:
45-
- php: '8.1'
46-
doctrine-orm: '2.14'
47-
doctrine-lexer: '1.2'
48-
- php: '8.4' # Run coverage report only based on the latest dependencies
49-
doctrine-lexer: 'latest'
50-
doctrine-orm: 'latest'
51-
calculate-code-coverage: true
52-
exclude:
53-
- doctrine-orm: '2.14'
54-
doctrine-lexer: '3.0'
55-
- doctrine-orm: '3.0'
56-
doctrine-lexer: '2.1'
37+
name: "Code Quality"
5738

5839
steps:
5940
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
6041

61-
- name: Set up PHP with PECL extension
42+
- name: Set up PHP
6243
uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2
6344
with:
64-
php-version: ${{ matrix.php }}
65-
coverage: xdebug
45+
php-version: '8.4'
6646
extensions: ctype, json, mbstring
6747
tools: composer
6848

@@ -78,60 +58,11 @@ jobs:
7858
restore-keys: |
7959
${{ runner.os }}-php-
8060
81-
- name: Install Doctrine Lexer dependency
82-
run: |
83-
if [ "${{ matrix.doctrine-lexer }}" = "1.2" ]; then
84-
composer require doctrine/lexer "~1.2" --dev --prefer-dist --no-interaction --no-progress
85-
elif [ "${{ matrix.doctrine-lexer }}" = "2.1" ]; then
86-
composer require doctrine/lexer "~2.1" --dev --prefer-dist --no-interaction --no-progress
87-
elif [ "${{ matrix.doctrine-lexer }}" = "3.0" ]; then
88-
composer require doctrine/lexer "~3.0" --dev --prefer-dist --no-interaction --no-progress
89-
else
90-
composer update --prefer-dist --no-interaction --no-progress
91-
fi
92-
93-
- name: Install Doctrine ORM dependency
94-
run: |
95-
if [ "${{ matrix.doctrine-orm }}" = "2.14" ]; then
96-
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress --with-all-dependencies
97-
elif [ "${{ matrix.doctrine-orm }}" = "2.18" ]; then
98-
composer require doctrine/orm "~2.18" --prefer-dist --no-interaction --no-progress --with-all-dependencies
99-
elif [ "${{ matrix.doctrine-orm }}" = "3.0" ]; then
100-
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress --with-all-dependencies
101-
else
102-
composer update --prefer-dist --no-interaction --no-progress
103-
fi
104-
105-
- name: Run static analysis
106-
run: composer run-static-analysis
107-
continue-on-error: ${{ matrix.continue-on-error || false }}
61+
- name: Install dependencies
62+
run: composer install --prefer-dist --no-interaction --no-progress
10863

10964
- name: Check code style
11065
run: composer check-code-style
11166

11267
- name: Check for security vulnerabilities in 3rd party dependencies
11368
run: composer audit
114-
115-
- name: Run unit test suite
116-
run: composer run-unit-tests
117-
118-
- name: Upload coverage results to Coveralls
119-
if: matrix.calculate-code-coverage == true
120-
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
121-
with:
122-
github-token: ${{ secrets.GITHUB_TOKEN }}
123-
file: ./var/logs/test-coverage/unit/clover.xml
124-
parallel: true
125-
flag-name: "Unit"
126-
fail-on-error: false
127-
128-
coveralls-finish:
129-
needs: tests
130-
if: always()
131-
runs-on: ubuntu-latest
132-
steps:
133-
- name: Finalize Coveralls parallel run
134-
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
135-
with:
136-
github-token: ${{ secrets.GITHUB_TOKEN }}
137-
parallel-finished: true

.github/workflows/coverage.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Coverage
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Integration Tests", "Unit Tests"]
6+
types: [completed]
7+
8+
jobs:
9+
finalize:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_sha == github.sha }}
12+
# Needed for listWorkflowRunsForRepo and safe defaults for token scope
13+
permissions:
14+
actions: read
15+
contents: read
16+
statuses: write
17+
# Prevent multiple concurrent finalizers for the same commit
18+
concurrency:
19+
group: coverage-${{ github.event.workflow_run.head_sha }}
20+
cancel-in-progress: true
21+
steps:
22+
- id: check
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const workflows = await github.rest.actions.listWorkflowRunsForRepo({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
head_sha: context.payload.workflow_run.head_sha,
30+
status: 'completed',
31+
per_page: 100
32+
});
33+
34+
const bothComplete = ['Integration Tests', 'Unit Tests'].every(name =>
35+
workflows.data.workflow_runs.some(
36+
run => run.name === name && run.conclusion === 'success'
37+
)
38+
);
39+
40+
core.info(bothComplete ? 'Both workflows completed successfully.' : 'Waiting for other workflow to complete.');
41+
core.setOutput('ready', String(bothComplete));
42+
43+
- if: ${{ steps.check.outputs.ready == 'true' }}
44+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b
45+
with:
46+
github-token: ${{ secrets.GITHUB_TOKEN }}
47+
parallel-finished: true

.github/workflows/integration-tests.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Integrations
1+
name: Integration Tests
22

33
on:
44
push:
@@ -41,6 +41,10 @@ jobs:
4141
matrix:
4242
php: ['8.1', '8.2', '8.3', '8.4']
4343
postgres: ['16', '17']
44+
include:
45+
- php: '8.4'
46+
postgres: '17'
47+
calculate-code-coverage: true
4448

4549
services:
4650
postgres:
@@ -114,3 +118,13 @@ jobs:
114118
POSTGRES_DB: postgres_doctrine_test
115119
POSTGRES_USER: postgres
116120
POSTGRES_PASSWORD: postgres
121+
122+
- name: Upload coverage results to Coveralls
123+
if: matrix.calculate-code-coverage == true
124+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
125+
with:
126+
github-token: ${{ secrets.GITHUB_TOKEN }}
127+
file: ./var/logs/test-coverage/integration/clover.xml
128+
parallel: true
129+
flag-name: "Integration"
130+
fail-on-error: false

.github/workflows/unit-tests.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '.github/actions/release-please/**'
9+
pull_request:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
should-run:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
run: ${{ steps.check.outputs.run }}
21+
steps:
22+
- name: Skip for release-please
23+
id: check
24+
run: |
25+
if [ "${{ github.event.pull_request.user.id }}" = "41898282" ]; then
26+
echo "run=false" >> $GITHUB_OUTPUT
27+
echo "::notice::Skipping unit tests - this a release-please bot's interaction"
28+
else
29+
echo "run=true" >> $GITHUB_OUTPUT
30+
echo "::notice::Unit tests will execute - the actor is not the release-please bot"
31+
fi
32+
33+
unit-tests:
34+
needs: should-run
35+
if: needs.should-run.outputs.run == 'true'
36+
runs-on: ubuntu-latest
37+
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }} + Doctrine Lexer ${{ matrix.doctrine-lexer }}"
38+
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
php: ['8.1', '8.2', '8.3', '8.4']
43+
doctrine-lexer: ['2.1', '3.0', 'latest']
44+
doctrine-orm: ['2.14', '2.18', '3.0', 'latest']
45+
include:
46+
- php: '8.1'
47+
doctrine-orm: '2.14'
48+
doctrine-lexer: '1.2'
49+
- php: '8.4' # Run coverage report only based on the latest dependencies
50+
doctrine-lexer: 'latest'
51+
doctrine-orm: 'latest'
52+
calculate-code-coverage: true
53+
exclude:
54+
- doctrine-orm: '2.14'
55+
doctrine-lexer: '3.0'
56+
- doctrine-orm: '3.0'
57+
doctrine-lexer: '2.1'
58+
59+
steps:
60+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
61+
62+
- name: Set up PHP with PECL extension
63+
uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2
64+
with:
65+
php-version: ${{ matrix.php }}
66+
coverage: xdebug
67+
extensions: ctype, json, mbstring
68+
tools: composer
69+
70+
- name: Cache Composer packages
71+
id: composer-cache
72+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4
73+
with:
74+
path: vendor
75+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
76+
restore-keys: |
77+
${{ runner.os }}-php-
78+
79+
- name: Install Doctrine Lexer dependency
80+
run: |
81+
if [ "${{ matrix.doctrine-lexer }}" = "1.2" ]; then
82+
composer require doctrine/lexer "~1.2" --dev --prefer-dist --no-interaction --no-progress
83+
elif [ "${{ matrix.doctrine-lexer }}" = "2.1" ]; then
84+
composer require doctrine/lexer "~2.1" --dev --prefer-dist --no-interaction --no-progress
85+
elif [ "${{ matrix.doctrine-lexer }}" = "3.0" ]; then
86+
composer require doctrine/lexer "~3.0" --dev --prefer-dist --no-interaction --no-progress
87+
else
88+
composer update --prefer-dist --no-interaction --no-progress
89+
fi
90+
91+
- name: Install Doctrine ORM dependency
92+
run: |
93+
if [ "${{ matrix.doctrine-orm }}" = "2.14" ]; then
94+
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress --with-all-dependencies
95+
elif [ "${{ matrix.doctrine-orm }}" = "2.18" ]; then
96+
composer require doctrine/orm "~2.18" --prefer-dist --no-interaction --no-progress --with-all-dependencies
97+
elif [ "${{ matrix.doctrine-orm }}" = "3.0" ]; then
98+
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress --with-all-dependencies
99+
else
100+
composer update --prefer-dist --no-interaction --no-progress
101+
fi
102+
103+
- name: Run static analysis
104+
run: composer run-static-analysis
105+
continue-on-error: ${{ matrix.continue-on-error || false }}
106+
107+
- name: Run unit test suite
108+
run: composer run-unit-tests
109+
110+
- name: Upload coverage results to Coveralls
111+
if: matrix.calculate-code-coverage == true
112+
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2
113+
with:
114+
github-token: ${{ secrets.GITHUB_TOKEN }}
115+
file: ./var/logs/test-coverage/unit/clover.xml
116+
parallel: true
117+
flag-name: "Unit"
118+
fail-on-error: false

0 commit comments

Comments
 (0)