Skip to content

Refactor crlf check #835

Refactor crlf check

Refactor crlf check #835

Workflow file for this run

name: tests
#on: [gollum]
on: [push, pull_request]
env:
SWOW_HAVE_SSL: 1
SWOW_HAVE_CURL: 1
jobs:
cs-check:
name: Coding style check
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for CRLF endings
id: checkcrlf
continue-on-error: true
shell: php {0}
run: |
<?php
# find out files with CRLF (\r\n) line endings
$includes = [
'.'
];
$excludes = [
'/.+\.ps1$/',
'/.+\.bat$/',
'/.+\.cmd$/',
];
$files = [];
foreach ($includes as $include) {
$iteriter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($include));
foreach ($iteriter as $file) {
if ($file->isDir()) {
continue;
}
$files[] = $file->getPathname();
}
}
foreach ($excludes as $exclude) {
$files = array_filter($files, static function (string $file) use ($exclude): bool {
return !preg_match($exclude, $file);
});
}
$haveCRLF = [];
foreach ($files as $file) {
$stat = stat($file);
if ($stat['size'] >= 1024 * 1024) {
# skip large files
continue;
}
$content = file_get_contents($file);
if (strpos($content, "\0")) {
# skip binary files
continue;
}
if (strpos($content, "\r") !== false) {
# if we have a file like
# "<?php\n$someData = \"somedata\r\n\";\n"
# this is not a CRLF ending file
# while
# "<?php\r\n$someData = \"somedata\r\n\";\r\n# this file is noeol"
# is a CRLF file
# so we need to find the last (CRLF or LF) in the file, if it is CRLF, then it is a CRLF file
if (strrpos($content, "\r\n") === strrpos($content, "\n") - 1) {
echo $file . PHP_EOL;
$haveCRLF[] = $file;
}
}
}
if (count($haveCRLF) > 0) {
echo "::error::CRLF line endings found" . PHP_EOL;
exit(1);
}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
- name: Coding Standards Check
shell: bash
run: |
echo "::group::Accquire composer dependencies"
composer update -o --ignore-platform-reqs
echo "::endgroup::"
echo "::group::Run cs-check"
composer cs-check -- -v
- name: Error if CRLF found
if: steps.checkcrlf.outcome == 'success'
run: exit 1
linux-tests:
name: PHP ${{ matrix.php-version }} ${{ matrix.ts }} Test on ubuntu-latest
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
php-version: ['8.4', '8.3', '8.2', '8.1', '8.0']
#php-version: ['8.0']
#ts: ['nts', 'ts']
max-parallel: 5
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup extension dependencies
run: |
sudo apt-get update
sudo apt-get install -yqq libcurl4-openssl-dev lcov
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpize
ini-values: pcov.enabled = 0
coverage: pcov
# coverage: none
extensions: curl,openssl,sockets,ffi,pdo,pdo_pgsql
#env:
#phpts: ${{ matrix.ts }}
- name: Setup composer dependencies
run: |
php ./.github/workflows/phpunit-adapter.php ${{ matrix.php-version }}
composer update -o --ignore-platform-reqs
- name: Build Swow extension
run: |
cd ext
printf "\033[1mRun phpize\033[0m\n"
phpize
printf "\033[1mStart configure\033[0m\n"
./configure --enable-swow\
--enable-swow-debug \
--enable-swow-gcov \
--enable-swow-ssl \
--enable-swow-curl \
--enable-swow-pdo-pgsql
printf "\033[1mStart build Swow\033[0m\n"
make -j`nproc`
printf "\033[1mDone build Swow\033[0m\n"
php -d extension=.libs/swow.so --ri swow
printf "\033[1mInstall Swow\033[0m\n"
sudo make install-modules
- name: Run extension tests
id: test-extension
continue-on-error: true
run: |
TEST_SWOW_POSTGRESQL=1 composer test-extension .
- name: Run library tests
id: test-library
continue-on-error: true
run: php --ri pcov && composer test-library-with-pcov
- name: Run PHPT from php-src
id: test-php-src
continue-on-error: true
run: |
script -eqc ./.github/workflows/run-php-src-tests.sh
- name: Fail if test-extension failed
if: steps.test-extension.outcome != 'success'
run: exit 1
- name: Fail if test-library failed
if: steps.test-library.outcome != 'success'
run: exit 1
- name: Coverage ext tests
shell: bash
run: |
lcov \
--capture \
--directory "ext/src" \
--directory "ext/include" \
--output-file coverage.info &&
lcov \
--extract coverage.info \
"${{github.workspace}}/ext/include/*" \
"${{github.workspace}}/ext/src/*" \
--output-file coverage.info &&
lcov --list coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: coverage.info,./lib/swow-library/build/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
macos-tests:
name: PHP ${{ matrix.php-version }} ${{ matrix.ts }} Test on macos-latest
runs-on: "macos-latest"
strategy:
fail-fast: false
matrix:
php-version: ['8.4', '8.3', '8.2', '8.1', '8.0']
#php-version: ['8.0']
#ts: ['nts', 'ts']
max-parallel: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup extension dependencies
run: |
# [ ! -d /opt/homebrew/Cellar/pkgconf* ] && brew install pkgconf
[ ! -d /opt/homebrew/Cellar/openssl@3 ] && brew install openssl@3
[ ! -d /opt/homebrew/Cellar/curl* ] && brew install curl
[ ! -d /opt/homebrew/Cellar/postgresql* ] && brew install libpq postgresql
[ ! -d /opt/homebrew/Cellar/lcov* ] && brew install lcov
initdb --locale=C -E UTF-8 -U postgres "$HOME/pgsqldata"
pg_ctl -D "$HOME/pgsqldata" start
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpize
ini-values: pcov.enabled = 0
coverage: pcov
# coverage: none
extensions: curl,openssl,sockets,ffi,pdo,pdo_pgsql
#env:
#phpts: ${{ matrix.ts }}
- name: Setup composer dependencies
run: |
php ./.github/workflows/phpunit-adapter.php ${{ matrix.php-version }}
composer update -o --ignore-platform-reqs
# for arm64 machines:
# Warning: JIT on AArch64 doesn't support opcache.jit_buffer_size above 128M. in Unknown on line 0
if uname -m | grep -q -e arm64 -e aarch64; then
# for shivammathur/setup-php@v2 at macos
for f in \
/opt/homebrew/etc/php/${{ matrix.php-version }}/php.ini \
$(find /opt/homebrew/etc/php/${{ matrix.php-version }}/conf.d -name '*.ini' -type f)
do
sed -i -E 's/opcache.jit_buffer_size=.+/opcache.jit_buffer_size=128M/g' "$f"
done
fi
- name: Detect dependencies path from php-config
run: |
simplefind() {
find /opt/homebrew/Cellar/$1 -type d -depth 1 | head -n 1
}
echo "OPENSSL_ROOT_DIR=$(simplefind openssl@3)" >> $GITHUB_ENV
echo "CURL_ROOT_DIR=$(simplefind curl)" >> $GITHUB_ENV
echo "PGSQL_ROOT_DIR=$(simplefind libpq)" >> $GITHUB_ENV
- name: Build Swow extension
env:
CFLAGS: -I${{ env.OPENSSL_ROOT_DIR }}/include ${{ env.CFLAGS }}
CPPFLAGS: -I${{ env.OPENSSL_ROOT_DIR }}/include ${{ env.CPPFLAGS }}
LDFLAGS: -L${{ env.OPENSSL_ROOT_DIR }}/lib ${{ env.LDFLAGS }}
PKG_CONFIG_PATH: ${{ env.OPENSSL_ROOT_DIR }}/lib/pkgconfig:${{ env.PKG_CONFIG_PATH }}
run: |
cd ext
printf "\033[1mRun phpize\033[0m\n"
phpize
printf "\033[1mStart configure\033[0m\n"
./configure --enable-swow\
--enable-swow-debug \
--enable-swow-gcov \
--enable-swow-ssl=${{ env.OPENSSL_ROOT_DIR }} \
--enable-swow-curl=${{ env.CURL_ROOT_DIR }} \
--enable-swow-pdo-pgsql=${{ env.PGSQL_ROOT_DIR }}
printf "\033[1mStart build Swow\033[0m\n"
make -j`sysctl -n hw.logicalcpu`
printf "\033[1mDone build Swow\033[0m\n"
php -d extension=.libs/swow.so --ri swow
printf "\033[1mInstall Swow\033[0m\n"
make install-modules
- name: Run extension tests
id: test-extension
continue-on-error: true
run: |
TEST_SWOW_POSTGRESQL=1 composer test-extension .
- name: Run library tests
id: test-library
continue-on-error: true
run: php --ri pcov && composer test-library-with-pcov
- name: Run PHPT from php-src
id: test-php-src
continue-on-error: true
run: |
script -q whatever ./.github/workflows/run-php-src-tests.sh
- name: Fail if test-extension failed
if: steps.test-extension.outcome != 'success'
run: exit 1
- name: Fail if test-library failed
if: steps.test-library.outcome != 'success'
run: exit 1
- name: Coverage ext tests
shell: bash
run: |
lcov \
--capture \
--directory "ext/src" \
--directory "ext/include" \
--ignore-errors empty \
--output-file coverage.info &&
lcov \
--extract coverage.info \
"${{github.workspace}}/ext/include/*" \
"${{github.workspace}}/ext/src/*" \
--output-file coverage.info &&
lcov --list coverage.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: coverage.info,./lib/swow-library/build/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
windows-tests:
name: PHP ${{ matrix.php-version }} ${{ matrix.ts }} Test on ${{ matrix.image }}
runs-on: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
php-version: ["8.3", "8.2", "8.1", "8.0"]
arch: ["x64"]
ts: ["nts", "ts"]
image: [ "windows-2019" ]
include:
- php-version: "8.4"
arch: "x64"
ts: "nts"
image: "windows-2022"
- php-version: "8.4"
arch: "x64"
ts: "ts"
image: "windows-2022"
max-parallel: 10
steps:
- name: Checkout
uses: actions/checkout@v4
# TODO: windows varient of setup-php seems to be so slow
# shell we add caches?
- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-version }}
# ini-values: pcov.directory=lib
# coverage: pcov
coverage: none
extensions: curl,openssl,sockets,ffi,pdo,pdo_pgsql
env:
phpts: ${{ matrix.ts }}
- name: Setup composer dependencies
run: |
C:\tools\php\php.exe .\.github\workflows\phpunit-adapter.php ${{ matrix.php-version }}
composer update -o --ignore-platform-reqs
- name: Build Swow extension
uses: ./.github/workflows/winext
with:
ext-path: ./ext
tools-path: C:\tools\phpdev
conf-args: --enable-swow-debug --enable-swow-ssl --enable-swow-curl --enable-debug-pack --enable-swow-pdo-pgsql
ext-name: swow
deps: openssl,libcurl,libssh2,zlib,nghttp2,libpq
- name: Prepare coverage dependencies
shell: powershell
run: |
$headers = @{
"accept"="application/vnd.github.v3+json";
"content-type"="application/json";
"authorization"="Bearer ${{github.token}}";
}
# get latest OpenCppCoverage download path
Write-Host "Fetching latest OpenCppCoverage download path"
$info = Invoke-WebRequest `
-UseBasicParsing `
-Headers $headers `
-Uri https://api.github.com/repos/OpenCppCoverage/OpenCppCoverage/releases/latest `
| ConvertFrom-Json
foreach ($x in $info.assets) {
if ($x.name.EndsWith('.exe')) {
Write-Host "Downloading latest OpenCppCoverage"
$uri = $x.browser_download_url
Invoke-WebRequest -Uri $uri -OutFile OpenCppCoverage.exe -Headers $headers -UseBasicParsing
break
}
}
# install OpenCppCoverage
Write-Host "Installing OpenCppCoverage"
& .\OpenCppCoverage.exe /SP- /NORESTART /VERYSILENT /DIR=C:\OpenCppCoverage
# get latest codecov uploader download path
Write-Host "Fetching latest codecov uploader download path"
$info = Invoke-WebRequest `
-UseBasicParsing `
-Headers $headers `
-Uri https://api.github.com/repos/codecov/codecov-exe/releases/latest `
| ConvertFrom-Json
foreach ($x in $info.assets) {
if ($x.name.EndsWith('win7-x64.zip')) {
Write-Host "Downloading latest codecov uploader"
$uri = $x.browser_download_url
Invoke-WebRequest -Uri $uri -OutFile codecov.zip -Headers $headers -UseBasicParsing
break
}
}
# unzip it
Write-Host "Extracting codecov uploader"
New-Item C:\Codecov -ItemType Container | Out-Null
Expand-Archive .\codecov.zip -DestinationPath C:\Codecov
- name: Run extension tests
shell: pwsh
id: test-extension
continue-on-error: true
run: |
& "${env:PGBIN}\initdb.exe" --locale=C -E UTF-8 -U postgres "C:\pgsqldata"
& "${env:PGBIN}\pg_ctl.exe" -D "C:\pgsqldata" start
${env:TEST_SWOW_POSTGRESQL} = "1"
& C:\OpenCppCoverage\OpenCppCoverage.exe `
--export_type binary:ext_test.cov `
--sources ext\include `
--sources ext\src `
--excluded_sources ext\deps `
--cover_children `
--excluded_line_regex "\s*else.*" `
--excluded_line_regex "\s*\}.*" `
--excluded_line_regex "\s*\{\s*" `
--modules php_swow.dll `
-- C:\tools\php\php.exe C:\tools\php\composer.phar test-extension .
- name: Run library tests
shell: pwsh
id: test-library
continue-on-error: true
run: |
& C:\OpenCppCoverage\OpenCppCoverage.exe `
--export_type binary:lib_test.cov `
--sources ext\include `
--sources ext\src `
--excluded_sources ext\deps `
--cover_children `
--excluded_line_regex "\s*else.*" `
--excluded_line_regex "\s*\}.*" `
--excluded_line_regex "\s*\{\s*" `
--modules php_swow.dll `
-- C:\tools\php\php.exe C:\tools\php\composer.phar test-library
- name: Run PHPT from php-src
shell: pwsh
id: test-php-src
continue-on-error: true
run: |
./.github/workflows/run-php-src-tests.ps1
- name: Fail if test-extension failed
if: steps.test-extension.outcome != 'success'
run: exit 1
- name: Fail if test-library failed
if: steps.test-library.outcome != 'success'
run: exit 1
- name: Upload coverage tests results
shell: pwsh
run: |
# merge results
& C:\OpenCppCoverage\OpenCppCoverage.exe `
--input_coverage=ext_test.cov `
--input_coverage=lib_test.cov `
--export_type cobertura:coverage.xml `
--sources ext\include `
--sources ext\src `
--excluded_sources ext\deps `
--excluded_line_regex "\s*else.*" `
--excluded_line_regex "\s*\}.*" `
--excluded_line_regex "\s*\{\s*" `
--modules php_swow.dll `
-- C:\tools\php\php.exe -dextension=swow --ri swow
& C:\Codecov\codecov.exe -f coverage.xml