Skip to content

Commit e6297d5

Browse files
authored
Merge pull request #6 from macocci7/add_github_workflows
Add github workflows
2 parents 8e1239f + a30dbe9 commit e6297d5

19 files changed

Lines changed: 288 additions & 14 deletions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Test and Static Analysis (Pull Request)
2+
3+
on: pull_request
4+
5+
jobs:
6+
test-and-static-analysis:
7+
name: Test and Lint
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
php: ['8.1', '8.2', '8.3', '8.4']
12+
13+
steps:
14+
- name: Set up PHP
15+
uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: ${{ matrix.php }}
18+
coverage: xdebug
19+
tools: composer:v2
20+
21+
- name: Set up Node
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '22.x'
25+
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: PHP Version Check
32+
run: php -v
33+
34+
- name: Validate Composer JSON
35+
run: composer validate
36+
37+
- name: Run Composer Install
38+
id: composerinstall
39+
run: composer install --no-interaction
40+
41+
- name: PHP Lint
42+
run: ./vendor/bin/parallel-lint src tests playground
43+
44+
- name: PHP Code Sniffer
45+
run: |
46+
./vendor/bin/phpcs --version
47+
./vendor/bin/phpcs --ignore=vendor --standard=phpcs.xml -s -p .
48+
49+
- name: PHPStan
50+
run: |
51+
./vendor/bin/phpstan --version
52+
./vendor/bin/phpstan analyze -c phpstan.neon
53+
54+
- name: Unit tests
55+
run: |
56+
mkdir -p build/logs
57+
./vendor/bin/phpunit --version
58+
echo "Test suite All"
59+
./vendor/bin/phpunit ./tests/
60+
61+
code-coverage:
62+
name: Code coverage
63+
runs-on: ubuntu-latest
64+
strategy:
65+
matrix:
66+
php: ['8.4']
67+
68+
steps:
69+
- name: Set up PHP
70+
uses: shivammathur/setup-php@v2
71+
with:
72+
php-version: ${{ matrix.php }}
73+
coverage: xdebug
74+
tools: composer:v2
75+
76+
- name: Set up Node
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: '22.x'
80+
81+
- name: Checkout code
82+
uses: actions/checkout@v4
83+
with:
84+
fetch-depth: 0
85+
86+
- name: Run Composer
87+
run: composer install --no-interaction
88+
89+
- name: Update PHPUnit for Code Coverage
90+
run: composer require phpunit/phpunit:^10.5 sebastian/version:* --with-all-dependencies
91+
92+
- name: PHP Lint
93+
run: ./vendor/bin/parallel-lint src tests playground
94+
95+
- name: Unit tests
96+
run: |
97+
mkdir -p build/logs
98+
XDEBUG_MODE=coverage ./vendor/bin/phpunit ./tests/ --coverage-clover build/logs/clover.xml --coverage-filter=./src/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 macocci7
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PHP_VERSIONS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
8.4
2+
8.3
3+
8.2
4+
8.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ composer require macocci7/bash-colorizer
7070
creating an instance:
7171
```php
7272
$colorizer = new Colorizer;
73-
$colorizer->("Hi, there!")
73+
$colorizer->echo("Hi, there!")
7474
->echo(" How's it going with you?", PHP_EOL);
7575
```
7676

bin/TestAndLint.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/bash
2+
3+
# Script to Test and Lint
4+
# requirement:
5+
# - https://github.com/jdx/mise installed
6+
# - PHP versions defined in ../PHP_VERSIONS installed
7+
8+
CMD=mise
9+
$CMD -v &> /dev/null
10+
if [ $? -ne 0 ]; then
11+
echo "command [${CMD}] not found!"
12+
exit 1
13+
fi
14+
echo "-----------------------------------------------------------"
15+
echo "[composer validate]"
16+
composer validate
17+
if [ $? -ne 0 ]; then
18+
echo "Operation aborted."
19+
exit 1
20+
fi
21+
22+
switch_version() {
23+
echo "==========================================================="
24+
echo "[PHP $1][Switching PHP version to $1]"
25+
mise x php@$1 -- bash bin/TestAndLintSub.sh $1;
26+
}
27+
28+
echo "[[TestAndLint.sh]]"
29+
30+
SUPPORTED_PHP_VERSIONS=PHP_VERSIONS
31+
if [ ! -f $SUPPORTED_PHP_VERSIONS ]; then
32+
echo "file [$SUPPORTED_PHP_VERSIONS] not found."
33+
echo "operation aborted."
34+
exit 1
35+
fi
36+
if [ ! -r $SUPPORTED_PHP_VERSIONS ]; then
37+
echo "cannot read file[$SUPPORTED_PHP_VERSIONS]."
38+
echo "operation aborted."
39+
exit 1
40+
fi
41+
STR_CMD=''
42+
while read version ; do
43+
STR_CMD="$STR_CMD switch_version $version;"
44+
done < $SUPPORTED_PHP_VERSIONS
45+
eval $STR_CMD

bin/TestAndLintSub.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/bash
2+
3+
# Script to Test and Lint
4+
# requirement:
5+
# - PHP versions defined in ../PHP_VERSIONS installed
6+
7+
echo "-----------------------------------------------------------"
8+
echo "[PHP $1][php -v]"
9+
php -v
10+
echo "-----------------------------------------------------------"
11+
echo "[PHP $1][parallel-lint]"
12+
./vendor/bin/parallel-lint src tests examples
13+
echo "-----------------------------------------------------------"
14+
echo "[PHP $1][phpcs]"
15+
./vendor/bin/phpcs --ignore=vendor \
16+
--standard=phpcs.xml \
17+
-p \
18+
-s \
19+
.
20+
echo "-----------------------------------------------------------"
21+
echo "[PHP $1][phpstan]"
22+
./vendor/bin/phpstan analyze -c phpstan.neon
23+
echo "-----------------------------------------------------------"
24+
echo "[PHP $1][phpunit]"
25+
./vendor/bin/phpunit ./tests/
26+
echo "-----------------------------------------------------------"

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
],
1717
"minimum-stability": "stable",
1818
"require-dev": {
19-
"phpunit/phpunit": "^10.5"
19+
"phpunit/phpunit": "^10.5",
20+
"php-parallel-lint/php-parallel-lint": "^1.4",
21+
"squizlabs/php_codesniffer": "^3.12",
22+
"phpstan/phpstan": "^2.1"
2023
}
2124
}

phpcs.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PhotoGps">
3+
<description>The coding standard for Bash Colorizer.</description>
4+
5+
<config name="php_version" value="81000"/>
6+
7+
<rule ref="PSR12">
8+
</rule>
9+
<!-- tests are special -->
10+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
11+
<exclude-pattern>*/tests/*</exclude-pattern>
12+
</rule>
13+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
14+
<exclude-pattern>*/tests/*</exclude-pattern>
15+
</rule>
16+
<rule ref="Generic.Files.LineLength.TooLong">
17+
<exclude-pattern>*/tests/*</exclude-pattern>
18+
</rule>
19+
<arg value="ps" />
20+
21+
</ruleset>

phpstan.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- ./src
5+
treatPhpDocTypesAsCertain: false
6+
ignoreErrors:
7+
-
8+
identifier: match.alwaysTrue
9+
path: src/Enums/*

playground/attributes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
$colors = [
1010
...array_filter(
11-
Foreground::values(), function ($v, $k) {
11+
Foreground::values(),
12+
function ($v, $k) {
1213
return ! in_array($k, [0, 8, 9]);
13-
},
14+
},
1415
ARRAY_FILTER_USE_BOTH
1516
)
1617
];

0 commit comments

Comments
 (0)