|
| 1 | +name: Build Windows release |
| 2 | + |
| 3 | +concurrency: |
| 4 | + cancel-in-progress: true |
| 5 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + paths: |
| 12 | + - "docker-bake.hcl" |
| 13 | + - "vcpkg.json" |
| 14 | + - ".github/workflows/static.yaml" |
| 15 | + - "**cgo.go" |
| 16 | + - "**Dockerfile" |
| 17 | + - "**.c" |
| 18 | + - "**.h" |
| 19 | + - "**.sh" |
| 20 | + - "**.stub.php" |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - main |
| 24 | + tags: |
| 25 | + - v*.*.* |
| 26 | + workflow_dispatch: |
| 27 | + inputs: |
| 28 | + #checkov:skip=CKV_GHA_7 |
| 29 | + version: |
| 30 | + description: "FrankenPHP version" |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + schedule: |
| 34 | + - cron: "0 8 * * *" |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + |
| 39 | +env: |
| 40 | + GOTOOLCHAIN: local |
| 41 | + GOFLAGS: "-ldflags=-extldflags=-fuse-ld=lld -tags=nobadger,nomysql,nopgx" |
| 42 | + PHP_DOWNLOAD_BASE: "https://downloads.php.net/~windows/releases/" |
| 43 | + CC: clang |
| 44 | + CXX: clang++ |
| 45 | + |
| 46 | +jobs: |
| 47 | + build: |
| 48 | + runs-on: windows-latest |
| 49 | + defaults: |
| 50 | + run: |
| 51 | + shell: powershell |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Configure Git |
| 55 | + run: | |
| 56 | + git config --global core.autocrlf false |
| 57 | + git config --global core.eol lf |
| 58 | +
|
| 59 | + - name: Checkout Code |
| 60 | + uses: actions/checkout@v6 |
| 61 | + with: |
| 62 | + path: frankenphp |
| 63 | + persist-credentials: false |
| 64 | + |
| 65 | + - name: Set FRANKENPHP_VERSION |
| 66 | + run: | |
| 67 | + if ($env:GITHUB_REF_TYPE -eq "tag") { |
| 68 | + $frankenphpVersion = $env:GITHUB_REF_NAME.Substring(1) |
| 69 | + } elseif ($env:GITHUB_EVENT_NAME -eq "schedule") { |
| 70 | + $frankenphpVersion = $env:GITHUB_REF |
| 71 | + } else { |
| 72 | + $frankenphpVersion = $env:GITHUB_SHA |
| 73 | + } |
| 74 | +
|
| 75 | + echo "FRANKENPHP_VERSION=$frankenphpVersion" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 76 | +
|
| 77 | + - name: Setup Go |
| 78 | + uses: actions/setup-go@v6 |
| 79 | + with: # zizmor: ignore[cache-poisoning] |
| 80 | + go-version: "1.26" |
| 81 | + cache-dependency-path: | |
| 82 | + frankenphp/go.sum |
| 83 | + frankenphp/caddy/go.sum |
| 84 | + cache: ${{ github.event_name != 'release' }} |
| 85 | + check-latest: true |
| 86 | + |
| 87 | + - name: Install Vcpkg Libraries |
| 88 | + working-directory: frankenphp |
| 89 | + run: "vcpkg install" |
| 90 | + |
| 91 | + - name: Download Watcher |
| 92 | + run: | |
| 93 | + $latestTag = gh release list --repo e-dant/watcher --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName' |
| 94 | + Write-Host "Latest Watcher version: $latestTag" |
| 95 | +
|
| 96 | + gh release download $latestTag --repo e-dant/watcher --pattern "*x86_64-pc-windows-msvc.tar" -O watcher.tar |
| 97 | +
|
| 98 | + tar -xf "watcher.tar" -C "$env:GITHUB_WORKSPACE" |
| 99 | + Rename-Item -Path "$env:GITHUB_WORKSPACE\x86_64-pc-windows-msvc" -NewName "watcher" |
| 100 | + env: |
| 101 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + |
| 103 | + - name: Download PHP |
| 104 | + run: | |
| 105 | + $webContent = Invoke-WebRequest -Uri $env:PHP_DOWNLOAD_BASE -UseBasicParsing |
| 106 | + $links = $webContent.Links.Href | Where-Object { $_ -match "php-\d+\.\d+\.\d+-Win32-vs17-x64\.zip$" } |
| 107 | +
|
| 108 | + if (-not $links) { throw "Could not find PHP zip files at $env:PHP_DOWNLOAD_BASE" } |
| 109 | +
|
| 110 | + $latestFile = $links | Sort-Object { if ($_ -match '(\d+\.\d+\.\d+)') { [version]$matches[1] } } | Select-Object -Last 1 |
| 111 | +
|
| 112 | + $version = if ($latestFile -match '(\d+\.\d+\.\d+)') { $matches[1] } |
| 113 | + Write-Host "Detected latest PHP version: $version" |
| 114 | +
|
| 115 | + "PHP_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 116 | +
|
| 117 | + $phpZip = "php-$version-Win32-vs17-x64.zip" |
| 118 | + $develZip = "php-devel-pack-$version-Win32-vs17-x64.zip" |
| 119 | +
|
| 120 | + $dirName = "frankenphp-$env:FRANKENPHP_VERSION-php-$version-Win32-vs17-x64" |
| 121 | +
|
| 122 | + echo "DIR_NAME=$dirName" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 123 | +
|
| 124 | + Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$phpZip" -OutFile "$env:TEMP\php.zip" |
| 125 | + Expand-Archive -Path "$env:TEMP\php.zip" -DestinationPath "$env:GITHUB_WORKSPACE\$dirName" |
| 126 | +
|
| 127 | + Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$develZip" -OutFile "$env:TEMP\php-devel.zip" |
| 128 | + Expand-Archive -Path "$env:TEMP\php-devel.zip" -DestinationPath "$env:GITHUB_WORKSPACE\php-devel" |
| 129 | +
|
| 130 | + - name: Prepare env |
| 131 | + run: | |
| 132 | + $vcpkgRoot = "$env:GITHUB_WORKSPACE\frankenphp\vcpkg_installed\x64-windows" |
| 133 | + $watcherRoot = "$env:GITHUB_WORKSPACE\watcher" |
| 134 | + $phpBin = "$env:GITHUB_WORKSPACE\$env:DIR_NAME" |
| 135 | + $phpDevel = "$env:GITHUB_WORKSPACE\php-devel\php-$env:PHP_VERSION-devel-vs17-x64" |
| 136 | +
|
| 137 | + echo "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 138 | + echo "$vcpkgRoot\bin" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 139 | + echo "$watcherRoot" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 140 | + echo "$phpBin" | Out-File -FilePath $env:GITHUB_PATH -Append |
| 141 | +
|
| 142 | + echo "CGO_CFLAGS=-DFRANKENPHP_VERSION=$env:FRANKENPHP_VERSION -I$vcpkgRoot\include -I$watcherRoot -I$phpDevel\include -I$phpDevel\include\main -I$phpDevel\include\TSRM -I$phpDevel\include\Zend -I$phpDevel\include\ext" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 143 | + echo "CGO_LDFLAGS=-L$vcpkgRoot\lib -lbrotlienc -L$watcherRoot -llibwatcher-c -L$phpBin -L$phpDevel\lib -lphp8ts -lphp8embed" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 144 | +
|
| 145 | + - name: Embed Windows icon and metadata |
| 146 | + working-directory: frankenphp\caddy\frankenphp |
| 147 | + run: | |
| 148 | + go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest |
| 149 | +
|
| 150 | + $major = 0; $minor = 0; $patch = 0; $build = 0 |
| 151 | + if ($env:FRANKENPHP_VERSION -match '^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$') { |
| 152 | + $major = [int]$Matches['major'] |
| 153 | + $minor = [int]$Matches['minor'] |
| 154 | + $patch = [int]$Matches['patch'] |
| 155 | + } |
| 156 | +
|
| 157 | + $json = @{ |
| 158 | + FixedFileInfo = @{ |
| 159 | + FileVersion = @{ Major = $major; Minor = $minor; Patch = $patch; Build = $build } |
| 160 | + ProductVersion = @{ Major = $major; Minor = $minor; Patch = $patch; Build = $build } |
| 161 | + } |
| 162 | + StringFileInfo = @{ |
| 163 | + CompanyName = "FrankenPHP" |
| 164 | + FileDescription = "The modern PHP app server" |
| 165 | + FileVersion = $env:FRANKENPHP_VERSION |
| 166 | + InternalName = "frankenphp" |
| 167 | + OriginalFilename = "frankenphp.exe" |
| 168 | + LegalCopyright = "(c) 2022 Kévin Dunglas, MIT License" |
| 169 | + ProductName = "FrankenPHP" |
| 170 | + ProductVersion = $env:FRANKENPHP_VERSION |
| 171 | + Comments = "https://frankenphp.dev/" |
| 172 | + } |
| 173 | + VarFileInfo = @{ |
| 174 | + Translation = @{ LangID = 9; CharsetID = 1200 } |
| 175 | + } |
| 176 | + } | ConvertTo-Json -Depth 10 |
| 177 | + [System.IO.File]::WriteAllText("versioninfo.json", $json, [System.Text.Encoding]::Default) |
| 178 | +
|
| 179 | + goversioninfo -64 -icon ..\..\frankenphp.ico versioninfo.json -o resource.syso |
| 180 | +
|
| 181 | + - name: Build FrankenPHP |
| 182 | + run: | |
| 183 | + $customVersion = "FrankenPHP $env:FRANKENPHP_VERSION PHP $env:PHP_VERSION Caddy" |
| 184 | + go build -ldflags="-extldflags=-fuse-ld=lld -X 'github.com/caddyserver/caddy/v2.CustomVersion=$customVersion' -X 'github.com/caddyserver/caddy/v2/modules/caddyhttp.ServerHeader=FrankenPHP Caddy'" |
| 185 | + working-directory: frankenphp\caddy\frankenphp |
| 186 | + |
| 187 | + - name: Create Directory |
| 188 | + run: | |
| 189 | + Copy-Item frankenphp\caddy\frankenphp\frankenphp.exe $env:DIR_NAME |
| 190 | + Copy-Item watcher\libwatcher-c.dll $env:DIR_NAME |
| 191 | + Copy-Item frankenphp\vcpkg_installed\x64-windows\bin\brotlienc.dll $env:DIR_NAME |
| 192 | + Copy-Item frankenphp\vcpkg_installed\x64-windows\bin\brotlidec.dll $env:DIR_NAME |
| 193 | + Copy-Item frankenphp\vcpkg_installed\x64-windows\bin\brotlicommon.dll $env:DIR_NAME |
| 194 | + Copy-Item frankenphp\vcpkg_installed\x64-windows\bin\pthreadVC3.dll $env:DIR_NAME |
| 195 | +
|
| 196 | + - name: Upload Artifact |
| 197 | + if: github.event_name != 'release' |
| 198 | + uses: actions/upload-artifact@v6 |
| 199 | + with: |
| 200 | + name: ${{ env.DIR_NAME }} |
| 201 | + path: ${{ env.DIR_NAME }} |
| 202 | + if-no-files-found: error |
| 203 | + |
| 204 | + - name: Zip Release Artifact |
| 205 | + if: github.event_name == 'release' |
| 206 | + run: Compress-Archive -Path "$env:DIR_NAME\*" -DestinationPath "$env:DIR_NAME.zip" |
| 207 | + |
| 208 | + - name: Upload Release Asset |
| 209 | + if: github.event_name == 'release' |
| 210 | + run: gh release upload $env:GITHUB_EVENT_RELEASE_TAG_NAME "$env:DIR_NAME.zip" --clobber |
| 211 | + env: |
| 212 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 213 | + GITHUB_EVENT_RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} |
| 214 | + |
| 215 | + - name: Run Tests |
| 216 | + run: | |
| 217 | + "opcache.enable=0`r`nopcache.enable_cli=0" | Out-File php.ini |
| 218 | + $env:PHPRC = Get-Location |
| 219 | +
|
| 220 | + go test ./... |
| 221 | + cd caddy |
| 222 | + go test ./... |
| 223 | + working-directory: ${{ github.workspace }}\frankenphp |
0 commit comments