From 66dc0a7925bb72389b91c75828535c52857d1e33 Mon Sep 17 00:00:00 2001 From: John Boehr Date: Sat, 28 Sep 2024 13:36:35 -0700 Subject: [PATCH] Modernize CI configure * Add PHP 8.2-8.4 --- .editorconfig | 3 + .github/dependabot.yml | 7 + .github/workflows/ci.yml | 274 +++++++++++++++++---------- .github/workflows/windows.yml | 279 ++++++++++++++-------------- .gitignore | 3 + LICENSE.md | 2 +- config.m4 | 9 + default.nix | 20 -- flake.lock | 125 +++++++++++-- flake.nix | 243 +++++++++++++++++++++--- nix/ci.nix | 56 ------ nix/derivation.nix | 103 ++++++++-- release.nix | 29 --- tests/SampleUploadedFileFactory.inc | 6 +- 14 files changed, 751 insertions(+), 408 deletions(-) create mode 100644 .github/dependabot.yml delete mode 100644 default.nix delete mode 100644 nix/ci.nix delete mode 100644 release.nix diff --git a/.editorconfig b/.editorconfig index 8abecdd..d14501d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,5 +20,8 @@ indent_style = tab [*.yml] indent_size = 2 +[.github/**/*.yml] +indent_size = 4 + [*.md] trim_trailing_whitespace = false diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b75fee9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0c0ecf..3fcbc37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,113 +1,181 @@ name: ci on: - push: - branches: - - master - - github-actions - - ci - pull_request: - branches: - - master + push: + branches: + - master + - develop + - github-actions + - ci + pull_request: + branches: + - master jobs: - linux: - if: "!contains(github.event.head_commit.message, 'ci skip')" - name: PHP ${{ matrix.php-versions }} / ${{ matrix.operating-system }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - operating-system: [ubuntu-latest] - php-versions: - - "7.4" - - "8.0" - - "8.1" - - "8.2" - coverage: - - "true" - - "false" - steps: - - uses: actions/checkout@v3 - - run: bash .github/scripts/linux.sh - env: - PHP_VERSION: ${{ matrix.php-versions }} - COVERAGE: ${{ matrix.coverage }} - - name: Coveralls - if: ${{ matrix.coverage == 'true' }} - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./coverage.info + linux: + if: "!contains(github.event.head_commit.message, 'ci skip')" + name: PHP ${{ matrix.php-versions }} / ${{ matrix.operating-system }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest] + php-versions: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + - "8.4" + coverage: + - "true" + - "false" + steps: + - uses: actions/checkout@v3 + - run: bash .github/scripts/linux.sh + env: + PHP_VERSION: ${{ matrix.php-versions }} + COVERAGE: ${{ matrix.coverage }} + - name: Coveralls + if: ${{ matrix.coverage == 'true' }} + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: ./coverage.info - osx: - if: "!contains(github.event.head_commit.message, 'ci skip')" - name: PHP ${{ matrix.php-versions }} / ${{ matrix.operating-system }} - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: - - "macos-latest" - php-versions: - - "7.4" - - "8.0" - - "8.1" - steps: - - uses: actions/checkout@v3 - - run: bash .github/scripts/osx.sh - env: - PHP_VERSION: ${{ matrix.php-versions }} + osx: + if: "!contains(github.event.head_commit.message, 'ci skip')" + name: PHP ${{ matrix.php-versions }} / ${{ matrix.operating-system }} + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: + - "macos-latest" + php-versions: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + - "8.4" + steps: + - uses: actions/checkout@v3 + - run: bash .github/scripts/osx.sh + env: + PHP_VERSION: ${{ matrix.php-versions }} - docker: - if: "!contains(github.event.head_commit.message, 'ci skip')" - name: PHP ${{ matrix.php-versions }} / ${{ matrix.docker-image }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - docker-image: - - "alpine" - - "debian" - php-versions: - - "7.4" - - "8.0" - - "8.1" - - "8.2-rc" - steps: - - uses: actions/checkout@v3 - - run: bash .github/scripts/docker.sh - env: - PHP_VERSION: ${{ matrix.php-versions }} - DOCKER_NAME: ${{ matrix.docker-image }} + docker: + if: "!contains(github.event.head_commit.message, 'ci skip')" + name: PHP ${{ matrix.php-versions }} / ${{ matrix.docker-image }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + docker-image: + - "alpine" + - "debian" + php-versions: + - "7.4" + - "8.0" + - "8.1" + - "8.2" + - "8.3" + - "8.4.0RC1" + steps: + - uses: actions/checkout@v3 + - run: bash .github/scripts/docker.sh + env: + PHP_VERSION: ${{ matrix.php-versions }} + DOCKER_NAME: ${{ matrix.docker-image }} - docker-fedora: - if: "!contains(github.event.head_commit.message, 'ci skip')" - name: fedora - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - run: bash .github/scripts/docker.sh - env: - DOCKER_NAME: fedora - TEST_PHP_EXECUTABLE: /usr/bin/php + docker-fedora: + if: "!contains(github.event.head_commit.message, 'ci skip')" + name: fedora + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: bash .github/scripts/docker.sh + env: + DOCKER_NAME: fedora + TEST_PHP_EXECUTABLE: /usr/bin/php - nix: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-unstable - - run: nix-build - - run: nix-build nix/ci.nix + nix-matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-24.05 + extra_nix_config: "system-features = nixos-test benchmark big-parallel kvm" + - id: set-matrix + name: Generate Nix Matrix + run: | + set -Eeu + matrix="$(nix eval --json '.#githubActions.matrix')" + echo "matrix=$matrix" >> "$GITHUB_OUTPUT" - nix-flake: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v18 - with: - nix_path: nixpkgs=channel:nixos-unstable - - run: nix build - - run: nix flake check + nix: + name: "nix (${{ matrix.name }})" + runs-on: ${{ matrix.os }} + needs: nix-matrix + strategy: + matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}} + steps: + - uses: actions/checkout@v4 + + - name: Set Up Build Cache + uses: actions/cache@v4 + id: nix-cache + with: + path: /tmp/nix-store.nar + key: nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.attr }} + restore-keys: | + nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.attr }} + nix-store.nar-${{ runner.os }}-${{ hashFiles('flake.lock') }}- + nix-store.nar-${{ runner.os }}- + + - uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-24.05 + extra_nix_config: "system-features = nixos-test benchmark big-parallel kvm" + + - name: Import Nix Store Cache + if: "steps.nix-cache.outputs.cache-hit == 'true'" + run: | + nix-store --import < /tmp/nix-store.nar + + - run: nix build -L ".#${{ matrix.attr }}" + + - run: find -L result*; cp result-coverage/coverage.info coverage.info || true + + # - name: Upload coverage reports to Codecov + # if: ${{ hashFiles('coverage.info') != '' }} + # uses: codecov/codecov-action@v4 + # with: + # file: coverage.info + # token: ${{ secrets.CODECOV_TOKEN }} + # slug: jbboehr/php-perfifidous + + # - name: Coveralls + # if: ${{ hashFiles('coverage.info') != '' }} + # uses: coverallsapp/github-action@v2 + # continue-on-error: true + # with: + # file: coverage.info + # format: lcov + # parallel: true + + - name: Export Nix Store Cache + shell: bash + # partially based on /~https://github.com/NixOS/nix/issues/1245#issuecomment-282586759 + run: | + drv="$(nix-store -qd "$(readlink result)")" + drvRefs="$( echo "$drv" | xargs nix-store -q --references )" + ( echo "$drvRefs" | grep '[.]drv$' | xargs nix-store -q --outputs ; + echo "$drvRefs" | grep -v '[.]drv$' ) | \ + xargs nix-store -r | \ + xargs nix-store -qR | + xargs nix-store --export > /tmp/nix-store.nar diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 723a305..72ff645 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,157 +1,158 @@ name: windows on: - push: - branches: - - master - - dev-1.x - - github-actions - - ci - - windows - pull_request: - branches: - - master + push: + branches: + - master + - develop + - dev-1.x + - github-actions + - ci + - windows + pull_request: + branches: + - master jobs: - test_windows: - if: "!contains(github.event.head_commit.message, 'ci skip')" + test_windows: + if: "!contains(github.event.head_commit.message, 'ci skip')" - name: PHP ${{ matrix.php-versions }} / ${{ matrix.ts }} / ${{ matrix.operating-system }} - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: [windows-latest] - php-versions: ["7.4", "8.0", "8.1"] - ts: [ts, nts] - include: - - php-versions: "7.4" - vc_num: "vc15" - arch: x64 - build_type: Win32 - - php-versions: "8.0" - vc_num: "vs16" - arch: x64 - build_type: Win32 - - php-versions: "8.1" - vc_num: "vs16" - arch: x64 - build_type: Win32 + name: PHP ${{ matrix.php-versions }} / ${{ matrix.ts }} / ${{ matrix.operating-system }} + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [windows-latest] + php-versions: ["7.4", "8.0", "8.1"] + ts: [ts, nts] + include: + - php-versions: "7.4" + vc_num: "vc15" + arch: x64 + build_type: Win32 + - php-versions: "8.0" + vc_num: "vs16" + arch: x64 + build_type: Win32 + - php-versions: "8.1" + vc_num: "vs16" + arch: x64 + build_type: Win32 - steps: - - name: Disable Git autocrlf - run: git config --global core.autocrlf false + steps: + - name: Disable Git autocrlf + run: git config --global core.autocrlf false - - name: Checkout Code - uses: actions/checkout@v3 - with: - fetch-depth: 1 + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 1 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - ini-values: apc.enable_cli=on, session.save_path=C:\temp - tools: pecl - env: - PHPTS: ${{ matrix.ts }} + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + ini-values: apc.enable_cli=on, session.save_path=C:\temp + tools: pecl + env: + PHPTS: ${{ matrix.ts }} - - name: Setup Environment Variables - run: | - Write-Output "PHP_SDK_VERSION=2.2.0" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHP_DEVPACK=C:\tools\php-devpack" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHP_SDK_PATH=C:\tools\php-sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHP_PECL_PATH=C:\tools\pecl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - # FIXME: phpversion() return 7.4.3 but windows.php.net has only 7.4.4 - # We should parse the following file to get the correct version: - # https://windows.php.net/downloads/releases/sha256sum.txt - If ("${{ matrix.php-versions }}" -eq "7.4") { - Write-Output "PHP_VERSION=7.4.4" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } Else { - Write-Output "PHP_VERSION=$(php -r 'echo phpversion();')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } - Write-Output "PHP_MINOR=${{ matrix.php-versions }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "TEST_PHP_EXECUTABLE=${env:PHPROOT}\php.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "VC_VERSION=${{ matrix.vc_num }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHP_ARCH=${{ matrix.arch }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PACKAGE_PREFIX=psr" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "EXTENSION_NAME=psr" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "EXTENSION_FILE=php_psr.dll" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHPTS=${{ matrix.ts }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - If ("${{ matrix.ts }}" -eq "nts") { - Write-Output "BUILD_TYPE=nts-${{ matrix.build_type }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } Else { - Write-Output "BUILD_TYPE=${{ matrix.build_type }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - } - - name: Setup Common Environment - run: | - Import-Module .\.ci\win-ci-tools.psm1 - SetupCommonEnvironment - - name: Install PHP SDK Binary Tools - run: | - Import-Module .\.ci\win-ci-tools.psm1 - InstallPhpSdk - - name: Install PHP Dev pack - run: | - Import-Module .\.ci\win-ci-tools.psm1 - InstallPhpDevPack - - name: Getting Details About Installed PHP - run: | - Import-Module .\.ci\win-ci-tools.psm1 - Get-Php "${env:PHPROOT}" - - name: Install System Dependencies - run: choco install -y --cache-location=C:\Downloads\Choco re2c + - name: Setup Environment Variables + run: | + Write-Output "PHP_SDK_VERSION=2.2.0" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_DEVPACK=C:\tools\php-devpack" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_SDK_PATH=C:\tools\php-sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_PECL_PATH=C:\tools\pecl" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + # FIXME: phpversion() return 7.4.3 but windows.php.net has only 7.4.4 + # We should parse the following file to get the correct version: + # https://windows.php.net/downloads/releases/sha256sum.txt + If ("${{ matrix.php-versions }}" -eq "7.4") { + Write-Output "PHP_VERSION=7.4.4" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } Else { + Write-Output "PHP_VERSION=$(php -r 'echo phpversion();')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + Write-Output "PHP_MINOR=${{ matrix.php-versions }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "TEST_PHP_EXECUTABLE=${env:PHPROOT}\php.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "VC_VERSION=${{ matrix.vc_num }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHP_ARCH=${{ matrix.arch }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PACKAGE_PREFIX=psr" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "EXTENSION_NAME=psr" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "EXTENSION_FILE=php_psr.dll" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "PHPTS=${{ matrix.ts }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + If ("${{ matrix.ts }}" -eq "nts") { + Write-Output "BUILD_TYPE=nts-${{ matrix.build_type }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } Else { + Write-Output "BUILD_TYPE=${{ matrix.build_type }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + } + - name: Setup Common Environment + run: | + Import-Module .\.ci\win-ci-tools.psm1 + SetupCommonEnvironment + - name: Install PHP SDK Binary Tools + run: | + Import-Module .\.ci\win-ci-tools.psm1 + InstallPhpSdk + - name: Install PHP Dev pack + run: | + Import-Module .\.ci\win-ci-tools.psm1 + InstallPhpDevPack + - name: Getting Details About Installed PHP + run: | + Import-Module .\.ci\win-ci-tools.psm1 + Get-Php "${env:PHPROOT}" + - name: Install System Dependencies + run: choco install -y --cache-location=C:\Downloads\Choco re2c - - name: Initialize Release Variables - run: | - Import-Module .\.ci\win-ci-tools.psm1 - InitializeReleaseVars - - name: "Setup Visual Studio Command Line for PHP SDK ${{ matrix.arch }}" - run: .ci\vsenv.bat -arch=${{ matrix.arch }} -host_arch=${{ matrix.arch }} + - name: Initialize Release Variables + run: | + Import-Module .\.ci\win-ci-tools.psm1 + InitializeReleaseVars + - name: "Setup Visual Studio Command Line for PHP SDK ${{ matrix.arch }}" + run: .ci\vsenv.bat -arch=${{ matrix.arch }} -host_arch=${{ matrix.arch }} - - name: Fix Environment Variables - shell: powershell - run: | - $v = "${env:WindowsSDKVersion}" -replace '\\$', '' - Write-Output "WindowsSDKVersion=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - $v = "${env:WindowsSDKLibVersion}" -replace '\\$', '' - Write-Output "WindowsSDKLibVersion=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Fix Environment Variables + shell: powershell + run: | + $v = "${env:WindowsSDKVersion}" -replace '\\$', '' + Write-Output "WindowsSDKVersion=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + $v = "${env:WindowsSDKLibVersion}" -replace '\\$', '' + Write-Output "WindowsSDKLibVersion=$v" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - name: PSR extension | init, phpize - shell: cmd - run: | - set PATH=%PATH%;%PHP_DEVPACK% - phpize + - name: PSR extension | init, phpize + shell: cmd + run: | + set PATH=%PATH%;%PHP_DEVPACK% + phpize - - name: PSR extension | configure - shell: cmd - run: | - set PATH=%PATH%;%PHP_DEVPACK% - configure --disable-all --enable-psr --with-prefix=%PHPROOT% + - name: PSR extension | configure + shell: cmd + run: | + set PATH=%PATH%;%PHP_DEVPACK% + configure --disable-all --enable-psr --with-prefix=%PHPROOT% - - name: PSR extension | build - shell: cmd - run: | - set PATH=%PATH%;%PHP_DEVPACK% - nmake - nmake install + - name: PSR extension | build + shell: cmd + run: | + set PATH=%PATH%;%PHP_DEVPACK% + nmake + nmake install - - name: PSR extension | test - shell: cmd - run: | - set PATH=%PATH%;%PHP_DEVPACK% - nmake test + - name: PSR extension | test + shell: cmd + run: | + set PATH=%PATH%;%PHP_DEVPACK% + nmake test - - name: Upload Artifact - uses: actions/upload-artifact@v2 - with: - name: ${{ env.RELEASE_ZIPBALL }} - path: ${{ env.RELEASE_DLL_PATH }} + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.RELEASE_ZIPBALL }} + path: ${{ env.RELEASE_DLL_PATH }} - - name: Upload build artifacts after Failure - if: failure() - uses: actions/upload-artifact@v2 - with: - name: workspace - path: ${{ github.workspace }} - retention-days: 1 + - name: Upload build artifacts after Failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: workspace + path: ${{ github.workspace }} + retention-days: 1 diff --git a/.gitignore b/.gitignore index dbce29f..be88194 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,14 @@ .c9 .deps .dirstamp +.direnv .libs +.pre-commit-config.yaml .settings autom4te.cache gmon* *.a +*.dep *.la *.lo *.log diff --git a/LICENSE.md b/LICENSE.md index 11eb5d4..a63f63d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ Simplified BSD License ====================== -_Copyright © 2016-2018 John Boehr_ +_Copyright © anno Domini nostri Jesu Christi MMXVI-MMXXIV John Boehr & contributors_ _All rights reserved._ Redistribution and use in source and binary forms, with or without diff --git a/config.m4 b/config.m4 index 3304de7..448aa05 100644 --- a/config.m4 +++ b/config.m4 @@ -4,6 +4,9 @@ dnl PSR ------------------------------------------------------------------------ PHP_ARG_ENABLE(psr, whether to enable psr support, [ --enable-psr Enable PSR support]) +PHP_ARG_ENABLE(psr-coverage, whether to enable psr coverage support, +[AS_HELP_STRING([--enable-psr-coverage], [Enable psr coverage support])], [no], [no]) + dnl MAIN ------------------------------------------------------------------------- if test "$PHP_PSR" != "no"; then AH_BOTTOM([ @@ -12,6 +15,12 @@ if test "$PHP_PSR" != "no"; then #/**/undef/**/ HAVE_ASM_GOTO #endif ]) + + if test "$PHP_PSR_COVERAGE" == "yes"; then + CFLAGS="-fprofile-arcs -ftest-coverage $CFLAGS" + LDFLAGS="--coverage $LDFLAGS" + fi + AC_DEFINE(HAVE_PSR, 1, [Whether you have PSR]) PHP_NEW_EXTENSION(psr, php_psr.c psr_cache.c psr_container.c psr_http_message.c psr_link.c psr_log.c psr_simple_cache.c psr_http_server_handler.c psr_http_server_middleware.c psr_http_factory.c psr_http_client.c psr_event_dispatcher.c, $ext_shared) PHP_INSTALL_HEADERS([ext/psr], [php_psr.h psr_cache.h psr_container.h psr_http_message.h psr_link.h psr_log.h psr_simple_cache.h psr_http_server_handler.h psr_http_server_middleware.h psr_http_factory.h psr_http_client.h psr_event_dispatcher.h]) diff --git a/default.nix b/default.nix deleted file mode 100644 index 42a8a0d..0000000 --- a/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -# to use a specific version of php, run: nix-shell --arg php '(import {}).php73'` -# or clang: nix-shell --arg stdenv '(import {}).clangStdenv' -{ - system ? builtins.currentSystem, - pkgs ? import { inherit system; }, - stdenv ? pkgs.stdenv, - php ? pkgs.php, - buildPecl ? php.buildPecl, - - gitignoreSource ? (import (pkgs.fetchFromGitHub { - owner = "hercules-ci"; - repo = "gitignore"; - rev = "00b237fb1813c48e20ee2021deb6f3f03843e9e4"; - sha256 = "sha256:186pvp1y5fid8mm8c7ycjzwzhv7i6s3hh33rbi05ggrs7r3as3yy"; - }) { inherit (pkgs) lib; }).gitignoreSource, -}: - -pkgs.callPackage ./nix/derivation.nix { - inherit stdenv php buildPecl gitignoreSource; -} diff --git a/flake.lock b/flake.lock index d8415eb..fddf32d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,28 +1,33 @@ { "nodes": { - "composer2nix": { + "flake-compat": { "flake": false, "locked": { - "lastModified": 1646178110, - "narHash": "sha256-P3acfGwHYjjZQcviPiOT7T7qzzP/drc2mibzrsrNP18=", - "owner": "svanderburg", - "repo": "composer2nix", - "rev": "299caca4aac42d7639a42eb4dde951c010f6e91c", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { - "owner": "svanderburg", - "repo": "composer2nix", + "owner": "edolstra", + "repo": "flake-compat", "type": "github" } }, "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -38,11 +43,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", "type": "github" }, "original": { @@ -51,27 +56,109 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720066371, + "narHash": "sha256-uPlLYH2S0ACj0IcgaK9Lsf4spmJoGejR9DotXiXSBZQ=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "622f829f5fe69310a866c8a6cd07e747c44ef820", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1669514825, - "narHash": "sha256-O+ZV9754fLxA2JTuoLu9Bn+C27PchW2ZzcdTD3/dIT8=", + "lastModified": 1727397532, + "narHash": "sha256-pojbL/qteElw/nIXlN8kmHn/w6PQbEHr7Iz+WOXs0EM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f65141456289e81ea0d5a05af8898333cab5c53d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1727348695, + "narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=", "owner": "nixos", "repo": "nixpkgs", - "rev": "77d215150550fc3f0eb1012015f92b371e0ef2e9", + "rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784", "type": "github" }, "original": { "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": [ + "gitignore" + ], + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1727514110, + "narHash": "sha256-0YRcOxJG12VGDFH8iS8pJ0aYQQUAgo/r3ZAL+cSh9nk=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "85f7a7177c678de68224af3402ab8ee1bcee25c8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { - "composer2nix": "composer2nix", "flake-utils": "flake-utils", "gitignore": "gitignore", - "nixpkgs": "nixpkgs" + "nix-github-actions": "nix-github-actions", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable", + "pre-commit-hooks": "pre-commit-hooks", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 082ec1b..0518f6f 100644 --- a/flake.nix +++ b/flake.nix @@ -2,37 +2,232 @@ description = "php-psr"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs"; - flake-utils.url = "github:numtide/flake-utils"; - composer2nix.url = "github:svanderburg/composer2nix"; - composer2nix.flake = false; + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; + nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default"; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.systems.follows = "systems"; + }; gitignore = { - url = "github:hercules-ci/gitignore.nix"; - inputs.nixpkgs.follows = "nixpkgs"; + url = "github:hercules-ci/gitignore.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixpkgs-stable.follows = "nixpkgs"; + inputs.gitignore.follows = "gitignore"; + }; + nix-github-actions = { + url = "github:nix-community/nix-github-actions"; + inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = { self, nixpkgs, flake-utils, composer2nix, gitignore }@args: - flake-utils.lib.eachDefaultSystem (system: - let + outputs = { + self, + nixpkgs, + nixpkgs-unstable, + systems, + flake-utils, + gitignore, + pre-commit-hooks, + nix-github-actions, + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; - php = pkgs.php; - in - rec { - packages = flake-utils.lib.flattenTree rec { - composer2nix = pkgs.callPackage args.composer2nix {}; - php-psr = pkgs.callPackage ./default.nix { - inherit php; - inherit (gitignore.lib) gitignoreSource; - inherit (php) buildPecl; - }; - default = php-psr; + pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; + inherit (pkgs) lib; + + src' = gitignore.lib.gitignoreSource ./.; + + src = pkgs.lib.cleanSourceWith { + name = "php-psr-source"; + src = src'; + filter = gitignore.lib.gitignoreFilterWith { + basePath = ./.; + extraRules = '' + .clang-format + composer.json + composer.lock + .editorconfig + .envrc + .gitattributes + .github + .gitignore + *.md + *.nix + flake.* + ''; + }; }; - devShells.default = pkgs.mkShell { - inputsFrom = builtins.attrValues self.packages.${system}; - buildInputs = [ php.packages.composer ]; + makePackage = { + stdenv ? pkgs.stdenv, + php ? pkgs.php, + debugSupport ? false, + coverageSupport ? false, + }: + pkgs.callPackage ./nix/derivation.nix { + inherit src; + inherit stdenv php; + #inherit debugSupport coverageSupport; + buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") { + inherit php stdenv; + }; + }; + + makeCheck = package: + package.override { + checkSupport = true; + }; + + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = src'; + hooks = { + actionlint.enable = true; + actionlint.excludes = ["^.github\/workflows\/windows.yml"]; + alejandra.enable = true; + alejandra.excludes = ["\/vendor\/"]; + # I hate formatters + #clang-format.enable = true; + #clang-format.types_or = ["c" "c++"]; + #clang-format.files = "\\.(c|h)$"; + #markdownlint.enable = true; + #markdownlint.excludes = ["LICENSE\.md"]; + #markdownlint.settings.configuration = { + # MD013 = { + # line_length = 1488; + # # this doesn't seem to work + # table = false; + # }; + #}; + shellcheck.enable = true; + # @TODO FIXME + shellcheck.excludes = ["^.github\/scripts\/"]; + }; }; + + makeDevShell = package: + (pkgs.mkShell.override { + stdenv = package.stdenv; + }) { + inputsFrom = [package]; + buildInputs = with pkgs; [ + actionlint + autoconf-archive + clang-tools + lcov + gdb + package.php.packages.composer + valgrind + ]; + shellHook = '' + ${pre-commit-check.shellHook} + mkdir -p .direnv/include + unlink .direnv/include/php + ln -sf ${package.php.unwrapped.dev}/include/php/ .direnv/include/php + export REPORT_EXIT_STATUS=1 + export NO_INTERACTION=1 + export PATH="$PWD/vendor/bin:$PATH" + # opcache isn't getting loaded for tests because tests are run with '-n' and nixos doesn't compile + # in opcache and relies on mkWrapper to load extensions + export TEST_PHP_ARGS='-c ${package.php.phpIni}' + # php.unwrapped from the buildDeps is overwriting php + export PATH="${package.php}/bin:./vendor/bin:$PATH" + ''; + }; + + matrix = with pkgs; { + php = { + inherit php81 php82 php83; + php84 = pkgs-unstable.php84; + }; + stdenv = { + gcc = stdenv; + clang = clangStdenv; + musl = pkgsMusl.stdenv; + }; + }; + + # @see /~https://github.com/NixOS/nixpkgs/pull/110787 + buildConfs = + (lib.cartesianProductOfSets { + php = ["php81" "php82" "php83" "php84"]; + stdenv = [ + "gcc" + "clang" + # totally broken + # "musl" + ]; + coverageSupport = [false]; + }) + ++ (lib.cartesianProductOfSets { + php = ["php81" "php82" "php83" "php84"]; + stdenv = ["gcc"]; + coverageSupport = [true]; + }); + + buildFn = { + php, + stdenv, + coverageSupport ? false, + }: + lib.nameValuePair + (lib.concatStringsSep "-" (lib.filter (v: v != "") [ + "${php}" + "${stdenv}" + #(if stdenv == "gcc" then "" else "${stdenv}") + ( + if coverageSupport + then "coverage" + else "" + ) + ])) + ( + makePackage { + php = matrix.php.${php}; + stdenv = matrix.stdenv.${stdenv}; + inherit coverageSupport; + } + ); + + packages' = builtins.listToAttrs (builtins.map buildFn buildConfs); + packages = + packages' + // { + # php81 = packages.php81-gcc; + # php82 = packages.php82-gcc; + # php83 = packages.php83-gcc; + # php84 = packages.php84-gcc; + default = packages.php81-gcc; + php-psr = packages.php81-gcc; + }; + in rec { + inherit packages; + + devShells = builtins.mapAttrs (name: package: makeDevShell package) packages; + + checks = + {inherit pre-commit-check;} + // (builtins.mapAttrs (name: package: makeCheck package) packages); + + formatter = pkgs.alejandra; } - ); + ) + // { + # prolly gonna break at some point + githubActions.matrix.include = let + cleanFn = v: v // {name = builtins.replaceStrings ["githubActions." "checks." "x86_64-linux."] ["" "" ""] v.attr;}; + in + builtins.map cleanFn + (nix-github-actions.lib.mkGithubMatrix { + attrPrefix = "checks"; + checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.checks; + }) + .matrix + .include; + }; } diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index c762545..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,56 +0,0 @@ -let - generateTestsForPlatform = { system, pkgs, phpAttr, noThirdParty ? false }: - let - filterPhpExtensions = php: ({ enabled, all }: - # calendar tests are broken on 32bit? - let enabled' = (pkgs.lib.filter (e: e != php.extensions.calendar) enabled); - in enabled' ++ [ all.mongodb ]); - in - pkgs.recurseIntoAttrs { - gcc = let - php = pkgs.${phpAttr}.withExtensions (filterPhpExtensions pkgs.${phpAttr}); - in pkgs.callPackage ../default.nix { - inherit php pkgs; - buildPecl = php.buildPecl; - }; - - clang = let - php = pkgs.${phpAttr}.withExtensions (filterPhpExtensions pkgs.${phpAttr}); - stdenv = pkgs.clangStdenv; - in pkgs.callPackage ../default.nix { - inherit php stdenv pkgs; - buildPecl = php.buildPecl; - }; - }; -in -builtins.mapAttrs (k: _v: - let - path = builtins.fetchTarball { - url = /~https://github.com/NixOS/nixpkgs/archive/nixos-22.05.tar.gz; - name = "nixos-22.05"; - }; - system = k; - pkgs = import (path) { inherit system; }; - - in - pkgs.recurseIntoAttrs { - php74 = generateTestsForPlatform { - inherit system pkgs; - phpAttr = "php74"; - }; - - php80 = generateTestsForPlatform { - inherit system pkgs; - phpAttr = "php80"; - }; - - php81 = generateTestsForPlatform { - inherit system pkgs; - phpAttr = "php81"; - }; - } -) { - x86_64-linux = {}; - # Uncomment to test build on macOS too - # x86_64-darwin = {}; -} diff --git a/nix/derivation.nix b/nix/derivation.nix index 8cafe3b..de1d2df 100644 --- a/nix/derivation.nix +++ b/nix/derivation.nix @@ -1,22 +1,97 @@ +# Copyright (c) anno Domini nostri Jesu Christi MMXVI-MMXXIV John Boehr & contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . { - lib, stdenv, autoreconfHook, fetchurl, - php, buildPecl, gitignoreSource + lib, + php, + stdenv, + pkg-config, + valgrind, + autoreconfHook, + buildPecl, + src, + lcov, + checkSupport ? false, + debugSupport ? false, + valgrindSupport ? true, + coverageSupport ? false, }: - -buildPecl rec { +(buildPecl rec { pname = "psr"; name = "psr-${version}"; - version = "v1.0.0"; + version = "v1.2.0"; + + inherit src; + + nativeBuildInputs = + [php.unwrapped.dev pkg-config] + ++ lib.optional valgrindSupport valgrind + ++ lib.optional coverageSupport lcov; - src = lib.cleanSourceWith { - filter = (path: type: (builtins.all (x: x != baseNameOf path) - [".idea" ".git" ".github" "ci.nix" ".ci" "nix" "default.nix" "flake.nix" "flake.lock"])); - src = gitignoreSource ../.; + passthru = { + inherit php stdenv; }; - makeFlags = ["phpincludedir=$(out)/include/php/ext/psr"]; + configureFlags = + [] + ++ lib.optional coverageSupport ["--enable-psr-coverage"]; + + makeFlags = ["phpincludedir=$(dev)/include"]; + outputs = + lib.optional (checkSupport && coverageSupport) "coverage" + ++ ["out" "dev"]; + + doCheck = checkSupport; + theRealFuckingCheckPhase = + '' + runHook preCheck + REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n" || (find tests -name '*.log' | xargs cat ; exit 1) + '' + + (lib.optionalString valgrindSupport '' + USE_ZEND_ALLOC=0 REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test TEST_PHP_ARGS="-n -m" || (find tests -name '*.mem' | xargs cat ; exit 1) + '') + + '' + runHook postCheck + ''; + + preBuild = lib.optionalString coverageSupport '' + lcov --directory . --zerocounters + lcov --directory . --capture --compat-libtool --initial --output-file coverage.info + ''; + + postCheck = lib.optionalString coverageSupport '' + lcov --no-checksum --directory . --capture --no-markers --compat-libtool --output-file coverage.info + set -o noglob + lcov --remove coverage.info '${builtins.storeDir}/*' \ + --compat-libtool \ + --output-file coverage.info + set +o noglob + mkdir -p $coverage + cp coverage.info $coverage/coverage.info + genhtml coverage.info -o $coverage/html/ + ''; + + meta = with lib; { + homepage = "/~https://github.com/jbboehr/php-psr"; + license = licenses.bsd3; + outputsToInstall = outputs; + }; - doCheck = true; - checkTarget = "test"; - checkFlags = ["REPORT_EXIT_STATUS=1" "NO_INTERACTION=1"]; # "TEST_PHP_DETAILED=1" -} + #TEST_PHP_DETAILED = 1; +}) +.overrideAttrs (o: + o + // { + checkPhase = o.theRealFuckingCheckPhase; + }) diff --git a/release.nix b/release.nix deleted file mode 100644 index b268e08..0000000 --- a/release.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ - system ? builtins.currentSystem, - pkgs ? import { inherit system; }, - stdenv ? pkgs.stdenv, - php ? pkgs.php.buildEnv { - extensions = { all, ... }: with all; [ zlib ]; - }, - gitignoreSource ? (import (pkgs.fetchFromGitHub { - owner = "hercules-ci"; - repo = "gitignore"; - rev = "00b237fb1813c48e20ee2021deb6f3f03843e9e4"; - sha256 = "sha256:186pvp1y5fid8mm8c7ycjzwzhv7i6s3hh33rbi05ggrs7r3as3yy"; - }) { inherit (pkgs) lib; }).gitignoreSource, - phpPsrSrc ? pkgs.lib.cleanSourceWith { - filter = (path: type: (builtins.all (x: x != baseNameOf path) [".idea" ".git" ".github" "ci.nix" ".ci" "nix" "default.nix"])); - src = gitignoreSource ./.; - } -}: - -{ - dist = pkgs.runCommand "psr-pecl.tgz" { - buildInputs = [php]; - src = phpPsrSrc; - } '' - cp -r $src/* . - PHP_PEAR_PHP_BIN=${php}/bin/php pecl package - mv psr-*.tgz $out - ''; -} diff --git a/tests/SampleUploadedFileFactory.inc b/tests/SampleUploadedFileFactory.inc index b5aadae..626c245 100644 --- a/tests/SampleUploadedFileFactory.inc +++ b/tests/SampleUploadedFileFactory.inc @@ -8,10 +8,10 @@ class SampleUploadedFileFactory implements UploadedFileFactoryInterface { public function createUploadedFile( StreamInterface $stream, - int $size = null, + ?int $size = null, int $error = \UPLOAD_ERR_OK, - string $clientFilename = null, - string $clientMediaType = null + ?string $clientFilename = null, + ?string $clientMediaType = null ): UploadedFileInterface { var_dump(__METHOD__, $stream, $size, $error, $clientFilename, $clientMediaType);