Skip to content

Commit f94618c

Browse files
committed
GitHub Actions worklow
1 parent c9ab80e commit f94618c

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

.github/workflows/windows.yaml

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

0 commit comments

Comments
 (0)