Skip to content

Update build.yml

Update build.yml #112

Workflow file for this run

name: Build
on:
push:
pull_request:
release:
types:
- published
env:
# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Release
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v4.1.0
with:
dotnet-version: 8.x
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
with:
vs-version: '[17.11]'
- name: Restore NuGet packages
run: dotnet restore
- name: Extract Private Key
run: |
echo "${{ secrets.PRIVATE_KEY }}" > WmiLight\private_key.base64
certutil -decode WmiLight\private_key.base64 WmiLight\private_key.snk
rm WmiLight\private_key.base64
- name: Build .Net Lib
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} WmiLight\WmiLight.csproj
- name: Cleanup Private Key
run: rm WmiLight\private_key.snk
- name: Build Native dynamic Lib (x64)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=DynamicLibrary /p:Platform=x64 WmiLight.Native\WmiLight.Native.vcxproj
- name: Build Native dynamic Lib (x86)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=DynamicLibrary /p:Platform=x86 WmiLight.Native\WmiLight.Native.vcxproj
- name: Build Native dynamic Lib (arm64)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=DynamicLibrary /p:Platform=arm64 WmiLight.Native\WmiLight.Native.vcxproj
- name: Build Native static Lib (x64, NoOp)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=StaticLibrary /p:WholeProgramOptimization=false /p:Platform=x64 WmiLight.Native\WmiLight.Native.vcxproj
- name: Build Native static Lib (x86, NoOp)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=StaticLibrary /p:WholeProgramOptimization=false /p:Platform=x86 WmiLight.Native\WmiLight.Native.vcxproj
- name: Build Native static Lib (arm64, NoOp)
# See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:ConfigurationType=StaticLibrary /p:WholeProgramOptimization=false /p:Platform=arm64 WmiLight.Native\WmiLight.Native.vcxproj
- name: Run Unit Tests (x64)
run: dotnet test -property:Platform=x64 --configuration ${{env.BUILD_CONFIGURATION}} .\WmiLight.UnitTests\WmiLight.UnitTests.csproj
- name: Run Unit Tests (x86)
run: dotnet test -property:Platform=x64 --configuration ${{env.BUILD_CONFIGURATION}} .\WmiLight.UnitTests\WmiLight.UnitTests.csproj
- name: Run Unit Tests (arm64)
run: echo "::warning Unit Tests are disabled for Arm64 because there is no machine to run tests at Arm64 architecture."
#run: dotnet test -property:Platform=arm64 --configuration ${{env.BUILD_CONFIGURATION}} .\WmiLight.UnitTests\WmiLight.UnitTests.csproj
- name: Pack with dotnet
run: dotnet pack WmiLight\WmiLight.csproj --configuration ${{env.BUILD_CONFIGURATION}} --output nuget-packages --no-build
- name: Add Nativ Native Lib to NuGet package
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
$nuget_package_name = ('nuget-packages\' + [io.path]::GetFileName((Get-ChildItem 'nuget-packages\')))
$zip_file = [io.path]::ChangeExtension($nuget_package_name, ".zip")
# rename .nupkg to .zip because we need a .zip for Expand-Archive
Rename-Item $nuget_package_name ([io.path]::GetFileName($zip_file))
Expand-Archive $zip_file -DestinationPath 'nuget-packages\unpacked'
Remove-Item $zip_file
# create folders for native runtime DLLs
New-Item 'nuget-packages\unpacked\runtimes\win-x64\native\' -Type Directory
New-Item 'nuget-packages\unpacked\runtimes\win-x86\native\' -Type Directory
New-Item 'nuget-packages\unpacked\runtimes\win-arm64\native\' -Type Directory
# create folders native libs
New-Item 'nuget-packages\unpacked\lib\native\win-x64\' -Type Directory
New-Item 'nuget-packages\unpacked\lib\native\win-x86\' -Type Directory
New-Item 'nuget-packages\unpacked\lib\native\win-arm64\' -Type Directory
# create folders for WmiLight.props and WmiLight.targets
New-Item 'nuget-packages\unpacked\build\' -Type Directory
# copy native runtime DLLs for dynamic linking
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x64\WmiLight.Native.dll' 'nuget-packages\unpacked\runtimes\win-x64\native\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x86\WmiLight.Native.dll' 'nuget-packages\unpacked\runtimes\win-x86\native\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\arm64\WmiLight.Native.dll' 'nuget-packages\unpacked\runtimes\win-arm64\native\'
# copy native libs and .pdb files for static linking
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x64\WmiLight.Native.lib' 'nuget-packages\unpacked\lib\native\win-x64\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x64\WmiLight.Native.pdb' 'nuget-packages\unpacked\lib\native\win-x64\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x86\WmiLight.Native.lib' 'nuget-packages\unpacked\lib\native\win-x86\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\x86\WmiLight.Native.pdb' 'nuget-packages\unpacked\lib\native\win-x86\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\arm64\WmiLight.Native.lib' 'nuget-packages\unpacked\lib\native\win-arm64\'
Copy-Item 'WmiLight.Native\bin\${{env.BUILD_CONFIGURATION}}\arm64\WmiLight.Native.pdb' 'nuget-packages\unpacked\lib\native\win-arm64\'
# copy WmiLight.props and WmiLight.targets
Copy-Item 'WmiLight\.nuget\.build\WmiLight.props' 'nuget-packages\unpacked\build\'
Copy-Item 'WmiLight\.nuget\.build\WmiLight.targets' 'nuget-packages\unpacked\build\'
Compress-Archive 'nuget-packages\unpacked\*' $zip_file
Rename-Item $zip_file ([io.path]::GetFileName($nuget_package_name))
Remove-Item -Recurse -Force -Confirm:$false 'nuget-packages\unpacked'
- name: Push with dotnet
if: github.event.action == 'published'
run: dotnet nuget push nuget-packages/ --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json