Skip to content

Commit 607c028

Browse files
committed
GitHub Actions worklow
1 parent c9ab80e commit 607c028

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

.github/workflows/windows.yaml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
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+
- ".github/workflows/static.yaml"
14+
- "**cgo.go"
15+
- "**Dockerfile"
16+
- "**.c"
17+
- "**.h"
18+
- "**.sh"
19+
- "**.stub.php"
20+
push:
21+
branches:
22+
- main
23+
tags:
24+
- v*.*.*
25+
workflow_dispatch:
26+
inputs:
27+
#checkov:skip=CKV_GHA_7
28+
version:
29+
description: "FrankenPHP version"
30+
required: false
31+
type: string
32+
schedule:
33+
- cron: "0 8 * * *"
34+
35+
permissions:
36+
contents: read
37+
38+
env:
39+
GOTOOLCHAIN: local
40+
PHP_DOWNLOAD_BASE: "https://windows.php.net/downloads/releases"
41+
CC: clang
42+
CXX: clang++
43+
44+
jobs:
45+
build:
46+
runs-on: windows-latest
47+
defaults:
48+
run:
49+
shell: powershell
50+
51+
steps:
52+
- name: Checkout Code
53+
uses: actions/checkout@v6
54+
with:
55+
path: frankenphp
56+
persist-credentials: false
57+
58+
- name: Setup Go
59+
uses: actions/setup-go@v5
60+
with:
61+
go-version: '>=1.26rc1'
62+
63+
- name: Install Vcpkg Libraries
64+
run: |
65+
cd "$env:VCPKG_INSTALLATION_ROOT"
66+
git pull
67+
.\bootstrap-vcpkg.bat
68+
- name: Cache Vcpkg Packages
69+
uses: actions/cache@v5
70+
with:
71+
path: |
72+
${{ env.VCPKG_INSTALLATION_ROOT }}\installed
73+
${{ env.VCPKG_INSTALLATION_ROOT }}\downloads
74+
key: ${{ runner.os }}-vcpkg-libs-${{ hashFiles('vcpkg/ports/**') }}
75+
restore-keys: |
76+
${{ runner.os }}-vcpkg-libs-
77+
78+
- name: Install Vcpkg Libraries
79+
run: & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install pthreads brotli --triplet x64-windows
80+
81+
- name: Download Latest Watcher
82+
run: |
83+
$latestTag = gh release list --repo e-dant/watcher --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName'
84+
Write-Host "Latest Watcher version: $latestTag"
85+
86+
gh release download $latestTag --repo e-dant/watcher --pattern "*x86_64-pc-windows-msvc.tar" --dir "$env:TEMP"
87+
88+
tar -xf "$env:TEMP\watcher-x86_64-pc-windows-msvc.tar" -C "$env:GITHUB_WORKSPACE"
89+
Rename-Item -Path "$env:GITHUB_WORKSPACE\x86_64-pc-windows-msvc" -NewName "watcher"
90+
91+
# See https://github.com/e-dant/watcher/issues/108
92+
New-Item -Path .\watcher\wtr -ItemType Directory
93+
Move-Item -Path .\watcher-c.h -Destination .\watcher\wtr\watcher-c.h
94+
env:
95+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
97+
- name: Download Latest PHP & Devel Pack
98+
run: |
99+
$webContent = Invoke-WebRequest -Uri $env:PHP_DOWNLOAD_BASE -UseBasicParsing
100+
$links = $webContent.Links.Href | Where-Object { $_ -match "php-(\d+\.\d+\.\d+)-Win32-vs17-x64\.zip" }
101+
102+
if (-not $links) { throw "Could not find PHP zip files at $env:PHP_DOWNLOAD_BASE" }
103+
104+
$latestFile = $links | Sort-Object { [version]($_ -replace 'php-', '' -replace '-Win32-vs17-x64.zip', '') } | Select-Object -Last 1
105+
106+
$version = $latestFile -replace 'php-', '' -replace '-Win32-vs17-x64.zip', ''
107+
Write-Host "Detected latest PHP version: $version"
108+
109+
"PHP_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
110+
111+
$phpZip = "php-$version-Win32-vs17-x64.zip"
112+
$develZip = "php-devel-pack-$version-Win32-vs17-x64.zip"
113+
114+
Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$phpZip" -OutFile "$env:TEMP\php.zip"
115+
Expand-Archive -Path "$env:TEMP\php.zip" -DestinationPath "$env:GITHUB_WORKSPACE\php-bin"
116+
117+
118+
Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$develZip" -OutFile "$env:TEMP\php-devel.zip"
119+
Expand-Archive -Path "$env:TEMP\php-devel.zip" -DestinationPath "$env:GITHUB_WORKSPACE\php-devel"
120+
121+
- name: Prepare env
122+
run: |
123+
$vcpkgRoot = "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows"
124+
$watcherRoot = "$env:GITHUB_WORKSPACE\watcher"
125+
$phpBin = "$env:GITHUB_WORKSPACE\php-bin"
126+
$phpDevel = "$env:GITHUB_WORKSPACE\php-devel\php-$env:PHP_VERSION-devel-vs17-x64"
127+
128+
echo "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
129+
echo "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
130+
echo "$env:VCPKG_INSTALLATION_ROOT\watcher" | Out-File -FilePath $env:GITHUB_PATH -Append
131+
echo "$env:GITHUB_WORKSPACE\php-bin" | Out-File -FilePath $env:GITHUB_PATH -Append
132+
133+
echo "CGO_CFLAGS=-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
134+
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
135+
136+
- name: Build FrankenPHP
137+
run: |
138+
go build -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx
139+
working-directory: { { env.GITHUB_WORKSPACE } }/frankenphp
140+
141+
- name: Create Zip Archive
142+
run: |
143+
Move-Item frankenphp\caddy\frankenphp\frankenphp.exe php-bin
144+
Move-Item watcher\libwatcher-c.dll php-bin
145+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\brotlienc.dll" php-bin
146+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\brotlicommon.dll" php-bin
147+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\pthreadVC3.dll" php-bin
148+
149+
$version = $env:PHP_VERSION
150+
$zipName = "frankenphp-php-$version-Win32-vs17-x64.zip"
151+
152+
# TODO: create a single folder inside the zip
153+
Compress-Archive -Path "php-bin\*" -DestinationPath "$zipName"
154+
155+
echo "ASSET_NAME=$zipName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
156+
157+
- name: Upload Artifact
158+
if: github.event_name != 'release'
159+
uses: actions/upload-artifact@v6
160+
with:
161+
name: ${{ env.ASSET_NAME }}
162+
path: ${{ env.GITHUB_WORKSPACE }}\${{ env.ASSET_PATH }}
163+
164+
- name: Upload Release Asset
165+
if: github.event_name == 'release'
166+
run: |
167+
gh release upload ${{ github.event.release.tag_name }} "${{ env.ASSET_PATH }}" --clobber
168+
env:
169+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
170+
171+
- name: Run Tests
172+
run: |
173+
"opcache.enable=0`r`nopcache.enable_cli=0" | Out-File -Encoding ascii php.ini
174+
$env:PHPRC = Get-Location
175+
176+
go test -ldflags '-extldflags="-fuse-ld=lld"' ./...
177+
cd caddy
178+
go test -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
179+
working-directory: {{ env.GITHUB_WORKSPACE }}/frankenphp

0 commit comments

Comments
 (0)