Skip to content

ci: Update Windows build step to use bash (for multi-line command sup… #15

ci: Update Windows build step to use bash (for multi-line command sup…

ci: Update Windows build step to use bash (for multi-line command sup… #15

name: Build, test, and docs
on:
push:
branches-ignore:
- 'gh-pages'
pull_request:
branches-ignore:
- 'gh-pages'
workflow_dispatch:
jobs:
macos:
runs-on: macos-14
steps:
- name: Force Xcode 15.4
run: sudo xcode-select -switch /Applications/Xcode_15.4.app
- name: Swift version
run: swift --version
- uses: actions/checkout@v3
- name: Install Dependencies
run: brew install pkg-config gtk4 gtk+3 || echo "This step 'fails' every time but it's just a brew linking error - not important."
- name: Build
run: |
swift build --target GtkCodeGen && \
cd Examples && \
swift build --target SwiftCrossUI && \
swift build --target GtkBackend && \
swift build --target Gtk3Backend && \
swift build --target AppKitBackend && \
swift build --target CounterExample && \
swift build --target ControlsExample && \
swift build --target RandomNumberGeneratorExample && \
swift build --target WindowingExample && \
swift build --target GreetingGeneratorExample && \
swift build --target NavigationExample && \
swift build --target SplitExample && \
swift build --target StressTestExample && \
swift build --target SpreadsheetExample && \
swift build --target NotesExample && \
swift build --target GtkExample && \
swift build --target PathsExample
- name: Test
run: swift test --test-product swift-cross-uiPackageTests
- name: Compile AppKitBackend docs
uses: ./.github/actions/compile-docs
with:
target: AppKitBackend
upload: true
uikit:
runs-on: macos-14
strategy:
matrix:
device-type:
- iPhone
- iPad
- TV
steps:
- name: Force Xcode 15.4
run: sudo xcode-select -switch /Applications/Xcode_15.4.app
- name: Swift version
run: swift --version
- name: Install xcbeautify
run: brew install xcbeautify
- uses: actions/checkout@v3
- name: Build
run: |
set -uo pipefail
device_type=${{ matrix.device-type }}
set +e
deviceid=$(xcrun simctl list devices $device_type available | grep -v -- -- | tail -n 1 | grep -oE '[0-9A-F\-]{36}')
if [ $? -eq 0 ]; then
set -ex
(
buildtarget () {
# Use the same derived data path as DocC compilation so that we don't duplicate work.
xcodebuild -derivedDataPath /tmp/data -skipMacroValidation -scheme "$1" -destination "id=$deviceid" build | xcbeautify --renderer github-actions
}
buildtarget SwiftCrossUI
buildtarget UIKitBackend
cd Examples
buildtarget CounterExample
buildtarget GreetingGeneratorExample
buildtarget NavigationExample
buildtarget StressTestExample
buildtarget NotesExample
buildtarget PathsExample
if [ $device_type != TV ]; then
# Slider is not implemented for tvOS
buildtarget ControlsExample
buildtarget RandomNumberGeneratorExample
fi
if [ $device_type = iPad ]; then
# NavigationSplitView is only implemented for iPad
buildtarget SplitExample
fi
)
else
echo "No $device_type simulators found" >&2
fi
- name: Compile UIKitBackend docs
if: ${{ matrix.device-type == 'iPhone' }}
uses: ./.github/actions/compile-docs
with:
target: UIKitBackend
upload: true
xcodebuild: true
xcodebuild-device-type: ${{ matrix.device-type }}
windows:
runs-on: windows-latest
defaults:
run: # Use powershell because bash is not supported: https://github.com/compnerd/gha-setup-swift/issues/18#issuecomment-1705524890
shell: pwsh
steps:
- name: Setup VS Dev Environment
uses: seanmiddleditch/gha-setup-vsdevenv@v5
- name: Setup
uses: compnerd/[email protected]
with:
branch: swift-6.1-release
tag: 6.1-RELEASE
- name: Swift version
run: swift --version
- name: Compute vcpkg Triplet
id: triplet
uses: ASzc/change-string-case-action@v5
with:
string: ${{ runner.arch }}-${{ runner.os }}
- uses: actions/checkout@v3
- name: Restore Dependency Cache
id: cache
uses: actions/cache/restore@v3
with:
path: vcpkg_installed
key: vcpkg-${{ steps.triplet.outputs.lowercase }}-${{ hashFiles('vcpkg.json') }}
- name: Build and Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
env:
VCPKG_DEFAULT_TRIPLET: ${{ steps.triplet.outputs.lowercase }}
run: vcpkg install
- name: Save Dependency Cache
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: vcpkg_installed
key: vcpkg-${{ steps.triplet.outputs.lowercase }}-${{ hashFiles('vcpkg.json') }}
- name: Build SwiftCrossUI
env:
PKG_CONFIG_PATH: ${{ github.workspace }}/vcpkg_installed/${{ steps.triplet.outputs.lowercase }}/lib/pkgconfig
run: swift build --target SwiftCrossUI -v
# DocC doesn't work on Windows yet, so we just emit the symbol graphs and construct
# the final WinUIBackend documentation archive in the update-docs job.
# Related issue: https://github.com/swiftlang/swift-docc/pull/668
- name: Build WinUIBackend
run: |
swift build --target WinUIBackend -v \
-Xswiftc -emit-symbol-graph \
-Xswiftc -emit-symbol-graph-dir -Xswiftc symbol-graphs
shell: bash
- name: Upload WinUIBackend symbol graph
uses: actions/upload-artifact@v4
with:
name: WinUIBackend.symbols.json
path: symbol-graphs/WinUIBackend.symbols.json
linux:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}
steps:
# The Ubuntu image comes with Swift, but it's installed as root and DocC
# doesn't like that, so we install our own copy as a user.
# Related issue: https://github.com/swiftlang/swift-docc/issues/1136
- name: Install Swift
uses: SwiftyLab/setup-swift@latest
with:
swift-version: "6.1.0"
- name: Swift version
run: swift --version
- uses: actions/checkout@v3
- name: Install Dependencies
run: |
sudo apt update && \
sudo apt install -y libgtk-4-dev libgtk-3-dev clang
- name: Build
run: |
swift build --target GtkCodeGen && \
cd Examples && \
swift build --target SwiftCrossUI && \
swift build --target GtkBackend && \
swift build --target Gtk3Backend && \
swift build --target CounterExample && \
swift build --target ControlsExample && \
swift build --target RandomNumberGeneratorExample && \
swift build --target WindowingExample && \
swift build --target GreetingGeneratorExample && \
swift build --target NavigationExample && \
swift build --target SplitExample && \
swift build --target StressTestExample && \
swift build --target SpreadsheetExample && \
swift build --target NotesExample && \
swift build --target GtkExample
- name: Test
run: swift test --test-product swift-cross-uiPackageTests
- name: Compile GtkBackend docs
if: ${{ matrix.os == 'ubuntu-24.04' }}
uses: ./.github/actions/compile-docs
with:
target: GtkBackend
upload: true
- name: Compile Gtk3Backend docs
if: ${{ matrix.os == 'ubuntu-24.04' }}
uses: ./.github/actions/compile-docs
with:
target: Gtk3Backend
upload: true
update-docs:
runs-on: macos-14
needs: [macos, uikit, windows, linux]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
steps:
- name: Force Xcode 15.4
run: sudo xcode-select -switch /Applications/Xcode_15.4.app
- uses: actions/checkout@v3
- name: Swift Version
run: swift --version
- name: Compile SwiftCrossUI docs
uses: ./.github/actions/compile-docs
with:
target: SwiftCrossUI
upload: false
- name: Download AppKitBackend.doccarchive
uses: actions/download-artifact@v4
with:
name: AppKitBackend.doccarchive.tar.gz
- name: Download UIKitBackend.doccarchive
uses: actions/download-artifact@v4
with:
name: UIKitBackend.doccarchive.tar.gz
- name: Download GtkBackend.doccarchive
uses: actions/download-artifact@v4
with:
name: GtkBackend.doccarchive.tar.gz
- name: Download Gtk3Backend.doccarchive
uses: actions/download-artifact@v4
with:
name: Gtk3Backend.doccarchive.tar.gz
- name: Extract AppKitBackend.doccarchive.tar.gz
uses: a7ul/[email protected]
with:
command: x
files: ./AppKitBackend.doccarchive.tar.gz
- name: Extract UIKitBackend.doccarchive.tar.gz
uses: a7ul/[email protected]
with:
command: x
files: ./UIKitBackend.doccarchive.tar.gz
- name: Extract GtkBackend.doccarchive.tar.gz
uses: a7ul/[email protected]
with:
command: x
files: ./GtkBackend.doccarchive.tar.gz
- name: Extract Gtk3Backend.doccarchive.tar.gz
uses: a7ul/[email protected]
with:
command: x
files: ./Gtk3Backend.doccarchive.tar.gz
- name: Download WinUIBackend.symbols.json
uses: actions/download-artifact@v4
with:
name: WinUIBackend.symbols.json
- name: Compile WinUIBackend documentation
run: |
mkdir WinUIBackend.docc
mkdir winui-symbol-graphs
mv WinUIBackend.symbols.json winui-symbol-graphs/
xcrun docc convert WinUIBackend.docc \
--additional-symbol-graph-dir winui-symbol-graphs \
--transform-for-static-hosting \
--hosting-base-path swift-cross-ui \
--output-path "WinUIBackend.doccarchive" \
--source-service github \
--source-service-base-url https://github.com/stackotter/swift-cross-ui/blob/main \
--checkout-path $(pwd)
- name: Merge DocC archives
run: |
xcrun docc merge \
SwiftCrossUI.doccarchive \
AppKitBackend.doccarchive \
UIKitBackend.doccarchive \
GtkBackend.doccarchive \
Gtk3Backend.doccarchive \
WinUIBackend.doccarchive \
--output-path gh-pages/docs
- name: Update docs if changed
run: |
set -eux
git config user.email "[email protected]"
git config user.name "stackotter"
git fetch
git worktree add --checkout gh-pages origin/gh-pages
CURRENT_COMMIT_HASH=`git rev-parse --short HEAD`
cd gh-pages
git add docs
if [ -n "$(git status --porcelain)" ]; then
echo "Documentation changes found."
git commit -m "Update GitHub Pages documentation site to '$CURRENT_COMMIT_HASH'."
git push origin HEAD:gh-pages
else
echo "No documentation changes found."
fi