358 lines
12 KiB
YAML
358 lines
12 KiB
YAML
name: staticlink-avalonia-native
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
avalonia_version:
|
|
type: string
|
|
default: ''
|
|
force_build:
|
|
type: boolean
|
|
default: false
|
|
publish_to_nuget:
|
|
type: boolean
|
|
default: false
|
|
workflow_dispatch:
|
|
inputs:
|
|
avalonia_version:
|
|
description: Avalonia version to build; empty checks the latest stable 11.x and 12.x versions
|
|
required: false
|
|
type: string
|
|
force_build:
|
|
description: Build even when this StaticLink.Avalonia.Native version already exists
|
|
required: true
|
|
default: false
|
|
type: boolean
|
|
publish_to_nuget:
|
|
description: Publish with NuGet Trusted Publishing after smoke tests
|
|
required: true
|
|
default: false
|
|
type: boolean
|
|
|
|
jobs:
|
|
detect:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
outputs:
|
|
versions: ${{ steps.version.outputs.versions }}
|
|
should_build: ${{ steps.version.outputs.should_build }}
|
|
steps:
|
|
- name: Detect unpublished Avalonia version
|
|
id: version
|
|
shell: bash
|
|
env:
|
|
REQUESTED_VERSION: ${{ inputs.avalonia_version }}
|
|
FORCE_BUILD: ${{ inputs.force_build }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [ -n "$REQUESTED_VERSION" ]; then
|
|
candidate_versions=("$REQUESTED_VERSION")
|
|
else
|
|
nuget_versions="$(curl --fail --silent --show-error --location \
|
|
https://api.nuget.org/v3-flatcontainer/avalonia/index.json)"
|
|
candidate_versions=()
|
|
for major in 11 12; do
|
|
candidate_versions+=("$(jq -r --arg major "$major" \
|
|
'[.versions[] | select(startswith($major + ".") and (contains("-") | not))] | last' \
|
|
<<< "$nuget_versions")")
|
|
done
|
|
fi
|
|
|
|
versions='[]'
|
|
for avalonia_version in "${candidate_versions[@]}"; do
|
|
if [ -z "$avalonia_version" ] || [ "$avalonia_version" = "null" ]; then
|
|
echo "Could not determine a stable Avalonia version." >&2
|
|
exit 1
|
|
fi
|
|
|
|
package_version="$avalonia_version.2"
|
|
package_url="https://api.nuget.org/v3-flatcontainer/staticlink.avalonia.native/$package_version/staticlink.avalonia.native.$package_version.nupkg"
|
|
status=$(curl --retry 3 --silent --show-error --location --output /dev/null --write-out '%{http_code}' "$package_url")
|
|
if [ "$status" != 200 ] && [ "$status" != 404 ]; then
|
|
echo "NuGet availability check failed: HTTP $status" >&2
|
|
exit 1
|
|
fi
|
|
if [ "$FORCE_BUILD" != "true" ] && [ "$status" = 200 ]; then
|
|
echo "Already published: $package_version"
|
|
continue
|
|
fi
|
|
|
|
echo "Build required: $package_version"
|
|
versions="$(jq -cn --argjson versions "$versions" \
|
|
--arg avalonia_version "$avalonia_version" \
|
|
--arg package_version "$package_version" \
|
|
'$versions + [{avalonia_version: $avalonia_version, package_version: $package_version}]')"
|
|
done
|
|
|
|
echo "versions=$versions" >> "$GITHUB_OUTPUT"
|
|
if [ "$versions" = '[]' ]; then
|
|
echo 'should_build=false' >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo 'should_build=true' >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
toolchain:
|
|
needs: detect
|
|
if: ${{ needs.detect.outputs.should_build == 'true' }}
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
uses: ./.github/workflows/zig-toolchain-image.yml
|
|
|
|
build:
|
|
needs: [detect, toolchain]
|
|
if: ${{ needs.detect.outputs.should_build == 'true' }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
version: ${{ fromJSON(needs.detect.outputs.versions) }}
|
|
rid: [osx-x64, osx-arm64]
|
|
include:
|
|
- rid: osx-x64
|
|
runner: macos-14
|
|
- rid: osx-arm64
|
|
runner: macos-15
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
env:
|
|
TOOLCHAIN_IMAGE: ${{ needs.toolchain.outputs.image }}
|
|
RID: ${{ matrix.rid }}
|
|
AVALONIA_VERSION: ${{ matrix.version.avalonia_version }}
|
|
WORK_DIR: ${{ github.workspace }}/External/AvaloniaNative/.work
|
|
OUTPUT_DIR: ${{ github.workspace }}/External/AvaloniaNative/${{ matrix.rid }}/native
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Pull immutable toolchain image
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
ACTOR: ${{ github.actor }}
|
|
run: |
|
|
printf '%s' "$GH_TOKEN" | docker login ghcr.io -u "$ACTOR" --password-stdin
|
|
docker pull "$TOOLCHAIN_IMAGE"
|
|
|
|
- name: Build static AvaloniaNative and font preinit with Zig
|
|
run: |
|
|
mkdir -p "$WORK_DIR" "$OUTPUT_DIR"
|
|
docker run --rm --user "$(id -u):$(id -g)" \
|
|
-e HOME=/tmp/staticlink-home -e RID -e AVALONIA_VERSION \
|
|
-v "$PWD:/src" -w /src --entrypoint bash "$TOOLCHAIN_IMAGE" -c '
|
|
set -euo pipefail
|
|
mkdir -p "$HOME"
|
|
src="/src/External/AvaloniaNative/.work/Avalonia-$AVALONIA_VERSION"
|
|
git clone --depth 1 --branch "$AVALONIA_VERSION" https://github.com/AvaloniaUI/Avalonia.git "$src"
|
|
if git -C "$src" config -f .gitmodules --get-regexp path | awk '{print $2}' | grep -qx external/Numerge; then
|
|
git -C "$src" submodule update --init --depth 1 external/Numerge
|
|
fi
|
|
python3 build/linux-toolchain/build-avalonia-native-cross.py \
|
|
--source "$src" --rid "$RID" --sdk /opt/macos-sdk/MacOSX15.5.sdk \
|
|
--work "/src/External/AvaloniaNative/.work/zig-$AVALONIA_VERSION-$RID" \
|
|
--output "/src/External/AvaloniaNative/$RID/native"
|
|
'
|
|
|
|
- name: Upload static AvaloniaNative
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: native-avalonia-${{ matrix.version.avalonia_version }}-${{ matrix.rid }}
|
|
path: |
|
|
External/AvaloniaNative/${{ matrix.rid }}/native/libAvaloniaNative.a
|
|
External/AvaloniaNative/${{ matrix.rid }}/native/macos_font_preinit.o
|
|
External/AvaloniaNative/${{ matrix.rid }}/native/avalonia-native-build.json
|
|
if-no-files-found: error
|
|
|
|
pack:
|
|
needs:
|
|
- detect
|
|
- build
|
|
if: ${{ needs.detect.outputs.should_build == 'true' }}
|
|
strategy:
|
|
matrix:
|
|
version: ${{ fromJSON(needs.detect.outputs.versions) }}
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: "10.0.x"
|
|
|
|
- name: Download static AvaloniaNative archives
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: native-avalonia-${{ matrix.version.avalonia_version }}-*
|
|
path: artifacts/native
|
|
merge-multiple: false
|
|
|
|
- name: Prepare package inputs
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
for rid in osx-x64 osx-arm64; do
|
|
mkdir -p "External/AvaloniaNative/$rid/native"
|
|
cp "artifacts/native/native-avalonia-${{ matrix.version.avalonia_version }}-$rid/libAvaloniaNative.a" "External/AvaloniaNative/$rid/native/"
|
|
cp "artifacts/native/native-avalonia-${{ matrix.version.avalonia_version }}-$rid/macos_font_preinit.o" "External/AvaloniaNative/$rid/native/"
|
|
done
|
|
|
|
- name: Pack StaticLink.Avalonia.Native
|
|
run: |
|
|
dotnet pack NuGet/AvaloniaNative/StaticLink.Avalonia.Native.csproj \
|
|
-c Release \
|
|
-o artifacts/nuget \
|
|
/p:PackageVersion=${{ matrix.version.package_version }} \
|
|
/p:Version=${{ matrix.version.package_version }}
|
|
|
|
- name: Upload NuGet package
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
|
|
path: artifacts/nuget/*.nupkg
|
|
if-no-files-found: error
|
|
|
|
smoke:
|
|
needs:
|
|
- detect
|
|
- pack
|
|
if: ${{ needs.detect.outputs.should_build == 'true' }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
version: ${{ fromJSON(needs.detect.outputs.versions) }}
|
|
rid: [osx-x64, osx-arm64]
|
|
include:
|
|
- rid: osx-x64
|
|
runner: macos-14
|
|
- rid: osx-arm64
|
|
runner: macos-15
|
|
runs-on: ${{ matrix.runner }}
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: "10.0.x"
|
|
|
|
- name: Download NuGet package
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
|
|
path: artifacts/nuget
|
|
|
|
- name: Publish Avalonia NativeAOT smoke app
|
|
shell: pwsh
|
|
run: |
|
|
$projectDir = Join-Path $PWD "artifacts/avalonia-native-smoke-src"
|
|
pwsh ./scripts/create-avalonia-smoke.ps1 `
|
|
-ProjectDir $projectDir `
|
|
-NuGetSource (Resolve-Path "artifacts/nuget") `
|
|
-AvaloniaVersion "${{ matrix.version.avalonia_version }}" `
|
|
-StaticLinkNativeVersion "${{ matrix.version.package_version }}"
|
|
dotnet publish (Join-Path $projectDir "AvaloniaStaticLinkSmoke.csproj") `
|
|
-c Release `
|
|
-r "${{ matrix.rid }}" `
|
|
--configfile (Join-Path $projectDir "NuGet.config") `
|
|
/p:PublishDir="$PWD/artifacts/smoke-${{ matrix.rid }}/"
|
|
|
|
- name: Verify AvaloniaNative is statically linked
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
test ! -f "artifacts/smoke-${{ matrix.rid }}/libAvaloniaNative.dylib"
|
|
test -x "artifacts/smoke-${{ matrix.rid }}/AvaloniaStaticLinkSmoke"
|
|
|
|
- name: Run Avalonia smoke app
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
cd "artifacts/smoke-${{ matrix.rid }}"
|
|
python3 - <<'PY'
|
|
import subprocess
|
|
import sys
|
|
|
|
proc = subprocess.Popen(
|
|
["./AvaloniaStaticLinkSmoke"],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
text=True,
|
|
)
|
|
try:
|
|
output, _ = proc.communicate(timeout=15)
|
|
except subprocess.TimeoutExpired:
|
|
proc.kill()
|
|
output, _ = proc.communicate()
|
|
print(output or "")
|
|
print("Avalonia smoke app stayed alive for 15 seconds.")
|
|
sys.exit(0)
|
|
|
|
print(output or "")
|
|
if proc.returncode == 0:
|
|
sys.exit(0)
|
|
sys.exit(proc.returncode if proc.returncode > 0 else 1)
|
|
PY
|
|
|
|
- name: Upload AvaloniaNative smoke app
|
|
if: ${{ always() }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: avalonia-native-smoke-${{ matrix.version.avalonia_version }}-${{ matrix.rid }}
|
|
path: artifacts/smoke-${{ matrix.rid }}/**
|
|
if-no-files-found: warn
|
|
|
|
publish:
|
|
needs:
|
|
- detect
|
|
- smoke
|
|
if: ${{ needs.detect.outputs.should_build == 'true' && inputs.publish_to_nuget == true }}
|
|
strategy:
|
|
matrix:
|
|
version: ${{ fromJSON(needs.detect.outputs.versions) }}
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
steps:
|
|
- name: Download NuGet package
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: staticlink-avalonia-native-${{ matrix.version.package_version }}
|
|
path: artifacts/nuget
|
|
|
|
- uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: "10.0.302"
|
|
|
|
- name: Validate Trusted Publishing configuration
|
|
env:
|
|
NUGET_USER: ${{ vars.NUGET_USER }}
|
|
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
|
|
run: |
|
|
if [ -z "$NUGET_USER" ] && [ -z "$NUGET_API_KEY" ]; then
|
|
echo 'Configure NUGET_USER with Trusted Publishing or NUGET_API_KEY.' >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: NuGet login
|
|
if: ${{ vars.NUGET_USER != '' }}
|
|
id: login
|
|
uses: NuGet/login@v1
|
|
with:
|
|
user: ${{ vars.NUGET_USER }}
|
|
|
|
- name: Publish to nuget.org
|
|
env:
|
|
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY || secrets.NUGET_API_KEY }}
|
|
run: |
|
|
dotnet nuget push artifacts/nuget/*.nupkg \
|
|
--source https://www.nuget.org/api/v2/package \
|
|
--api-key "$NUGET_API_KEY" \
|
|
--skip-duplicate
|