Skip to content

Commit d987d57

Browse files
committed
code style and static analysis permission
1 parent 64a2b64 commit d987d57

File tree

1 file changed

+80
-28
lines changed

1 file changed

+80
-28
lines changed

.github/workflows/ci.yml

Lines changed: 80 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,19 @@ jobs:
4545
php -v
4646
shell: pwsh
4747

48-
- name: Install Composer (Windows)
49-
if: matrix.os == 'windows-latest'
50-
run: |
51-
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
52-
php composer-setup.php
53-
php -r "unlink('composer-setup.php');"
54-
mkdir -p C:\tools\composer
55-
move composer.phar C:\tools\composer\composer
56-
echo "C:\tools\composer" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
57-
shell: pwsh
58-
59-
- name: Install Composer (Unix)
60-
if: matrix.os != 'windows-latest'
48+
- name: Install Composer
6149
run: |
6250
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
63-
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
51+
if [ "$RUNNER_OS" == "Windows" ]; then
52+
php composer-setup.php
53+
mkdir -p C:\tools\composer
54+
move composer.phar C:\tools\composer\composer
55+
echo "C:\tools\composer" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
56+
else
57+
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
58+
fi
6459
php -r "unlink('composer-setup.php');"
60+
composer --version
6561
shell: bash
6662

6763
- name: Validate composer.json
@@ -90,11 +86,6 @@ jobs:
9086
run: vendor/bin/phpunit
9187
shell: bash
9288

93-
- name: Verify binary installation
94-
run: |
95-
php -r "require 'vendor/autoload.php'; new VoltTest\Platform();"
96-
shell: bash
97-
9889
- name: Upload test artifacts
9990
if: always()
10091
uses: actions/upload-artifact@v3
@@ -108,24 +99,66 @@ jobs:
10899
static-analysis:
109100
name: Static Analysis
110101
runs-on: ubuntu-latest
102+
permissions:
103+
contents: read
111104

112105
steps:
113106
- uses: actions/checkout@v4
114107

115-
- name: Setup PHP and tools
108+
- name: Setup PHP
116109
run: |
117110
sudo add-apt-repository ppa:ondrej/php
118111
sudo apt-get update
119112
sudo apt-get install -y php8.2 php8.2-cli php8.2-xml php8.2-mbstring
113+
shell: bash
114+
115+
- name: Install Composer
116+
run: |
120117
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
121-
composer global require phpstan/phpstan
122-
echo "${HOME}/.composer/vendor/bin" >> $GITHUB_PATH
118+
sudo chmod +x /usr/local/bin/composer
119+
mkdir -p ~/.composer
120+
sudo chown -R $USER:$USER ~/.composer
121+
shell: bash
123122

124-
- name: Install dependencies
125-
run: composer install --prefer-dist --no-progress
123+
- name: Get Composer Cache Directory
124+
id: composer-cache
125+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
126+
127+
- name: Cache Composer packages
128+
uses: actions/cache@v3
129+
with:
130+
path: ${{ steps.composer-cache.outputs.dir }}
131+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
132+
restore-keys: |
133+
${{ runner.os }}-composer-
134+
135+
- name: Install Dependencies
136+
run: |
137+
composer install --prefer-dist --no-progress
138+
composer require --dev phpstan/phpstan --with-all-dependencies
139+
shell: bash
140+
141+
- name: Create PHPStan config
142+
run: |
143+
echo '
144+
parameters:
145+
level: 5
146+
paths:
147+
- src
148+
- tests
149+
excludePaths:
150+
- vendor/*
151+
' > phpstan.neon
126152
127153
- name: Run PHPStan
128-
run: phpstan analyse src tests --level=5
154+
run: |
155+
if [ -f "vendor/bin/phpstan" ]; then
156+
vendor/bin/phpstan analyse -c phpstan.neon
157+
else
158+
echo "PHPStan not found in vendor/bin"
159+
exit 1
160+
fi
161+
shell: bash
129162

130163
code-style:
131164
name: Code Style
@@ -140,8 +173,27 @@ jobs:
140173
sudo apt-get update
141174
sudo apt-get install -y php8.2 php8.2-cli php8.2-xml php8.2-mbstring
142175
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
143-
composer global require friendsofphp/php-cs-fixer
144-
echo "${HOME}/.composer/vendor/bin" >> $GITHUB_PATH
176+
177+
- name: Install PHP CS Fixer
178+
run: |
179+
composer require --dev friendsofphp/php-cs-fixer
180+
181+
- name: Create PHP CS Fixer config
182+
run: |
183+
echo "<?php
184+
return (new PhpCsFixer\Config())
185+
->setRules([
186+
'@PSR2' => true,
187+
'array_syntax' => ['syntax' => 'short'],
188+
'no_unused_imports' => true,
189+
'ordered_imports' => true,
190+
])
191+
->setFinder(
192+
PhpCsFixer\Finder::create()
193+
->exclude('vendor')
194+
->in(__DIR__)
195+
);
196+
" > .php-cs-fixer.php
145197
146198
- name: Check coding standards
147-
run: php-cs-fixer fix --dry-run --diff
199+
run: vendor/bin/php-cs-fixer fix --dry-run --diff

0 commit comments

Comments
 (0)