Skip to content

Commit

Permalink
OXDEV-7222 Add php_cs check to GHA build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Aug 16, 2023
1 parent 2506ee2 commit fbadad8
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 3 deletions.
45 changes: 44 additions & 1 deletion .github/workflows/matrix_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:

- name: Clone the shop (${{ github.ref_name }})
if: github.event_name != 'pull_request'
run: git clone --depth 1 https://github.com/OXID-eSales/oxideshop_ce.git --branch ${{ github.ref_name }} --single-branch source
run: git clone --depth 2 https://github.com/OXID-eSales/oxideshop_ce.git --branch ${{ github.ref_name }} --single-branch source

- name: Clone the shop (PR ${{ github.event.number }})
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -150,6 +150,49 @@ jobs:
./*
key: shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}

php_cs_check:
strategy:
matrix:
php: [ '8.1' ]
mysql: [ '8.0' ]
fail-fast: false
needs: [ install_shop ]
runs-on: ubuntu-latest
steps:
- name: Load current installation from cache
uses: actions/cache@v3
with:
path: |
./*
key: shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
restore-keys: |
shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}
- name: Start containers
run: |
make up
sleep 2
- name: Doing PHP_CS check
id: phpcs_run
run: |
docker-compose run -T php vendor/bin/phpcs -q --standard=PSR12 source/Internal \
| tee phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt || true
if grep -q -Ei 'fail|\\.\\=\\=|Warning|Notice|Deprecated|Fatal|Error' phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt; then
echo "**** PHP_CS has found some issues ****"
exit 1
fi
- name: Upload PHP_CS Log
if: always()
uses: actions/upload-artifact@v3
with:
name: phpunit-logs
path: phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt
if-no-files-found: error
retention-days: 7

unit_tests:
strategy:
matrix:
Expand Down
58 changes: 56 additions & 2 deletions .github/workflows/matrix_slim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:

- name: Clone the shop (${{ github.ref_name }})
if: github.event_name != 'pull_request'
run: git clone --depth 1 https://github.com/OXID-eSales/oxideshop_ce.git --branch ${{ github.ref_name }} --single-branch source
run: |
git clone --depth 2 https://github.com/OXID-eSales/oxideshop_ce.git --branch ${{ github.ref_name }} --single-branch source
- name: Clone the shop (PR ${{ github.event.number }})
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -51,7 +52,7 @@ jobs:
perl -pi\
-e 's#display_errors =.*#display_errors = false#g;'\
-e 'print "xdebug.max_nesting_level=1000\n\n";'\
-e 'print "error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING\n"'\
-e 'print "error_reporting = E_ALL & ~E_WARNING & ~E_DEPRECATED & ~E_NOTICE\n"'\
containers/php/custom.ini
perl -pi\
-e 's#/var/www/#/var/www/source/#g;'\
Expand Down Expand Up @@ -121,6 +122,59 @@ jobs:
./*
key: shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}

php_cs_check:
strategy:
matrix:
php: [ '8.1' ]
mysql: [ '8.0' ]
fail-fast: false
needs: [ install_shop ]
runs-on: ubuntu-latest
steps:
- name: Load current installation from cache
uses: actions/cache@v3
with:
path: |
./*
key: shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
restore-keys: |
shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}-${{ github.run_number }}-${{ github.run_attempt }}
shopInstallation-${{ matrix.php }}-${{ matrix.mysql }}-${{ github.sha }}
- name: Start containers
run: |
make up
sleep 2
- name: Prepare for PHP_CS check
run: |
cd source
git diff --name-only origin/${{ github.ref_name }} HEAD~1 > changed-files.txt
echo "--- changed files ---"
cat changed-files.txt
- name: Doing PHP_CS check
id: phpcs_run
run: |
if test -f "source/changed-files.txt"; then
docker-compose run -T php vendor/bin/phpcs -q --standard=PSR12 --file-list=changed-files.txt 2>&1 \
| tee phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt || true
rm source/changed-files.txt
if grep -q -Ei 'fail|\\.\\=\\=|Warning|Notice|Deprecated|Fatal|Error' phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt; then
echo "**** PHP_CS has found some issues ****"
exit 1
fi
fi
- name: Upload PHP_CS Log
if: always()
uses: actions/upload-artifact@v3
with:
name: phpunit-logs
path: phpcs_PHP${{ matrix.php }}_MYSQL${{ matrix.mysql }}_codesniff_log.txt
if-no-files-found: error
retention-days: 7

unit_tests:
strategy:
matrix:
Expand Down
13 changes: 13 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>The coding standard for PHP_CodeSniffer itself.</description>
<file>source</file>
<exclude-pattern>*source/Application/views/.*$</exclude-pattern>
<exclude-pattern>*source/tmp/.*$</exclude-pattern>
<arg name="colors"/>
<arg value="p"/>
<arg value="n"/>
<arg name="parallel" value="75"/>
<arg name="extensions" value="php"/>
<rule ref="PSR12"/>
</ruleset>

0 comments on commit fbadad8

Please sign in to comment.