diff --git a/.ci/release-notes.sh b/.ci/release-notes.sh index 03492db3..53b564bc 100755 --- a/.ci/release-notes.sh +++ b/.ci/release-notes.sh @@ -22,14 +22,4 @@ startline=$(cat "$1" | grep -nE '^### ' | head -n 1 | cut -d ":" -f 1) finishline=$(($(cat "$1" | grep -nE '^## \[[0-9]+' | head -n 2 | tail -n 1 | cut -d ":" -f 1) - 1)) changelog=$(sed -n "${startline},${finishline}p" "$1"); - -: "${GITHUB_ACTIONS:=0}" - -if [ "$GITHUB_ACTIONS" = "true" ] -then - changelog="${changelog//'%'/'%25'}" - changelog="${changelog//$'\n'/'%0A'}" - changelog="${changelog//$'\r'/'%0D'}" -fi - echo "${changelog}" diff --git a/.ci/win-ci-tools.psm1 b/.ci/win-ci-tools.psm1 deleted file mode 100644 index 2d63a637..00000000 --- a/.ci/win-ci-tools.psm1 +++ /dev/null @@ -1,417 +0,0 @@ -# This file is part of the Zephir Parser. -# -# (c) Zephir Team -# -# For the full copyright and license information, please view -# the LICENSE file that was distributed with this source code. - -function SetupCommonEnvironment { - <# - .SYNOPSIS - Creates common directories if not exists - #> - - $CommonPath = "C:\Downloads", "C:\Downloads\Choco" - - foreach ($path in $CommonPath) { - if (-not (Test-Path $path)) { - New-Item -ItemType Directory -Force -Path $path | Out-Null - } - } - - # Hide "You are in 'detached HEAD' state" message - git config --global advice.detachedHead false -} - -function InitializeReleaseVars { - <# - .SYNOPSIS - Configures Environment variables for Release build. - #> - - # Build artifacts should be names like this: - # zephir-parser-php-7.0-nts-win32-vc14-x86.zip - # zephir-parser-php-7.0-ts-win32-vc14-x64.zip - - $VC_Prefix = "vc" - if (${env:VC_VERSION} -ge 16) { - $VC_Prefix = "vc" - } - - # Configure for Windows define `BUILD_DIR` using the next logic: - # - # Release ZTS x86 => Release_TS\php_zephir_parser.dll - # Release NTS x86 => Release\php_zephir_parser.dll - # Release ZTS x64 => x64\Release_TS\php_zephir_parser.dll - # Release NTS x64 => x64\Release\php_zephir_parser.dll - - $env:RELEASE_FOLDER = "Release" - if (${env:BUILD_TYPE} -eq 'ts') { - $env:RELEASE_FOLDER = -join($env:RELEASE_FOLDER, "_TS") - } - - if (${env:PHP_ARCH} -eq 'x64') { - $env:RELEASE_FOLDER = -join("x64\", $env:RELEASE_FOLDER) - } - - $env:RELEASE_DLL_PATH = "${env:GITHUB_WORKSPACE}\${env:RELEASE_FOLDER}\${env:EXTENSION_FILE}" - $env:RELEASE_ZIPBALL = "zephir-parser-php-${env:PHP_MINOR}-${env:BUILD_TYPE}-win32-${VC_Prefix}${env:VC_VERSION}-${env:PHP_ARCH}" - - Write-Output "RELEASE_FOLDER=${env:RELEASE_FOLDER}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "RELEASE_ZIPBALL=${env:RELEASE_ZIPBALL}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "RELEASE_DLL_PATH=${env:RELEASE_DLL_PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append -} - -function InstallPhpSdk { - <# - .SYNOPSIS - Install PHP SDK binary tools from sources. - #> - - Write-Output "Install PHP SDK binary tools: ${env:PHP_SDK_VERSION}" - - $PhpSdk = "php-sdk-${env:PHP_SDK_VERSION}.zip" - $RemoteUrl = "https://github.com/microsoft/php-sdk-binary-tools/archive/${PhpSdk}" - $DestinationPath = "C:\Downloads\${PhpSdk}" - - if (-not (Test-Path $env:PHP_SDK_PATH)) { - if (-not [System.IO.File]::Exists($DestinationPath)) { - Write-Output "Downloading PHP SDK binary tools: $RemoteUrl ..." - DownloadFile $RemoteUrl $DestinationPath - } - - $DestinationUnzipPath = "${env:Temp}\php-sdk-binary-tools-php-sdk-${env:PHP_SDK_VERSION}" - - if (-not (Test-Path "$DestinationUnzipPath")) { - Expand-Item7zip $DestinationPath $env:Temp - } - - Move-Item -Path $DestinationUnzipPath -Destination $env:PHP_SDK_PATH - } -} - -function InstallPhpDevPack { - <# - .SYNOPSIS - Intstall PHP Developer pack from sources. - #> - - Write-Output "Install PHP Dev pack: ${env:PHP_VERSION}" - - $TS = Get-ThreadSafety - - if ($env:VC_VERSION -gt 15) { - $VSPrefix = "VS" - $VSPrefixSmall = "vs" - } else { - $VSPrefix = "VC" - $VSPrefixSmall = "vc" - } - - $BaseUrl = "http://windows.php.net/downloads/releases" - $DevPack = "php-devel-pack-${env:PHP_VERSION}${TS}-Win32-${VSPrefixSmall}${env:VC_VERSION}-${env:PHP_ARCH}.zip" - - $RemoteUrl = "${BaseUrl}/${DevPack}" - $RemoteArchiveUrl = "${BaseUrl}/archives/${DevPack}" - $DestinationPath = "C:\Downloads\php-devel-pack-${env:PHP_VERSION}${TS}-${VSPrefix}${env:VC_VERSION}-${env:PHP_ARCH}.zip" - - if (-not (Test-Path $env:PHP_DEVPACK)) { - if (-not [System.IO.File]::Exists($DestinationPath)) { - DownloadFileUsingAlternative -RemoteUrl $RemoteUrl ` - -RemoteArchiveUrl $RemoteArchiveUrl ` - -DestinationPath $DestinationPath ` - -Message "Downloading PHP Dev pack" - } - - $DestinationUnzipPath = "${env:Temp}\php-${env:PHP_VERSION}-devel-${VSPrefix}${env:VC_VERSION}-${env:PHP_ARCH}" - - if (-not (Test-Path "$DestinationUnzipPath")) { - Expand-Item7zip $DestinationPath $env:Temp - } - - Move-Item -Path $DestinationUnzipPath -Destination $env:PHP_DEVPACK - } -} - -function DownloadFileUsingAlternative { - <# - .SYNOPSIS - Downloads files from URL using alternative ULR if primary URL not found - #> - - [CmdletBinding()] - param( - [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteUrl, - [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteArchiveUrl, - [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $DestinationPath, - [parameter(Mandatory = $true, ValueFromPipeline = $true)] [ValidateNotNullOrEmpty()] [System.String] $Message - ) - - process { - try { - Write-Output "${Message}: ${RemoteUrl} ..." - DownloadFile $RemoteUrl $DestinationPath - } catch [System.Net.WebException] { - Write-Output "${Message} from archive: ${RemoteArchiveUrl} ..." - DownloadFile $RemoteArchiveUrl $DestinationPath - } - } -} - -function DownloadFile { - <# - .SYNOPSIS - Downloads file from providing URL to specified destionation. - - .NOTES - Throws System.Net.WebException if $RequestUrl not found. - #> - - [CmdletBinding()] - param( - [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $RemoteUrl, - [parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $DestinationPath - ) - - process { - $RetryMax = 5 - $RetryCount = 0 - $Completed = $false - - $WebClient = New-Object System.Net.WebClient - $WebClient.Headers.Add('User-Agent', 'GitHub Actions PowerShell Script') - - while (-not $Completed -or $RetryCount -eq $RetryMax) { - try { - $WebClient.DownloadFile($RemoteUrl, $DestinationPath) - $Completed = $true - } catch [System.Net.WebException] { - $ErrorMessage = $_.Exception.Message - - if ($_.Exception.Response.StatusCode -eq 404) { - Write-Warning -Message "Error downloading ${RemoteUrl}: $ErrorMessage" - throw [System.Net.WebException] "Error downloading ${RemoteUrl}" - } - - if ($RetryCount -ge $RetryMax) { - Write-Output "Error downloading ${RemoteUrl}: $ErrorMessage" - $Completed = $true - } else { - $RetryCount++ - } - } - } - } -} - -function Expand-Item7zip { - <# - .SYNOPSIS - Extracts ZIP archives to specified directory - #> - - param( - [Parameter(Mandatory = $true)] [System.String] $Archive, - [Parameter(Mandatory = $true)] [System.String] $Destination - ) - - if (-not (Test-Path -Path $Archive -PathType Leaf)) { - throw "Specified archive File is invalid: [$Archive]" - } - - if (-not (Test-Path -Path $Destination -PathType Container)) { - New-Item $Destination -ItemType Directory | Out-Null - } - - $Result = (& 7z x "$Archive" "-o$Destination" -aoa -bd -y -r) - - if ($LastExitCode -ne 0) { - Write-Output "An error occurred while unzipping [$Archive] to [$Destination]. Error code was: ${LastExitCode}" - Exit $LastExitCode - } -} - -function Get-ThreadSafety { - <# - .SYNOPSIS - Detects if Build is Thread Safety or not and returns `ts` suffix. - #> - - if ($env:BUILD_TYPE -Match "nts") { - return "-nts" - } - - return [string]::Empty -} - -function AppendSessionPath { - [string[]] $PathsCollection = @( - "${Env:VSCOMNTOOLS}\..\..\VC", - "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC", - "C:\Program Files (x86)\Microsoft Visual Studio ${Env:VC_VERSION}.0\VC\bin", - "${Env:VSCOMNTOOLS}", - "C:\php" - "C:\php\bin" - "C:\php-sdk\bin", - "C:\php-devpack" - ) - - $CurrentPath = (Get-Item -Path ".\" -Verbose).FullName - - ForEach ($PathItem In $PathsCollection) { - Set-Location Env: - $AllPaths = (Get-ChildItem Path).value.split(";") | Sort-Object -Unique - $AddToPath = $true - - ForEach ($AddedPath In $AllPaths) { - If (-not "${AddedPath}") { - continue - } - - $AddedPath = $AddedPath -replace '\\$', '' - - If ($PathItem -eq $AddedPath) { - $AddToPath = $false - } - } - - If ($AddToPath) { - $Env:Path += ";$PathItem" - } - } - - Set-Location "${CurrentPath}" -} - -function EnableExtension { - <# - .SYNOPSIS - Enables PHP Extension. - #> - - if (-not (Test-Path env:RELEASE_DLL_PATH)) { - InitializeReleaseVars - } - - if (-not (Test-Path "${env:RELEASE_DLL_PATH}")) { - throw "Unable to locate extension path: ${env:RELEASE_DLL_PATH}" - } - - Copy-Item -Path "${env:RELEASE_DLL_PATH}" -Destination "${env:PHPROOT}\ext\" - - Enable-PhpExtension -Extension zephir_parser -Path "${env:PHPROOT}" -} - -function PrepareReleasePackage { - param ( - [Parameter(Mandatory=$true)] [System.String] $PhpVersion, - [Parameter(Mandatory=$true)] [System.String] $BuildType, - [Parameter(Mandatory=$true)] [System.String] $Platform, - [Parameter(Mandatory=$false)] [System.String] $ZipballName = '', - [Parameter(Mandatory=$false)] [System.String[]] $ReleaseFiles = @(), - [Parameter(Mandatory=$false)] [System.String] $ReleaseFile = 'RELEASE.txt', - [Parameter(Mandatory=$false)] [System.Boolean] $ConvertMd2Html = $false, - [Parameter(Mandatory=$false)] [System.String] $BasePath = '.' - ) - - $BasePath = Resolve-Path $BasePath - $ReleaseDirectory = "${Env:GITHUB_ACTOR}-${Env:RUNNER_OS}-${Env:GITHUB_JOB}-${Env:GITHUB_RUN_NUMBER}" - - Write-Output "ReleaseDirectory: ${ReleaseDirectory}" - - PrepareReleaseNote ` - -PhpVersion $PhpVersion ` - -BuildType $BuildType ` - -Platform $Platform ` - -ReleaseFile $ReleaseFile ` - -ReleaseDirectory $ReleaseDirectory ` - -BasePath $BasePath - - $ReleaseDestination = "${BasePath}\${ReleaseDirectory}" - - $CurrentPath = Resolve-Path '.' - - if ($ConvertMd2Html) { - FormatReleaseFiles -ReleaseDirectory $ReleaseDirectory - } - - if ($ReleaseFiles.count -gt 0) { - foreach ($File in $ReleaseFiles) { - Copy-Item "${File}" "${ReleaseDestination}" - Write-Debug "Copy ${File} to ${ReleaseDestination}" - } - } - - if (!$ZipballName) { - if (!$Env:RELEASE_ZIPBALL) { - throw "Required parameter `"ZipballName`" is missing" - } else { - $ZipballName = $Env:RELEASE_ZIPBALL; - } - } - - Set-Location "${ReleaseDestination}" - $Output = (& 7z a "${ZipballName}.zip" *) - $ExitCode = $LASTEXITCODE - - $DirectoryContents = Get-ChildItem -Path "${ReleaseDestination}" - Write-Debug ($DirectoryContents | Out-String) - - if ($ExitCode -ne 0) { - Set-Location "${CurrentPath}" - throw "An error occurred while creating release zipball: `"${ZipballName}`". ${Output}" - } - - Move-Item "${ZipballName}.zip" -Destination "${BasePath}" - Write-Output "Release file created: ${BasePath}\${ZipballName}.zip" - Set-Location "${CurrentPath}" -} - -function PrepareReleaseNote { - param ( - [Parameter(Mandatory=$true)] [System.String] $PhpVersion, - [Parameter(Mandatory=$true)] [System.String] $BuildType, - [Parameter(Mandatory=$true)] [System.String] $Platform, - [Parameter(Mandatory=$false)] [System.String] $ReleaseFile, - [Parameter(Mandatory=$false)] [System.String] $ReleaseDirectory, - [Parameter(Mandatory=$false)] [System.String] $BasePath - ) - - $Destination = "${BasePath}\${ReleaseDirectory}" - - if (-not (Test-Path $Destination)) { - New-Item -ItemType Directory -Force -Path "${Destination}" | Out-Null - } - - $ReleaseFile = "${Destination}\${ReleaseFile}" - $ReleaseDate = Get-Date -Format o - - $Version = Get-Content (Join-Path -Path ${BasePath} -ChildPath 'VERSION') -First 1 - - Write-Output "Release date: ${ReleaseDate}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" - Write-Output "Release version: ${Version}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" - Write-Output "Git commit: ${Env:GITHUB_SHA}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" - Write-Output "Build type: ${BuildType}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" - Write-Output "Platform: ${Platform}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" - Write-Output "Target PHP version: ${PhpVersion}" | Out-File -Encoding "ASCII" -Append "${ReleaseFile}" -} - -function FormatReleaseFiles { - param ( - [Parameter(Mandatory=$true)] [System.String] $ReleaseDirectory, - [Parameter(Mandatory=$false)] [System.String] $BasePath = '.' - ) - - $CurrentPath = (Get-Item -Path ".\" -Verbose).FullName - - $BasePath = Resolve-Path $BasePath - Set-Location "${BasePath}" - - Get-ChildItem (Get-Item -Path ".\" -Verbose).FullName *.md | - ForEach-Object{ - $BaseName = $_.BaseName - pandoc -f markdown -t html5 "${BaseName}.md" > "${BasePath}\${ReleaseDirectory}\${BaseName}.html" - } - - Set-Location "${CurrentPath}" -} diff --git a/.gitattributes b/.gitattributes index 4be68cd3..02c4a822 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,12 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto eol=lf + *.c linguist-language=C *.h linguist-language=C *.w32 linguist-language=JavaScript *.inc linguist-language=PHP + +# Enable commit diffs for binary PHP test files. Some PHP test files include +# special characters, such as ASCII control characters. Git recognizes these as +# binary and wouldn't generate diffs. +*.phpt diff eol=lf diff --git a/.github/actions/build-linux/action.yml b/.github/actions/build-linux/action.yml new file mode 100644 index 00000000..b09f50cb --- /dev/null +++ b/.github/actions/build-linux/action.yml @@ -0,0 +1,42 @@ +name: 'Zephir Parser PHP extension build action' +description: 'Build Zephir Parser for Linux according to various PHP versions.' + +runs: + using: 'composite' + steps: + - name: Install RE2C Lexer Generator + shell: bash + run: | + sudo apt-get update --quiet --yes 1>/dev/null + sudo apt-get install re2c lcov + + - name: Build Zephir Parser for Linux + shell: bash + working-directory: ${{ github.workspace }} + run: | + echo "::group::Run phpize" + phpize + echo "::endgroup::" + + echo "::group::Run configure" + ./configure \ + --enable-zephir-parser \ + --enable-zephir-parser-debug \ + ${{ env.CONFIGURE_COVERAGE }} + echo "::endgroup::" + + echo "::group::Compile" + make -j$(getconf _NPROCESSORS_ONLN) + echo "::endgroup::" + + - name: Preparing to collect coverage data + if: matrix.ccov == 'ON' + shell: bash + run: make coverage-initial + + - name: Enable Zephir Parser + shell: bash + run: | + sudo cp ./modules/zephir_parser.so "$(php -r 'echo ini_get("extension_dir");')/zephir_parser.so" + echo "extension=zephir_parser.so" > ./ext-zephir_parser.ini + sudo cp ./ext-zephir_parser.ini /etc/php/${{ matrix.php }}/cli/conf.d/20-zephir_parser.ini diff --git a/.github/actions/build-mac/action.yml b/.github/actions/build-mac/action.yml new file mode 100644 index 00000000..b58d85fc --- /dev/null +++ b/.github/actions/build-mac/action.yml @@ -0,0 +1,42 @@ +name: 'Zephir Parser PHP extension build action' +description: 'Build Zephir Parser for macOS according to various PHP versions.' + +runs: + using: 'composite' + steps: + - name: Install RE2C Lexer Generator + shell: bash + run: | + brew install re2c lcov + env: + HOMEBREW_NO_INSTALL_CLEANUP: 1 + + - name: Build Zephir Parser for macOS + shell: bash + working-directory: ${{ github.workspace }} + run: | + echo "::group::Run phpize" + phpize + echo "::endgroup::" + + echo "::group::Run configure" + ./configure \ + --enable-zephir-parser \ + --enable-zephir-parser-debug \ + ${{ env.CONFIGURE_COVERAGE }} + echo "::endgroup::" + + echo "::group::Compile" + make -j$(getconf _NPROCESSORS_ONLN) + echo "::endgroup::" + + - name: Preparing to collect coverage data + if: matrix.ccov == 'ON' + shell: bash + run: make coverage-initial + + - name: Enable Zephir Parser + shell: bash + run: | + cp ./modules/zephir_parser.so "$(php -r 'echo ini_get("extension_dir");')/zephir_parser.so" + echo "extension=zephir_parser.so" > /usr/local/etc/php/${{ matrix.php }}/conf.d/ext-zephir_parser.ini diff --git a/.github/actions/build-win/action.yml b/.github/actions/build-win/action.yml new file mode 100644 index 00000000..e7faacb1 --- /dev/null +++ b/.github/actions/build-win/action.yml @@ -0,0 +1,113 @@ +name: 'Zephir Parser PHP extension build action' +description: 'Build Zephir Parser for Windows according to various PHP versions.' + +inputs: + php_version: + description: 'PHP version to build for (e.g: 7.4, 8.0)' + required: true + ts: + description: 'Thread Safety' + required: false + default: 'nts' + msvc: + description: 'Microsoft Visual C++ compiler toolset prefix (e.g: vc14, vs15, vs16)' + required: true + arch: + description: 'Target architecture (x64, x86)' + required: false + default: 'x64' + +runs: + using: 'composite' + steps: + - name: Install RE2C Lexer Generator + shell: powershell + run: | + mkdir ${{ env.CACHE_DIR }}\Choco + choco install --no-progress -y --cache-location=${{ env.CACHE_DIR }}\Choco re2c + + - name: Install PHP PowerShell Manager + shell: powershell + run: | + Write-Output "::group::Install PowerShell PHP Manager module" + if (Get-Module -ListAvailable -Name PhpManager) { + Write-Host "PhpManager powershell module exist, skip install" + } else { + Install-Module -Name PhpManager -Repository PSGallery -Force + } + Write-Output "::endgroup::" + + - name: Compile Lemon Parser + shell: powershell + run: | + .\.ci\lemon-parser.ps1 + + - name: Setup PHP SDK tool kit + uses: zephir-lang/setup-php-sdk@v1 + with: + php_version: ${{ inputs.php_version }} + ts: ${{ inputs.ts }} + msvc: ${{ inputs.msvc }} + arch: ${{ inputs.arch }} + install_dir: ${{ env.TOOLS_DIR }} + cache_dir: ${{ env.CACHE_DIR }} + + - name: Configure Developer Command Prompt for MSVC compiler + uses: ilammy/msvc-dev-cmd@v1.10.0 + with: + arch: ${{ inputs.arch }} + + # Workaround for + # PHP Warning: PHP Startup: Can't load module 'C:\tools\php\ext\php_zephir_parser.dll' + # as it's linked with 14.29, but the core is linked with 14.16 in Unknown on line 0 + - name: Configure Developer Command Prompt for MSVC compiler + uses: ilammy/msvc-dev-cmd@v1.10.0 + if: ${{ inputs.php_version }} == '7.4' + with: + arch: ${{ inputs.arch }} + toolset: 14.16 + + - name: Getting Details About Installed PHP + shell: powershell + run: | + Get-Php (Get-Command php).Path + + - name: Phpize + shell: powershell + working-directory: ${{ github.workspace }} + run: | + echo "::group::Run phpize" + phpize + echo "::endgroup::" + + - name: Configure + shell: powershell + working-directory: ${{ github.workspace }} + run: | + echo "::group::Run configure" + .\configure.bat ` + --with-codegen-arch=yes ` + --with-prefix=${{ env.TOOLS_DIR }}\php ` + --with-php-build=${{ env.TOOLS_DIR }}\php-devpack ` + --disable-all ` + --enable-zephir-parser=shared ` + --enable-zephir-parser-debug + echo "::endgroup::" + + - name: Compile + shell: powershell + working-directory: ${{ github.workspace }} + run: | + echo "::group::Compile" + nmake + echo "::endgroup::" + + - name: Enable Zephir Parser + shell: powershell + run: | + $ReleaseFolder = if ("${{ inputs.ts }}" -eq "ts") { "Release_TS" } else { "Release" } + $ReleaseFolder = if ("${{ inputs.arch }}" -eq "x64") { "x64\${ReleaseFolder}" } else { "${ReleaseFolder}" } + $ReleaseDllPath = "${{ github.workspace }}\${ReleaseFolder}\php_zephir_parser.dll" + + Copy-Item -Path "$ReleaseDllPath" -Destination "${{ env.TOOLS_DIR }}\php\ext\" + Enable-PhpExtension -Extension 'zephir_parser' -Path "${{ env.TOOLS_DIR }}\php" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26b06c08..7cfeb8ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,10 @@ +# This file is part of the Zephir Parser. +# +# (c) Zephir Team +# +# For the full copyright and license information, please view +# the LICENSE file that was distributed with this source code. + name: Zephir Parser CI on: @@ -11,358 +18,230 @@ on: env: RE2C_VERSION: 2.2 - PHP_SDK_VERSION: 2.2.0 - PHP_DEVPACK: C:\tools\php-devpack - PHP_SDK_PATH: C:\tools\php-sdk - EXTENSION_FILE: php_zephir_parser.dll + CONFIGURE_COVERAGE: '' # Configure options for overage is empty by default jobs: - windows-builds: - # To prevent build a particular commit use - # git commit -m "......... [win skip] - skip Windows builds only" - # git commit -m "......... [ci skip] - skip all builds" - if: "!contains(github.event.head_commit.message, '[win skip]') || !contains(github.event.head_commit.message, '[ci skip]') " + builds: + name: PHP-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.arch }} + runs-on: ${{ matrix.os }} strategy: fail-fast: false - matrix: - php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - arch: ['x86', 'x64'] - build_type: ['ts', 'nts'] + php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ] + ts: [ 'nts' ] + arch: [ 'x64' ] + name: + - ubuntu-gcc + - macos-clang + + # matrix names should be in next format: + # {php}-{ts}-{os.name}-{compiler}-{arch} include: - - php: '7.0' - vc_num: 14 - vc_prefix: 'vc' - os: windows-2016 - - - php: '7.1' - vc_num: 14 - vc_prefix: 'vc' - os: windows-2016 - - - php: '7.2' - vc_num: 15 - vc_prefix: 'vc' - os: windows-2016 - - - php: '7.3' - vc_num: 15 - vc_prefix: 'vc' - os: windows-2016 - - - php: '7.4' - vc_num: 15 - vc_prefix: 'vc' - os: windows-2016 - - - php: '8.0' - vc_num: 16 - vc_prefix: 'vs' - os: windows-2019 - - - php: '8.1' - vc_num: 16 - vc_prefix: 'vs' - os: windows-2019 - - name: "PHP-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}" - runs-on: ${{ matrix.os}} + # Linux + - { name: ubuntu-gcc, os: ubuntu-18.04, compiler: gcc, ccov: 'ON' } + # macOS + - { name: macos-clang, os: macos-10.15, compiler: clang, ccov: 'ON' } + # Windows + - { php: '7.0', ts: 'nts', arch: 'x64', name: 'windows2019-vc14', os: 'windows-2019', compiler: 'vc14', ccov: 'OFF' } + - { php: '7.1', ts: 'nts', arch: 'x64', name: 'windows2019-vc14', os: 'windows-2019', compiler: 'vc14', ccov: 'OFF' } + - { php: '7.2', ts: 'nts', arch: 'x64', name: 'windows2019-vc15', os: 'windows-2019', compiler: 'vc15', ccov: 'OFF' } + - { php: '7.3', ts: 'nts', arch: 'x64', name: 'windows2019-vc15', os: 'windows-2019', compiler: 'vc15', ccov: 'OFF' } + - { php: '7.4', ts: 'nts', arch: 'x64', name: 'windows2019-vc15', os: 'windows-2019', compiler: 'vc15', ccov: 'OFF' } + - { php: '8.0', ts: 'nts', arch: 'x64', name: 'windows2019-vs16', os: 'windows-2019', compiler: 'vs16', ccov: 'OFF' } + - { php: '8.1', ts: 'nts', arch: 'x64', name: 'windows2019-vs16', os: 'windows-2019', compiler: 'vs16', ccov: 'OFF' } steps: - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - name: Setup PHP + - name: Install PHP ${{ matrix.php }} uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php }} + php-version: '${{ matrix.php }}' coverage: none env: - PHPTS: ${{ matrix.build_type }} + PHPTS: ${{ matrix.ts }} - - name: Set Environment Variables + - name: Setup Build System + shell: bash run: | - Write-Output "PHP_VERSION=$(php -r 'echo phpversion();')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - Write-Output "PHP_MINOR=${{ matrix.php }}" | 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 "BUILD_TYPE=${{ matrix.build_type }}" | 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 "BUILD_VERSION=${env:GITHUB_RUN_NUMBER}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append - - - name: Setup Common Environmet - run: | - Import-Module .\.ci\win-ci-tools.psm1 - SetupCommonEnvironment - InitializeReleaseVars - - - name: Cache Downloads - uses: actions/cache@v2 - with: - path: C:\Downloads - key: ${{ runner.os }}-zephir_parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }} + echo "::group::Enable Code Coverage Capture" + if [ "${{ matrix.ccov }}" = "ON" ]; then + echo "CONFIGURE_COVERAGE=--enable-coverage" >> $GITHUB_ENV + fi + echo "::endgroup::" - - name: Install System Dependencies - run: | - choco install -y --no-progress --cache-location=C:\Downloads\Choco pandoc + echo "::group::Setup PHP executable for tests" + if [ "${{ runner.os }}" = "Windows" ]; then + echo "TEST_PHP_EXECUTABLE=C:\tools\php\php.exe" >> $GITHUB_ENV + else + echo "TEST_PHP_EXECUTABLE=$(which php)" >> $GITHUB_ENV + fi + echo "::endgroup::" - - name: Install PHP SDK Binary Tools - run: | - Import-Module .\.ci\win-ci-tools.psm1 - InstallPhpSdk + - name: Build Zephir Parser Extension (Linux) + uses: ./.github/actions/build-linux + if: runner.os == 'Linux' - - name: Install PHP Dev pack - run: | - Import-Module .\.ci\win-ci-tools.psm1 - InstallPhpDevPack + - name: Build Zephir Parser Extension (macOS) + uses: ./.github/actions/build-mac + if: runner.os == 'macOS' - - name: Install MSVC Compiler Tool - uses: ilammy/msvc-dev-cmd@v1 + - name: Build Zephir Parser Extension (Windows) + uses: ./.github/actions/build-win + if: runner.os == 'Windows' with: + php_version: ${{ matrix.php }} + ts: ${{ matrix.ts }} + msvc: ${{ matrix.compiler }} arch: ${{ matrix.arch }} + env: + CACHE_DIR: 'C:\Downloads' + TOOLS_DIR: 'C:\tools' - - name: Set PHP SDK Environment variables - shell: cmd - run: | - call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat - call C:\tools\php-sdk\bin\phpsdk_setvars.bat - - - name: Parse Zephir Parser (Lemon) - shell: cmd - run: | - call C:\tools\php-sdk\bin\phpsdk_setvars.bat - powershell.exe -File .\.ci\lemon-parser.ps1 - - - name: Phpize - shell: cmd - run: | - call C:\tools\php-devpack\phpize.bat - - - name: Configure - shell: cmd - run: | - call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat - call C:\tools\php-sdk\bin\phpsdk_setvars.bat - configure --with-codegen-arch=yes --with-prefix=C:\php --with-php-build=C:\php-devpack --disable-all --enable-zephir-parser=shared - - - name: Compile - shell: cmd - run: | - call C:\tools\php-sdk\phpsdk-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.bat - call C:\tools\php-sdk\bin\phpsdk_setvars.bat - nmake - - - name: Get Zephir Parser extension info - run: | - Get-Php "${env:PHPROOT}" - Get-PhpExtension "${env:RELEASE_DLL_PATH}" - & ${env:TEST_PHP_EXECUTABLE} --ini - - - name: Enable Zephir Parser + - name: Run Tests for Zephir Parser + shell: bash run: | - Add-Content -Path "${env:PHPROOT}\php.ini" -Value 'extension=php_zephir_parser.dll' - Copy-Item -Path "${env:RELEASE_DLL_PATH}" -Destination "${env:PHPROOT}\ext\" + php --ri zephir_parser + php run-tests.php -q; exit $? + env: + NO_INTERACTION: 1 + REPORT_EXIT_STATUS: 1 - # Run tests only for x64 PHP builds (Windows currently not support setup php with multi arch) - - name: Run Tests - if: matrix.arch == 'x64' + - name: Collect Build Artifacts + shell: bash run: | - & ${env:TEST_PHP_EXECUTABLE} --ri zephir_parser - & ${env:TEST_PHP_EXECUTABLE} run-tests.php + echo "::group::Creating ZIP with Zephir Parser extension" + if [ "${{ runner.os }}" = "Windows" ]; then + EXTENSION="$(find ./x64 -type f -name 'php_zephir_parser.dll')" + else + EXTENSION="$(find ./modules -type f -name 'zephir_parser.so')" + fi - - name: Prepare Release Package - run: | - Import-Module .\.ci\win-ci-tools.psm1 - PrepareReleasePackage ` - -PhpVersion $Env:PHP_VERSION ` - -BuildType $Env:BUILD_TYPE ` - -Platform $Env:PLATFORM ` - -ZipballName $Env:RELEASE_ZIPBALL ` - -ConvertMd2Html $true ` - -ReleaseFiles "${Env:RELEASE_DLL_PATH}",` - "${Env:GITHUB_WORKSPACE}\LICENSE",` - "${Env:GITHUB_WORKSPACE}\CREDITS",` - "${Env:GITHUB_WORKSPACE}\VERSION",` - "${Env:GITHUB_WORKSPACE}\NO_WARRANTY" + zip -rvj zephir_parser-php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.arch }}.zip \ + $EXTENSION VERSION LICENSE CREDITS NO_WARRANTY CHANGELOG.md + echo "::endgroup::" + # Artifact names should be in next format: + # zephir_parser-{php-version}-{ts}-{os.name}-{compiler}-{arch} + # example: + # zephir_parser-php-7.3-nts-macos-clang-x64.zip + # zephir_parser-php-7.3-nts-ubuntu-gcc-x64.zip + # zephir_parser-php-7.3-nts-windows2019-vc15-x64.zip - name: Upload Zephir Parser uses: actions/upload-artifact@v2 with: - name: zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }}.zip + name: zephir_parser-php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.arch }}.zip path: | - ${{ github.workspace }}\zephir-parser-*.zip + ${{ github.workspace }}/zephir_parser-*.zip - name: Check for Errors if: always() + shell: pwsh run: | - Get-ChildItem (Get-Item -Path ".\" -Verbose).FullName *.log | + Get-ChildItem (Get-Item -Path "./" -Verbose).FullName *.log | ForEach-Object{ $BaseName = $_.BaseName - Write-Output "-- Log details: ${BaseName}.log --" + Write-Output "::group::-- Log details: ${BaseName}.log --" Get-Content -Path "${env:GITHUB_WORKSPACE}\${BaseName}.log" + Write-Output "::endgroup::" } + - name: Capture Coverage Data + if: success() && matrix.ccov == 'ON' + run: make coverage-capture + + - name: Upload Code Coverage Report + if: matrix.ccov == 'ON' + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./lcov.info + flags: unittests,${{ runner.os }} + - name: Upload Info for Debug on Fail if: failure() uses: actions/upload-artifact@v2 with: retention-days: 2 - name: errors-zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-win32-${{ matrix.vc_prefix }}${{ matrix.vc_num }}-${{ matrix.arch }} + name: debug-zephir_parser-php-${{ matrix.php }}-${{ matrix.ts }}-${{ matrix.name }}-${{ matrix.arch }} path: | - ${{ github.workspace }}\tests - ${{ github.workspace }}\parser - ${{ github.workspace }}\Release* - ${{ github.workspace }}\**\Release* + ${{ github.workspace }}/tests + ${{ github.workspace }}/parser + ${{ github.workspace }}/Release* + ${{ github.workspace }}/**/Release* - unix-builds: - # To prevent build a particular commit use - # git commit -m "......... [unix skip] - skip Linux & macOS builds only" - # git commit -m "......... [ci skip] - skip all builds" - if: "!contains(github.event.head_commit.message, '[unix skip]') || !contains(github.event.head_commit.message, '[ci skip]') " - - strategy: - fail-fast: false - - matrix: - php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - arch: ['x64'] - build_type: ['nts'] - name: - - ubuntu - - macos - - include: - - name: ubuntu - os: ubuntu-18.04 - ccov: ON - compiler: gcc - - - name: macos - os: macos-latest - ccov: OFF - compiler: clang - - name: "PHP-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}" - runs-on: ${{ matrix.os }} - - env: - HOMEBREW_NO_INSTALL_CLEANUP: 1 - ZEND_DONT_UNLOAD_MODULES: 1 - USE_ZEND_ALLOC: 0 + pecl: + name: Build PECL package + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - with: - fetch-depth: 5 - - name: Install PHP ${{ matrix.php }} + - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: '${{ matrix.php }}' - coverage: none - env: - PHPTS: ${{ matrix.build_type }} - - - name: Cache RE2C Downloads - uses: actions/cache@v2 - with: - path: ~/.cache/re2c - key: ${{ runner.os }}-php-${{ matrix.php }}-re2c-${{env.RE2C_VERSION}} + php-version: '8.0' + tools: pecl - - name: Setup Prerequisites (Linux) - if: runner.os == 'Linux' + - name: Install System Dependencies run: | sudo apt-get update --quiet --yes 1>/dev/null - sudo apt-get install --no-install-recommends --quiet --yes lcov gdb + sudo apt-get install --no-install-recommends -q -y re2c - - name: Setup Prerequisites (macOS) - if: runner.os == 'macOS' && matrix.ccov == 'ON' - run: | - brew install lcov - sudo xcode-select -switch /Applications/Xcode.app - - - name: Setup Build System (Generic) - run: | - ulimit -c unlimited -S || true - - mkdir -p $HOME/.cache/re2c - mkdir -p $HOME/.local/opt/re2c - - echo "PATH=$PATH:$HOME/bin:$(brew --prefix lcov)/bin" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN)" >> $GITHUB_ENV - echo "CI=true" >> $GITHUB_ENV - echo "ZEPHIR_PARSER_VERSION=$(head -1 VERSION)" >> $GITHUB_ENV - - - name: Setup Core Dump (Linux) - if: runner.os == 'Linux' - run: echo '/tmp/core.%e.%p.%t' | sudo tee /proc/sys/kernel/core_pattern - - - name: Install re2c - run: .ci/install-re2c.sh - - - name: Build extensions + - name: Build Zephir Parser run: | + echo "::group::Run phpize" phpize + echo "::endgroup::" - if [ "${{ matrix.ccov }}" = "ON" ]; then - ./configure \ - --enable-zephir-parser \ - --enable-zephir-parser-debug \ - --enable-coverage - else - ./configure \ + echo "::group::Run configure" + ./configure \ --enable-zephir-parser \ --enable-zephir-parser-debug - fi + echo "::endgroup::" + echo "::group::Compile" make -j$(getconf _NPROCESSORS_ONLN) + echo "::endgroup::" - - name: Preparing to collect coverage data - if: matrix.ccov == 'ON' - run: make coverage-initial - - - name: Run Tests + - name: Prepare PECL package config + shell: pwsh run: | - php -d extension=./modules/zephir_parser.so --ri zephir_parser - make test NO_INTERACTION=1 REPORT_EXIT_STATUS=1 - - - name: Print failures - if: failure() && runner.os == 'Linux' - run: .ci/after-failure.sh - - - name: Capture coverage data - if: success() && matrix.ccov == 'ON' - run: make coverage-capture - - - name: Prepare Build Artifacts - working-directory: modules + echo "-- Replacing Release data" + $Config = [xml](Get-Content ./package.xml) + $Config.package.date = $(Get-Date -Format "yyyy-MM-dd") + $Config.package.time = $(Get-Date -Format "HH:mm:ss") + $Config.package.version.Item(1).release = $(Get-Content ./VERSION) + $Config.package.version.Item(1).api = $Config.package.version.release + + echo "-- Parsing CHANGELOG" + ./.ci/release-notes.sh ./CHANGELOG.md > ./release-notes.md + $Config.package.notes = $(Get-Content ./release-notes.md -Encoding UTF8 -Raw) + $Config.Save('./package.xml') + + - name: Create PECL package run: | - echo "-- Creating ZIP with Zephir Parser extension" - zip -rv zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}.zip ./*.so + pecl package + zephir_parser_package="`ls | grep zephir_parser-*tgz`" + mv $zephir_parser_package zephir_parser-pecl.tgz - - name: Upload code coverage report - if: matrix.ccov == 'ON' - uses: codecov/codecov-action@v1 - with: - token: ${{secrets.CODECOV_TOKEN}} - file: ./lcov.info - flags: unittests - fail_ci_if_error: false + - name: Validate PECL Package + run: | + pecl package-validate zephir_parser-pecl.tgz + pecl info zephir_parser-pecl.tgz - - name: Upload Zephir Parser + - name: Upload Artifact uses: actions/upload-artifact@v2 with: - name: zephir-parser-php-${{ matrix.php }}-${{ matrix.build_type }}-${{ matrix.name }}-${{ matrix.compiler }}-${{ matrix.arch }}.zip - path: | - ${{ github.workspace }}/modules/*.zip + name: 'zephir_parser-pecl' + path: zephir_parser-pecl.tgz release: if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - needs: [windows-builds, unix-builds] + needs: [ builds, pecl ] name: Create Release runs-on: ubuntu-20.04 @@ -386,9 +265,9 @@ jobs: - name: Prepare Release assets run: | mkdir -p ./build-artifacts/release - find ./build-artifacts -type f -name zephir-parser*.zip -exec cp {} ./build-artifacts/release/ ";" + find ./build-artifacts -type f -name zephir_parser*.zip -exec cp {} ./build-artifacts/release/ ";" echo "-- Creating Release Notes" - GITHUB_ACTIONS=false ./.ci/release-notes.sh ./CHANGELOG.md > ./build-artifacts/release/release-notes.md + ./.ci/release-notes.sh ./CHANGELOG.md > ./build-artifacts/release/release-notes.md - name: Create Release uses: ncipollo/release-action@v1 diff --git a/package.xml b/package.xml index 2f5e33e8..4fdd47f2 100644 --- a/package.xml +++ b/package.xml @@ -206,6 +206,7 @@ +