Skip to content

Commit 341c28d

Browse files
committed
chore: update ci.yml
Signed-off-by: Alan Brault <alan.brault@visus.io>
1 parent 3940276 commit 341c28d

8 files changed

Lines changed: 132 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 114 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,142 @@ name: Continuous Integration
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
7+
paths-ignore:
8+
- "**.md"
9+
- "renovate.json"
10+
- ".github/ISSUE_TEMPLATE/**"
11+
- ".github/workflows/release.yml"
12+
613
pull_request:
14+
paths-ignore:
15+
- "**.md"
16+
- "renovate.json"
17+
- ".github/ISSUE_TEMPLATE/**"
18+
- ".github/workflows/release.yml"
719

820
concurrency:
921
group: ${{ github.workflow }}-${{ github.ref }}
1022
cancel-in-progress: true
1123

1224
jobs:
13-
static-analysis:
25+
coding-standards:
26+
name: Coding Standards
1427
runs-on: ubuntu-latest
28+
1529
steps:
16-
- uses: actions/checkout@v6
30+
- name: Checkout
31+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1732
with:
1833
fetch-depth: 0
1934
show-progress: false
20-
- uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
2138
with:
22-
php-version: '8.4'
39+
php-version: 'latest'
2340
tools: composer
24-
extensions: xdebug
25-
- uses: actions/cache@v4
41+
coverage: none
42+
43+
- name: Composer Install
44+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
45+
46+
- name: Check Syntax
47+
run: composer dev:lint:syntax
48+
49+
- name: Check Code Style
50+
run: composer dev:lint:style
51+
52+
static-analysis:
53+
name: Static Analysis
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2659
with:
27-
path: |
28-
vendor
29-
~/.composer/cache
30-
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
31-
restore-keys: composer-${{ runner.os }}-
32-
- run: composer install --quiet --no-ansi --no-interaction --no-progress --prefer-dist
33-
- run: composer normalize --dry-run
34-
- run: composer validate
35-
- run: composer phpstan -- --ansi
36-
- run: composer psalm
60+
fetch-depth: 0
61+
show-progress: false
3762

38-
unit-tests:
39-
needs: [static-analysis]
63+
- name: Setup PHP
64+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
65+
with:
66+
php-version: 'latest'
67+
tools: composer
68+
coverage: none
69+
70+
- name: Composer Install
71+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
72+
73+
- name: Run Static Analysis
74+
run: composer dev:analyze:phpstan
75+
76+
code-coverage:
77+
name: Code Coverage
78+
needs: [coding-standards, static-analysis]
4079
runs-on: ubuntu-latest
80+
4181
steps:
42-
- uses: actions/checkout@v6
82+
- name: Checkout
83+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4384
with:
4485
fetch-depth: 0
4586
show-progress: false
46-
- uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1
87+
88+
- name: Setup PHP
89+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
4790
with:
48-
php-version: '8.4'
91+
php-version: 'latest'
4992
tools: composer
93+
extensions: gmp
5094
coverage: xdebug
51-
- uses: actions/cache@v4
52-
with:
53-
path: |
54-
vendor
55-
~/.composer/cache
56-
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
57-
restore-keys: composer-${{ runner.os }}-
58-
- run: composer install --quiet --no-ansi --no-interaction --no-progress --prefer-dist
59-
- run: composer normalize --dry-run
60-
- run: composer validate
61-
- run: vendor/bin/phpunit || true
62-
- uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9
95+
96+
- name: Composer Install
97+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
98+
99+
- name: Run Tests with Coverage
100+
run: composer dev:test:coverage:ci
101+
102+
- name: Upload to SonarCloud
103+
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # 7.0.0
63104
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
105+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
106+
107+
unit-tests:
108+
name: Unit Tests
109+
needs: [coding-standards, static-analysis]
110+
runs-on: ${{ matrix.os }}
111+
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
php-version: ['8.2', '8.3', '8.4', '8.5']
116+
os: [ubuntu-latest, windows-latest]
117+
118+
steps:
119+
- name: Configure Git for Windows
120+
if: ${{ matrix.os == 'windows-latest' }}
121+
run: |
122+
git config --system core.autocrlf false
123+
git config --system core.eol lf
124+
125+
- name: Checkout
126+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
127+
with:
128+
fetch-depth: 0
129+
show-progress: false
130+
131+
- name: Setup PHP
132+
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
133+
with:
134+
php-version: ${{ matrix.php-version }}
135+
tools: composer
136+
extensions: gmp
137+
coverage: none
138+
139+
- name: Composer Install
140+
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3.1.1
141+
142+
- name: Run Unit Tests
143+
run: composer dev:test:unit

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"symfony/polyfill-php83": "^1.32"
2020
},
2121
"require-dev": {
22-
"captainhook/captainhook-phar": "^5.23",
23-
"captainhook/hook-installer": "^1.0",
22+
"captainhook/captainhook": "^5.27",
2423
"captainhook/plugin-composer": "^5.3",
2524
"dealerdirect/phpcodesniffer-composer-installer": "^1.2",
2625
"ergebnis/composer-normalize": "^2.29",
@@ -47,13 +46,12 @@
4746
},
4847
"autoload-dev": {
4948
"psr-4": {
50-
"Visus\\Cuid2\\Test\\": "tests/"
49+
"Visus\\Cuid2\\Test\\": "tests/",
50+
"Visus\\Cuid2\\Test\\Benchmark\\": "tests/benchmark"
5151
}
5252
},
5353
"config": {
5454
"allow-plugins": {
55-
"captainhook/captainhook-phar": true,
56-
"captainhook/hook-installer": true,
5755
"captainhook/plugin-composer": true,
5856
"dealerdirect/phpcodesniffer-composer-installer": true,
5957
"ergebnis/composer-normalize": true
@@ -82,9 +80,11 @@
8280
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
8381
"dev:test": [
8482
"@dev:lint",
83+
"@dev:benchmark",
8584
"@dev:analyze",
8685
"@dev:test:unit"
8786
],
87+
"dev:test:coverage:ci": "@php -d 'xdebug.mode=coverage' vendor/bin/phpunit --colors=always --coverage-clover build/coverage/xml/clover.xml --log-junit build/coverage/xml/execution.xml",
8888
"dev:test:coverage:html": "@php -d 'xdebug.mode=coverage' vendor/bin/phpunit --colors=always --coverage-html build/coverage/html",
8989
"dev:test:unit": "phpunit --colors=always --no-coverage",
9090
"test": "@dev:test"

sonar-project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ sonar.projectBaseDir=.
66
sonar.sources=src
77
sonar.tests=tests
88

9-
sonar.php.coverage.reportPaths=build/logs/clover.xml
10-
sonar.php.tests.reportPath=build/logs/execution.xml
9+
sonar.php.coverage.reportPaths=build/coverage/xml/clover.xml
10+
sonar.php.tests.reportPath=build/coverage/xml/execution.xml

tests/CounterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testGetNextValueReturnsInteger(): void
4343
$counter = Counter::getInstance();
4444
$value = $counter->getNextValue();
4545

46-
$this->assertIsInt($value);
46+
$this->assertGreaterThanOrEqual(0, $value);
4747
}
4848

4949
/**
@@ -84,6 +84,7 @@ public function testGetNextValueWrapsAtRange(): void
8484
{
8585
$counter = Counter::getInstance();
8686
$reflection = new ReflectionClass(Counter::class);
87+
/** @var int $rangeConstant */
8788
$rangeConstant = $reflection->getConstant('RANGE');
8889

8990
// Use reflection to set the counter value near RANGE

tests/Cuid2Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public function testJsonEncodesCorrectly(): void
160160
{
161161
$cuid = new Cuid2();
162162
$jsonString = json_encode($cuid);
163+
$this->assertIsString($jsonString);
163164

164165
$decoded = json_decode($jsonString, true);
165166
$this->assertIsString($decoded);

tests/FingerprintTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function testGetValueReturnsNonEmptyString(): void
4646
$fingerprint = Fingerprint::getInstance();
4747
$value = $fingerprint->getValue();
4848

49-
$this->assertIsString($value);
5049
$this->assertNotEmpty($value);
5150
}
5251

tests/benchmark/Cuid2Bench.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public function benchToString(): void
8787
#[Groups(['conversion', 'string'])]
8888
public function benchToStringMethod(): void
8989
{
90-
$this->cuid->toString();
90+
// @phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
91+
$result = $this->cuid->toString();
9192
}
9293

9394
/**

tests/benchmark/SingletonBench.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public function benchFingerprintGetInstance(): void
7777
#[Groups(['singleton', 'fingerprint'])]
7878
public function benchFingerprintGetValue(): void
7979
{
80-
Fingerprint::getInstance()->getValue();
80+
// @phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
81+
$result = Fingerprint::getInstance()->getValue();
8182
}
8283

8384
/**
@@ -92,7 +93,9 @@ public function benchFingerprintGetValue(): void
9293
#[Groups(['singleton', 'combined'])]
9394
public function benchCombinedSingletonAccess(): void
9495
{
95-
Counter::getInstance()->getNextValue();
96-
Fingerprint::getInstance()->getValue();
96+
// @phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
97+
$counterValue = Counter::getInstance()->getNextValue();
98+
// @phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
99+
$fingerprintValue = Fingerprint::getInstance()->getValue();
97100
}
98101
}

0 commit comments

Comments
 (0)