Skip to content

Commit 66d0b17

Browse files
roxblnfkclaude
andauthored
ci: add CI workflows and QA tools (#5)
* ci: add CI workflows and install QA tools as bamarni-bin tools - Tests: Unit on PHP 8.2-8.5 with lowest and highest dependencies; Feature, Acceptance and Regression suites on SQLite, MySQL, Postgres and SQLServer through resources/docker/compose.yaml with DB_REQUIRED=1; coverage of the Unit and SQLite suites uploaded to Codecov. - Psalm 7 and spiral/code-style in vendor-bin, run through the spiral/gh-actions workflows. - composer audit in security.yml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: apply spiral/code-style Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8bcfb95 commit 66d0b17

17 files changed

Lines changed: 360 additions & 47 deletions

File tree

‎.github/workflows/cs-fix.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
name: Fix Code Style
4+
5+
on: # yamllint disable-line rule:truthy
6+
push:
7+
branches:
8+
- '**'
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
cs-fix:
15+
uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master
16+
with:
17+
php: '["8.2"]'
18+
bin-tool: code-style
19+
command: composer cs:fix

‎.github/workflows/psalm.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
3+
name: 🔍 Static analysis
4+
5+
on: # yamllint disable-line rule:truthy
6+
pull_request:
7+
push:
8+
branches:
9+
- 1.x
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
psalm:
16+
uses: spiral/gh-actions/.github/workflows/psalm.yml@master
17+
with:
18+
os: >-
19+
['ubuntu-latest']
20+
php: '["8.4"]'
21+
bin-tool: psalm
22+
command: composer psalm:ci

‎.github/workflows/security.yml‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
3+
name: 🔐 Security analysis
4+
5+
on: # yamllint disable-line rule:truthy
6+
pull_request:
7+
push:
8+
branches: [1.x]
9+
10+
# `head_ref` is the PR source branch on `pull_request` events and empty on `push`
11+
# (falls back to `github.ref` = `refs/heads/<branch>`). Different PRs from different
12+
# branches → different groups, so they never cross-cancel. Same PR pushed again
13+
# → same group, the new run cancels the previous one.
14+
#
15+
# `cancel-in-progress` is only enabled on PR events: pushes to the default branch
16+
# (1.x) keep their full history of CI runs.
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
19+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
security-analysis:
26+
timeout-minutes: 4
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
fail-fast: true
30+
matrix:
31+
os:
32+
- ubuntu-latest
33+
php-version:
34+
- "8.5"
35+
dependencies:
36+
- highest
37+
steps:
38+
- name: 📦 Check out the codebase
39+
uses: actions/checkout@v7
40+
with:
41+
persist-credentials: false
42+
43+
- name: 🛠️ Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php-version }}
47+
ini-values: error_reporting=E_ALL
48+
coverage: none
49+
50+
- name: 🛠️ Setup problem matchers
51+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
52+
53+
- name: 🤖 Validate composer.json
54+
run: composer validate --ansi --strict
55+
56+
- name: 📥 Install dependencies with composer
57+
uses: ramsey/composer-install@v4
58+
with:
59+
dependency-versions: ${{ matrix.dependencies }}
60+
61+
- name: 🐛 Check installed packages for security vulnerability advisories
62+
run: composer audit --ansi

‎.github/workflows/testing.yml‎

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
3+
name: 🧪 Tests
4+
5+
on: # yamllint disable-line rule:truthy
6+
pull_request:
7+
push:
8+
branches:
9+
- 1.x
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
13+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
14+
15+
permissions:
16+
contents: read
17+
18+
env:
19+
COMPOSER_ROOT_VERSION: 1.x-dev
20+
# An unreachable database fails the run instead of skipping its tests.
21+
DB_REQUIRED: 1
22+
23+
jobs:
24+
unit:
25+
name: Unit · PHP ${{ matrix.php-version }} · ${{ matrix.dependencies }}
26+
timeout-minutes: 6
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
php-version:
32+
- '8.2'
33+
- '8.3'
34+
- '8.4'
35+
- '8.5'
36+
dependencies:
37+
- lowest
38+
- highest
39+
steps:
40+
- name: 📦 Check out the codebase
41+
uses: actions/checkout@v6
42+
with:
43+
persist-credentials: false
44+
45+
- name: 🛠️ Setup PHP
46+
uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: ${{ matrix.php-version }}
49+
extensions: pdo, pdo_sqlite
50+
ini-values: error_reporting=E_ALL
51+
coverage: none
52+
53+
- name: 🤖 Validate composer.json
54+
run: composer validate --ansi --strict
55+
56+
- name: 📥 Install dependencies with composer
57+
uses: ramsey/composer-install@v3
58+
with:
59+
dependency-versions: ${{ matrix.dependencies }}
60+
61+
- name: 🧪 Run unit tests
62+
run: composer test:unit
63+
64+
database:
65+
name: ${{ matrix.driver }} · PHP ${{ matrix.php-version }} · ${{ matrix.dependencies }}
66+
timeout-minutes: 12
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
driver:
72+
- sqlite
73+
- mysql
74+
- postgres
75+
- sqlserver
76+
php-version:
77+
- '8.2'
78+
- '8.3'
79+
- '8.4'
80+
- '8.5'
81+
dependencies:
82+
- highest
83+
include:
84+
- {driver: sqlite, php-version: '8.2', dependencies: lowest}
85+
- {driver: mysql, php-version: '8.2', dependencies: lowest}
86+
- {driver: postgres, php-version: '8.2', dependencies: lowest}
87+
- {driver: sqlserver, php-version: '8.2', dependencies: lowest}
88+
steps:
89+
- name: 📦 Check out the codebase
90+
uses: actions/checkout@v6
91+
with:
92+
persist-credentials: false
93+
94+
- name: 🛢️ Start ${{ matrix.driver }}
95+
if: matrix.driver != 'sqlite'
96+
run: docker compose -f resources/docker/compose.yaml up -d --wait ${{ matrix.driver }}
97+
98+
- name: 🛠️ Install the Microsoft ODBC driver
99+
if: matrix.driver == 'sqlserver'
100+
run: |
101+
curl -fsSL https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
102+
sudo apt-get update
103+
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
104+
105+
- name: 🛠️ Setup PHP
106+
uses: shivammathur/setup-php@v2
107+
with:
108+
php-version: ${{ matrix.php-version }}
109+
extensions: pdo, pdo_sqlite, pdo_mysql, pdo_pgsql, pdo_sqlsrv
110+
ini-values: error_reporting=E_ALL
111+
coverage: none
112+
113+
- name: 📥 Install dependencies with composer
114+
uses: ramsey/composer-install@v3
115+
with:
116+
dependency-versions: ${{ matrix.dependencies }}
117+
118+
- name: 🧪 Run Feature, Acceptance and Regression suites
119+
run: composer test:${{ matrix.driver }}
120+
121+
coverage:
122+
name: Code coverage
123+
timeout-minutes: 6
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: 📦 Check out the codebase
127+
uses: actions/checkout@v6
128+
with:
129+
persist-credentials: false
130+
131+
- name: 🛠️ Setup PHP
132+
uses: shivammathur/setup-php@v2
133+
with:
134+
php-version: '8.4'
135+
extensions: pdo, pdo_sqlite
136+
ini-values: error_reporting=E_ALL
137+
coverage: xdebug
138+
139+
- name: 📥 Install dependencies with composer
140+
uses: ramsey/composer-install@v3
141+
with:
142+
dependency-versions: highest
143+
144+
- name: 🧪 Collect code coverage (Unit and SQLite suites)
145+
run: composer test:cc
146+
147+
- name: 📤 Upload code coverage report to Codecov
148+
uses: codecov/codecov-action@v5
149+
continue-on-error: true
150+
with:
151+
files: runtime/clover.xml
152+
token: ${{ secrets.CODECOV_TOKEN }}
153+
verbose: true

‎composer.json‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
"testo/testo": "^0.10.60"
3535
},
3636
"require-dev": {
37+
"bamarni/composer-bin-plugin": "^1.9",
3738
"cycle/annotated": "^4.6",
3839
"cycle/orm": "^2.18",
3940
"cycle/schema-builder": "^2.12",
4041
"doctrine/collections": "^2.6 || ^3.0",
4142
"llm/skills": "^1.20",
4243
"mockery/mockery": "^1.6",
43-
"testo/bridge-mockery": "^0.1.2",
44-
"vimeo/psalm": "^7.12"
44+
"testo/bridge-mockery": "^0.1.2"
4545
},
4646
"suggest": {
4747
"cycle/annotated": "Schema\\SchemaCompiler: compile an ORM schema from annotated entities",
@@ -64,11 +64,17 @@
6464
},
6565
"config": {
6666
"allow-plugins": {
67+
"bamarni/composer-bin-plugin": true,
6768
"llm/skills": true
6869
},
6970
"sort-packages": true
7071
},
7172
"extra": {
73+
"bamarni-bin": {
74+
"bin-links": true,
75+
"forward-command": false,
76+
"target-directory": "vendor-bin"
77+
},
7278
"branch-alias": {
7379
"dev-1.x": "1.x-dev"
7480
},
@@ -79,8 +85,16 @@
7985
"scripts": {
8086
"db:down": "docker compose -f resources/docker/compose.yaml down -v",
8187
"db:up": "docker compose -f resources/docker/compose.yaml up -d --wait",
82-
"psalm": "psalm",
88+
"cs:diff": "php-cs-fixer fix --dry-run -v --diff --config=vendor-bin/code-style/.php-cs-fixer.dist.php",
89+
"cs:fix": "php-cs-fixer fix -v --config=vendor-bin/code-style/.php-cs-fixer.dist.php",
90+
"psalm": "psalm -c vendor-bin/psalm/psalm.xml",
91+
"psalm:baseline": "psalm -c vendor-bin/psalm/psalm.xml --set-baseline=vendor-bin/psalm/psalm-baseline.xml",
92+
"psalm:ci": "psalm -c vendor-bin/psalm/psalm.xml --output-format=github --shepherd --show-info=false --stats --threads=4",
8393
"test": "testo",
94+
"test:cc": [
95+
"@putenv XDEBUG_MODE=coverage",
96+
"testo --suite=Unit --suite=Feature/SQLite --suite=Acceptance/SQLite --suite=Regression/SQLite --coverage"
97+
],
8498
"test:mysql": "testo --suite=Feature/MySQL --suite=Acceptance/MySQL --suite=Regression/MySQL",
8599
"test:postgres": "testo --suite=Feature/Postgres --suite=Acceptance/Postgres --suite=Regression/Postgres",
86100
"test:sqlite": "testo --suite=Feature/SQLite --suite=Acceptance/SQLite --suite=Regression/SQLite",

‎src/Config.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,22 +260,22 @@ public function build(): ApplicationConfig
260260
}
261261

262262
/**
263-
* Without the plugin, Mockery expectations would go unverified silently.
264-
*
263+
* @param iterable<PluginConfigurator> $plugins
265264
* @return list<PluginConfigurator>
266265
*/
267-
private function mockery(): array
266+
private static function list(iterable $plugins): array
268267
{
269-
return \class_exists(MockeryPlugin::class) && \class_exists(\Mockery::class) ? [new MockeryPlugin()] : [];
268+
return \is_array($plugins) ? \array_values($plugins) : \iterator_to_array($plugins, false);
270269
}
271270

272271
/**
273-
* @param iterable<PluginConfigurator> $plugins
272+
* Without the plugin, Mockery expectations would go unverified silently.
273+
*
274274
* @return list<PluginConfigurator>
275275
*/
276-
private static function list(iterable $plugins): array
276+
private function mockery(): array
277277
{
278-
return \is_array($plugins) ? \array_values($plugins) : \iterator_to_array($plugins, false);
278+
return \class_exists(MockeryPlugin::class) && \class_exists(\Mockery::class) ? [new MockeryPlugin()] : [];
279279
}
280280

281281
/**

‎src/Database/ConnectionPool.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
*/
2323
final class ConnectionPool
2424
{
25+
public readonly Layout $layout;
26+
public readonly Env $env;
27+
2528
/** @var array<string, DriverInterface> */
2629
private array $drivers = [];
2730

2831
/** @var array<string, DatabaseManager> */
2932
private array $managers = [];
3033

31-
public readonly Layout $layout;
32-
public readonly Env $env;
33-
3434
public function __construct(
3535
public readonly Driver $driver,
3636
?Layout $layout = null,

‎src/Database/Env.php‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ public function __construct(
2323
private readonly array $overrides = [],
2424
) {}
2525

26-
/**
27-
* A copy whose given values win over the environment and the defaults.
28-
*
29-
* @param array<non-empty-string, string> $overrides
30-
*/
31-
public function with(array $overrides): self
32-
{
33-
return new self($this->defaults, $overrides + $this->overrides);
34-
}
35-
3626
/**
3727
* The shared instance over {@see self::DEFAULTS_FILE}.
3828
*/
@@ -67,6 +57,16 @@ public static function fromFile(string $path): self
6757
return new self($values);
6858
}
6959

60+
/**
61+
* A copy whose given values win over the environment and the defaults.
62+
*
63+
* @param array<non-empty-string, string> $overrides
64+
*/
65+
public function with(array $overrides): self
66+
{
67+
return new self($this->defaults, $overrides + $this->overrides);
68+
}
69+
7070
/**
7171
* @throws \OutOfBoundsException When the key is neither set nor has a default.
7272
*/

0 commit comments

Comments
 (0)