Skip to content

Commit a380c84

Browse files
committed
Create reusable yml
1 parent eeeeb8f commit a380c84

3 files changed

Lines changed: 171 additions & 396 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -8,212 +8,40 @@ on:
88

99
jobs:
1010
native-linux:
11-
runs-on: ubuntu-latest
12-
outputs:
13-
rid: ${{ steps.runtime-info.outputs.rid }}
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v4
17-
with:
18-
fetch-depth: 0
19-
20-
- name: Setup .NET
21-
uses: actions/setup-dotnet@v4
22-
with:
23-
dotnet-version: 8.0.x
24-
25-
- name: Install dependencies
26-
run: |
27-
sudo apt-get update
28-
sudo apt-get install -y libgtk-3-dev ninja-build clang-format zip
29-
30-
- name: Package native artifacts
31-
run: ./build/build.sh Release --skip-dotnet --skip-tests
32-
shell: bash
33-
34-
- name: Determine runtime identifier
35-
id: runtime-info
36-
run: |
37-
arch="$(uname -m)"
38-
case "${arch}" in
39-
x86_64|amd64) arch="x64" ;;
40-
arm64|aarch64) arch="arm64" ;;
41-
esac
42-
echo "rid=linux-${arch}" >> "${GITHUB_OUTPUT}"
43-
shell: bash
44-
45-
- name: Upload native artifact
46-
uses: actions/upload-artifact@v4
47-
with:
48-
name: native-linux
49-
path: artifacts/native-linux-*.zip
50-
if-no-files-found: error
11+
uses: ./.github/workflows/native-build.yml
12+
with:
13+
runner: ubuntu-latest
14+
configuration: Release
15+
artifact-name: native-linux
5116

5217
native-linux-arm64:
53-
runs-on: ubuntu-22.04-arm
54-
outputs:
55-
rid: ${{ steps.runtime-info.outputs.rid }}
56-
steps:
57-
- name: Checkout
58-
uses: actions/checkout@v4
59-
with:
60-
fetch-depth: 0
61-
62-
- name: Setup .NET
63-
uses: actions/setup-dotnet@v4
64-
with:
65-
dotnet-version: 8.0.x
66-
67-
- name: Install dependencies
68-
run: |
69-
sudo apt-get update
70-
sudo apt-get install -y libgtk-3-dev ninja-build clang-format zip
71-
72-
- name: Package native artifacts
73-
run: ./build/build.sh Release --skip-dotnet --skip-tests
74-
shell: bash
75-
76-
- name: Determine runtime identifier
77-
id: runtime-info
78-
run: |
79-
arch="$(uname -m)"
80-
case "${arch}" in
81-
x86_64|amd64) arch="x64" ;;
82-
arm64|aarch64) arch="arm64" ;;
83-
esac
84-
echo "rid=linux-${arch}" >> "${GITHUB_OUTPUT}"
85-
shell: bash
86-
87-
- name: Upload native artifact
88-
uses: actions/upload-artifact@v4
89-
with:
90-
name: native-linux-arm64
91-
path: artifacts/native-linux-*.zip
92-
if-no-files-found: error
18+
uses: ./.github/workflows/native-build.yml
19+
with:
20+
runner: ubuntu-22.04-arm
21+
configuration: Release
22+
artifact-name: native-linux-arm64
9323

9424
native-macos:
95-
runs-on: macos-latest
96-
outputs:
97-
rid: ${{ steps.runtime-info.outputs.rid }}
98-
steps:
99-
- name: Checkout
100-
uses: actions/checkout@v4
101-
with:
102-
fetch-depth: 0
103-
104-
- name: Setup .NET
105-
uses: actions/setup-dotnet@v4
106-
with:
107-
dotnet-version: 8.0.x
108-
109-
- name: Install dependencies
110-
run: |
111-
brew update
112-
brew install gtk+3 ninja clang-format
113-
114-
- name: Package native artifacts
115-
run: ./build/build.sh Release --skip-dotnet --skip-tests
116-
shell: bash
117-
118-
- name: Determine runtime identifier
119-
id: runtime-info
120-
run: |
121-
arch="$(uname -m)"
122-
case "${arch}" in
123-
x86_64|amd64) arch="x64" ;;
124-
arm64|aarch64) arch="arm64" ;;
125-
esac
126-
echo "rid=osx-${arch}" >> "${GITHUB_OUTPUT}"
127-
shell: bash
128-
129-
- name: Upload native artifact
130-
uses: actions/upload-artifact@v4
131-
with:
132-
name: native-macos
133-
path: artifacts/native-osx-*.zip
134-
if-no-files-found: error
25+
uses: ./.github/workflows/native-build.yml
26+
with:
27+
runner: macos-latest
28+
configuration: Release
29+
artifact-name: native-macos
13530

13631
native-windows:
137-
runs-on: windows-latest
138-
outputs:
139-
rid: ${{ steps.runtime-info.outputs.rid }}
140-
steps:
141-
- name: Checkout
142-
uses: actions/checkout@v4
143-
with:
144-
fetch-depth: 0
145-
146-
- name: Setup .NET
147-
uses: actions/setup-dotnet@v4
148-
with:
149-
dotnet-version: 8.0.x
150-
151-
- name: Install dependencies
152-
run: choco install ninja -y
153-
shell: powershell
154-
155-
- name: Package native artifacts
156-
run: ./build/build.ps1 -Configuration Release -SkipDotnet -SkipTests
157-
shell: pwsh
158-
159-
- name: Determine runtime identifier
160-
id: runtime-info
161-
shell: pwsh
162-
run: |
163-
$archive = Get-ChildItem -Path artifacts/native-*.zip | Select-Object -First 1
164-
if (-not $archive) {
165-
throw "Unable to determine runtime identifier: no native archive found under artifacts/"
166-
}
167-
$rid = $archive.BaseName.Substring(7) # trim 'native-'
168-
"rid=$rid" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
169-
170-
- name: Upload native artifact
171-
uses: actions/upload-artifact@v4
172-
with:
173-
name: native-windows
174-
path: artifacts/native-win-*.zip
175-
if-no-files-found: error
32+
uses: ./.github/workflows/native-build.yml
33+
with:
34+
runner: windows-latest
35+
configuration: Release
36+
artifact-name: native-windows
17637

17738
native-windows-arm64:
178-
runs-on: windows-latest
179-
outputs:
180-
rid: ${{ steps.runtime-info.outputs.rid }}
181-
steps:
182-
- name: Checkout
183-
uses: actions/checkout@v4
184-
with:
185-
fetch-depth: 0
186-
187-
- name: Setup .NET
188-
uses: actions/setup-dotnet@v4
189-
with:
190-
dotnet-version: 8.0.x
191-
192-
- name: Install dependencies
193-
run: choco install ninja -y
194-
shell: powershell
195-
196-
- name: Package native artifacts
197-
run: ./build/build.ps1 -Configuration Release -SkipDotnet -SkipTests -Architecture arm64
198-
shell: pwsh
199-
200-
- name: Determine runtime identifier
201-
id: runtime-info
202-
shell: pwsh
203-
run: |
204-
$archive = Get-ChildItem -Path artifacts/native-*.zip | Select-Object -First 1
205-
if (-not $archive) {
206-
throw "Unable to determine runtime identifier: no native archive found under artifacts/"
207-
}
208-
$rid = $archive.BaseName.Substring(7)
209-
"rid=$rid" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
210-
211-
- name: Upload native artifact
212-
uses: actions/upload-artifact@v4
213-
with:
214-
name: native-windows-arm64
215-
path: artifacts/native-win-*.zip
216-
if-no-files-found: error
39+
uses: ./.github/workflows/native-build.yml
40+
with:
41+
runner: windows-latest
42+
configuration: Release
43+
architecture: arm64
44+
artifact-name: native-windows-arm64
21745

21846
ios-xcframework:
21947
runs-on: macos-latest

.github/workflows/native-build.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Native Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runner:
7+
description: GitHub runner label to execute the build.
8+
type: string
9+
required: true
10+
configuration:
11+
description: Build configuration (e.g. Release, Debug).
12+
type: string
13+
default: Release
14+
architecture:
15+
description: Optional target architecture (e.g. arm64) for Windows builds.
16+
type: string
17+
default: ""
18+
artifact-name:
19+
description: Name to use when uploading the native artifact.
20+
type: string
21+
required: true
22+
skip-dotnet:
23+
description: Skip the dotnet restore/build/pack steps inside build scripts.
24+
type: boolean
25+
default: true
26+
skip-tests:
27+
description: Skip native test execution inside build scripts.
28+
type: boolean
29+
default: true
30+
dotnet-version:
31+
description: .NET version to install.
32+
type: string
33+
default: 8.0.x
34+
outputs:
35+
rid:
36+
description: Runtime identifier generated by the native build.
37+
value: ${{ jobs.build.outputs.rid }}
38+
39+
jobs:
40+
build:
41+
runs-on: ${{ inputs.runner }}
42+
outputs:
43+
rid: ${{ steps.runtime-info.outputs.rid }}
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Setup .NET
51+
uses: actions/setup-dotnet@v4
52+
with:
53+
dotnet-version: ${{ inputs.dotnet-version }}
54+
55+
- name: Install dependencies (Linux)
56+
if: startsWith(inputs.runner, 'ubuntu')
57+
run: |
58+
sudo apt-get update
59+
sudo apt-get install -y libgtk-3-dev ninja-build clang-format zip
60+
shell: bash
61+
62+
- name: Install dependencies (macOS)
63+
if: startsWith(inputs.runner, 'macos')
64+
run: |
65+
brew update
66+
brew install gtk+3 ninja clang-format
67+
shell: bash
68+
69+
- name: Install dependencies (Windows)
70+
if: startsWith(inputs.runner, 'windows')
71+
run: choco install ninja -y
72+
shell: pwsh
73+
74+
- name: Package native artifacts (Unix)
75+
if: startsWith(inputs.runner, 'ubuntu') || startsWith(inputs.runner, 'macos')
76+
shell: bash
77+
run: |
78+
set -euo pipefail
79+
args=("${{ inputs.configuration }}")
80+
if [[ '${{ inputs.skip-dotnet }}' == 'true' ]]; then
81+
args+=('--skip-dotnet')
82+
fi
83+
if [[ '${{ inputs.skip-tests }}' == 'true' ]]; then
84+
args+=('--skip-tests')
85+
fi
86+
./build/build.sh "${args[@]}"
87+
88+
- name: Package native artifacts (Windows)
89+
if: startsWith(inputs.runner, 'windows')
90+
shell: pwsh
91+
run: |
92+
$args = @('-Configuration', '${{ inputs.configuration }}')
93+
if ('${{ inputs.skip-dotnet }}' -eq 'true') { $args += '-SkipDotnet' }
94+
if ('${{ inputs.skip-tests }}' -eq 'true') { $args += '-SkipTests' }
95+
if ('${{ inputs.architecture }}') { $args += @('-Architecture', '${{ inputs.architecture }}') }
96+
./build/build.ps1 @args
97+
98+
- name: Determine runtime identifier
99+
id: runtime-info
100+
shell: bash
101+
run: |
102+
set -euo pipefail
103+
shopt -s nullglob
104+
files=(artifacts/native-*.zip)
105+
if (( ${#files[@]} == 0 )); then
106+
echo "No native archives found under artifacts/" >&2
107+
exit 1
108+
fi
109+
archive="${files[0]}"
110+
rid="${archive#artifacts/native-}"
111+
rid="${rid%.zip}"
112+
echo "rid=${rid}" >> "${GITHUB_OUTPUT}"
113+
114+
- name: Upload native artifact
115+
uses: actions/upload-artifact@v4
116+
with:
117+
name: ${{ inputs.artifact-name }}
118+
path: artifacts/native-*.zip
119+
if-no-files-found: error

0 commit comments

Comments
 (0)