Skip to content

Commit 985e36b

Browse files
committed
GitHub Actions worklow
1 parent c9ab80e commit 985e36b

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

.github/workflows/windows.yaml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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@v6
60+
with:
61+
go-version: "1.26.0rc1"
62+
cache-dependency-path: |
63+
go.sum
64+
caddy/go.sum
65+
cache: false
66+
check-latest: true
67+
68+
- name: Update Vcpkg
69+
run: |
70+
cd "$env:VCPKG_INSTALLATION_ROOT"
71+
git pull
72+
.\bootstrap-vcpkg.bat
73+
74+
- name: Cache Vcpkg Packages
75+
uses: actions/cache@v5
76+
with:
77+
path: |
78+
${{ env.VCPKG_INSTALLATION_ROOT }}\installed
79+
${{ env.VCPKG_INSTALLATION_ROOT }}\downloads
80+
key: ${{ runner.os }}-vcpkg-libs-${{ hashFiles('vcpkg/ports/**') }}
81+
restore-keys: |
82+
${{ runner.os }}-vcpkg-libs-
83+
lookup-only: true
84+
85+
- name: Install Vcpkg Libraries
86+
run: '& "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install pthreads brotli --triplet x64-windows'
87+
88+
- name: Download Watcher
89+
run: |
90+
$latestTag = gh release list --repo e-dant/watcher --limit 1 --exclude-drafts --exclude-pre-releases --json tagName --jq '.[0].tagName'
91+
Write-Host "Latest Watcher version: $latestTag"
92+
93+
gh release download $latestTag --repo e-dant/watcher --pattern "*x86_64-pc-windows-msvc.tar" --dir "$env:TEMP"
94+
95+
tar -xf "$env:TEMP\watcher-x86_64-pc-windows-msvc.tar" -C "$env:GITHUB_WORKSPACE"
96+
Rename-Item -Path "$env:GITHUB_WORKSPACE\x86_64-pc-windows-msvc" -NewName "watcher"
97+
98+
# See https://github.com/e-dant/watcher/issues/108
99+
New-Item -Path .\watcher\wtr -ItemType Directory
100+
Move-Item -Path .\watcher-c.h -Destination .\watcher\wtr\watcher-c.h
101+
env:
102+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
104+
- name: Download PHP
105+
run: |
106+
$webContent = Invoke-WebRequest -Uri $env:PHP_DOWNLOAD_BASE -UseBasicParsing
107+
$links = $webContent.Links.Href | Where-Object { $_ -match "php-(\d+\.\d+\.\d+)-Win32-vs17-x64\.zip" }
108+
109+
if (-not $links) { throw "Could not find PHP zip files at $env:PHP_DOWNLOAD_BASE" }
110+
111+
$latestFile = $links | Sort-Object { [version]($_ -replace 'php-', '' -replace '-Win32-vs17-x64.zip', '') } | Select-Object -Last 1
112+
113+
$version = $latestFile -replace 'php-', '' -replace '-Win32-vs17-x64.zip', ''
114+
Write-Host "Detected latest PHP version: $version"
115+
116+
"PHP_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
117+
118+
$phpZip = "php-$version-Win32-vs17-x64.zip"
119+
$develZip = "php-devel-pack-$version-Win32-vs17-x64.zip"
120+
121+
Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$phpZip" -OutFile "$env:TEMP\php.zip"
122+
Expand-Archive -Path "$env:TEMP\php.zip" -DestinationPath "$env:GITHUB_WORKSPACE\php-bin"
123+
124+
Invoke-WebRequest -Uri "$env:PHP_DOWNLOAD_BASE/$develZip" -OutFile "$env:TEMP\php-devel.zip"
125+
Expand-Archive -Path "$env:TEMP\php-devel.zip" -DestinationPath "$env:GITHUB_WORKSPACE\php-devel"
126+
127+
- name: Prepare env
128+
run: |
129+
$vcpkgRoot = "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows"
130+
$watcherRoot = "$env:GITHUB_WORKSPACE\watcher"
131+
$phpBin = "$env:GITHUB_WORKSPACE\php-bin"
132+
$phpDevel = "$env:GITHUB_WORKSPACE\php-devel\php-$env:PHP_VERSION-devel-vs17-x64"
133+
134+
echo "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
135+
echo "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
136+
echo "$env:VCPKG_INSTALLATION_ROOT\watcher" | Out-File -FilePath $env:GITHUB_PATH -Append
137+
echo "$env:GITHUB_WORKSPACE\php-bin" | Out-File -FilePath $env:GITHUB_PATH -Append
138+
139+
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
140+
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
141+
142+
- name: Build FrankenPHP
143+
run: go build -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx
144+
working-directory: ${{ env.GITHUB_WORKSPACE }}/frankenphp
145+
146+
- name: Create Zip Archive
147+
run: |
148+
Move-Item frankenphp\caddy\frankenphp\frankenphp.exe php-bin
149+
Move-Item watcher\libwatcher-c.dll php-bin
150+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\brotlienc.dll" php-bin
151+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\brotlicommon.dll" php-bin
152+
Move-Item "$env:VCPKG_INSTALLATION_ROOT\installed\x64-windows\bin\pthreadVC3.dll" php-bin
153+
154+
$version = $env:PHP_VERSION
155+
$zipName = "frankenphp-php-$version-Win32-vs17-x64.zip"
156+
157+
# TODO: create a single folder inside the zip
158+
Compress-Archive -Path "php-bin\*" -DestinationPath "$zipName"
159+
160+
echo "ASSET_NAME=$zipName" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
161+
162+
- name: Upload Artifact
163+
if: github.event_name != 'release'
164+
uses: actions/upload-artifact@v6
165+
with:
166+
name: ${{ env.ASSET_NAME }}
167+
path: ${{ env.GITHUB_WORKSPACE }}\${{ env.ASSET_PATH }}
168+
169+
- name: Upload Release Asset
170+
if: github.event_name == 'release'
171+
run: gh release upload $env:GITHUB_EVENT_RELEASE_TAG_NAME "$env:ASSET_PATH" --clobber
172+
env:
173+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
174+
GITHUB_EVENT_RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
175+
176+
- name: Run Tests
177+
run: |
178+
"opcache.enable=0`r`nopcache.enable_cli=0" | Out-File php.ini
179+
$env:PHPRC = Get-Location
180+
181+
go test -ldflags '-extldflags="-fuse-ld=lld"' ./...
182+
cd caddy
183+
go test -ldflags '-extldflags="-fuse-ld=lld"' -tags nobadger,nomysql,nopgx ./...
184+
working-directory: ${{ env.GITHUB_WORKSPACE }}/frankenphp

0 commit comments

Comments
 (0)