Skip to content

Commit 083e041

Browse files
committed
Publish yml
1 parent a27e53e commit 083e041

1 file changed

Lines changed: 201 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
packages: write
9+
contents: read
10+
actions: write
11+
12+
env:
13+
DOTNET_VERSION: '10.0.x'
14+
ARTIFACT_OUTPUT: '${{ github.workspace }}/artifacts'
15+
16+
jobs:
17+
build-native:
18+
name: Build native framework-system rust (${{ matrix.os }} ${{ matrix.platform }})
19+
strategy:
20+
fail-fast: true
21+
matrix:
22+
include:
23+
- os: Windows
24+
runsOn: windows-latest
25+
platform: win-x64
26+
artifactPath: framework-system/target/release/framework_dotnet_ffi.dll
27+
- os: Windows
28+
runsOn: windows-11-arm
29+
platform: win-arm64
30+
artifactPath: framework-system/target/release/framework_dotnet_ffi.dll
31+
- os: Linux
32+
runsOn: ubuntu-latest
33+
platform: linux-x64
34+
artifactPath: framework-system/target/release/libframework_dotnet_ffi.so
35+
- os: Linux
36+
runsOn: ubuntu-24.04-arm
37+
platform: linux-arm64
38+
artifactPath: framework-system/target/release/libframework_dotnet_ffi.so
39+
40+
runs-on: ${{ matrix.runsOn }}
41+
42+
steps:
43+
- uses: actions/checkout@v6
44+
with:
45+
submodules: recursive
46+
47+
- name: Setup Rust toolchain
48+
run: rustup show
49+
50+
- name: Cache Rust dependencies
51+
uses: Swatinem/rust-cache@v2
52+
with:
53+
workspaces: |
54+
framework-system -> target
55+
56+
- name: Install Linux Framework dependencies
57+
if: runner.os == 'Linux'
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y libudev-dev
61+
62+
- name: Build native library
63+
run: cargo build --manifest-path framework-system/Cargo.toml -p framework_dotnet_ffi --release
64+
65+
- name: Upload native artifact
66+
uses: actions/upload-artifact@v7
67+
with:
68+
name: framework-dotnet-native-${{ matrix.platform }}
69+
path: ${{ matrix.artifactPath }}
70+
if-no-files-found: error
71+
72+
- name: Upload generated bindings artifact
73+
if: matrix.platform == 'win-x64'
74+
uses: actions/upload-artifact@v7
75+
with:
76+
name: framework-dotnet-bindings
77+
path: framework-system/framework_dotnet_ffi/csharp/NativeMethods.g.cs
78+
if-no-files-found: error
79+
80+
- name: "Cancel if failure"
81+
if: ${{ failure() }}
82+
uses: potiuk/cancel-workflow-runs@master
83+
with:
84+
cancelMode: self
85+
cancelFutureDuplicates: false
86+
selfPreservation: false
87+
token: ${{ secrets.GITHUB_TOKEN }}
88+
89+
pack:
90+
name: Pack and publish NuGet
91+
needs: build-native
92+
runs-on: windows-latest
93+
94+
steps:
95+
- uses: actions/checkout@v6
96+
with:
97+
submodules: recursive
98+
99+
- name: Setup .NET
100+
uses: actions/setup-dotnet@v5
101+
with:
102+
dotnet-version: ${{ env.DOTNET_VERSION }}
103+
104+
- name: Download generated bindings artifact
105+
uses: actions/download-artifact@v8
106+
with:
107+
name: framework-dotnet-bindings
108+
path: framework-system/framework_dotnet_ffi/csharp
109+
110+
- name: Download win-x64 native artifact
111+
uses: actions/download-artifact@v8
112+
with:
113+
name: framework-dotnet-native-win-x64
114+
path: artifacts/win-x64
115+
116+
- name: Download win-arm64 native artifact
117+
uses: actions/download-artifact@v8
118+
with:
119+
name: framework-dotnet-native-win-arm64
120+
path: artifacts/win-arm64
121+
122+
- name: Download linux-x64 native artifact
123+
uses: actions/download-artifact@v8
124+
with:
125+
name: framework-dotnet-native-linux-x64
126+
path: artifacts/linux-x64
127+
128+
- name: Download linux-arm64 native artifact
129+
uses: actions/download-artifact@v8
130+
with:
131+
name: framework-dotnet-native-linux-arm64
132+
path: artifacts/linux-arm64
133+
134+
- name: Set version environment variable
135+
run: |
136+
$tagName = "${{ github.event.release.tag_name }}"
137+
# Check if the tag starts with 'v' and remove it
138+
if ($tagName.StartsWith("v")) {
139+
$version = $tagName.Substring(1)
140+
} else {
141+
$version = $tagName
142+
}
143+
144+
Write-Host "The original tag name was: $tagName"
145+
Write-Host "The processed version is: $version"
146+
147+
# Set the environment variable for subsequent steps in the same job
148+
echo "version=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
149+
shell: pwsh # Explicitly use PowerShell Core (default on windows-latest for 'run')
150+
151+
- name: Restore dependencies
152+
run: dotnet restore -p:Version=${{ env.version }} -p:InformationalVersion=${{ env.version }}+${{ github.sha }} -p:DebugSymbols=true -p:DebugType=portable
153+
154+
- name: Build
155+
run: >-
156+
dotnet build framework-dotnet/framework-dotnet.csproj
157+
-v normal
158+
--configuration Release
159+
--no-restore
160+
-p:Version=${{ env.version }}
161+
-p:InformationalVersion=${{ env.version }}+${{ github.sha }
162+
-p:DebugSymbols=true
163+
-p:DebugType=portable
164+
-p:ContinuousIntegrationBuild=true
165+
-p:SkipRustBuild=true
166+
-p:FrameworkDotnetWindowsNativeLibraryPath=${{ github.workspace }}\artifacts\win-x64\framework_dotnet_ffi.dll
167+
-p:FrameworkDotnetWindowsArm64NativeLibraryPath=${{ github.workspace }}\artifacts\win-arm64\framework_dotnet_ffi.dll
168+
-p:FrameworkDotnetLinuxNativeLibraryPath=${{ github.workspace }}\artifacts\linux-x64\libframework_dotnet_ffi.so
169+
-p:FrameworkDotnetLinuxArm64NativeLibraryPath=${{ github.workspace }}\artifacts\linux-arm64\libframework_dotnet_ffi.so
170+
171+
- name: Pack NuGet package
172+
run: >-
173+
dotnet pack framework-dotnet/framework-dotnet.csproj
174+
-v normal
175+
--configuration Release
176+
--no-restore
177+
--no-build
178+
--output ${{ env.ARTIFACT_OUTPUT }}
179+
-p:Version=${{ env.version }}
180+
-p:InformationalVersion=${{ env.version }}+${{ github.sha }
181+
-p:DebugSymbols=true
182+
-p:DebugType=portable
183+
-p:ContinuousIntegrationBuild=true
184+
-p:SkipRustBuild=true
185+
-p:FrameworkDotnetWindowsNativeLibraryPath=${{ github.workspace }}\artifacts\win-x64\framework_dotnet_ffi.dll
186+
-p:FrameworkDotnetWindowsArm64NativeLibraryPath=${{ github.workspace }}\artifacts\win-arm64\framework_dotnet_ffi.dll
187+
-p:FrameworkDotnetLinuxNativeLibraryPath=${{ github.workspace }}\artifacts\linux-x64\libframework_dotnet_ffi.so
188+
-p:FrameworkDotnetLinuxArm64NativeLibraryPath=${{ github.workspace }}\artifacts\linux-arm64\libframework_dotnet_ffi.so
189+
190+
- name: Upload NuGet package artifact
191+
uses: actions/upload-artifact@v7
192+
with:
193+
name: framework-dotnet-nuget
194+
path: ${{ env.ARTIFACT_OUTPUT }}
195+
if-no-files-found: error
196+
- name: Push nugets to Github
197+
run: |
198+
nuget sources Add -Name "GitHub" -Source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json -Username "${{ github.actor }}" -Password "${{ secrets.GITHUB_TOKEN }}"
199+
nuget push "${{ env.ARTIFACT_OUTPUT }}/**/*.nupkg" -Source "GitHub"
200+
nuget push "${{ env.ARTIFACT_OUTPUT }}/**/*.nupkg" -Source https://api.nuget.org/v3/index.json -NoSymbols -SkipDuplicate -ApiKey ${{ secrets.NUGET_KEY }}
201+

0 commit comments

Comments
 (0)