Update dotnet.yml #105
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: .NET Core | |
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@v3 | |
with: | |
dotnet-version: 8.x | |
- name: Setup MSBuild | |
uses: microsoft/setup-msbuild@v1.1.3 | |
- 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 -v | |
- name: Cleanup Private Key | |
run: rm WmiLight\private_key.snk -v | |
- 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 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: 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: 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 | |
# 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 | |
# 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 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 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 |