nuget package #114
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: nuget package | |
on: | |
workflow_dispatch: | |
inputs: | |
dry-run: | |
description: 'Dry run' | |
required: true | |
type: boolean | |
default: true | |
schedule: | |
- cron: '32 5 * * 1' # 05:32 AM UTC every Monday | |
jobs: | |
preflight: | |
name: Preflight | |
runs-on: ubuntu-20.04 | |
outputs: | |
dry-run: ${{ steps.get-dry-run.outputs.dry-run }} | |
steps: | |
- name: Get dry run | |
id: get-dry-run | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
$IsDryRun = '${{ github.event.inputs.dry-run }}' -Eq 'true' -Or '${{ github.event_name }}' -Eq 'schedule' | |
if ($IsDryRun) { | |
echo "dry-run=true" >> $Env:GITHUB_OUTPUT | |
} else { | |
echo "dry-run=false" >> $Env:GITHUB_OUTPUT | |
} | |
build-native: | |
name: Build native library | |
runs-on: windows-2022 | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [ x86, x64, arm64 ] | |
steps: | |
- name: Configure runner | |
run: | | |
Install-Module -Name VsDevShell -Force | |
- name: Check out ${{ github.repository }} | |
uses: actions/checkout@v3 | |
- name: Build Detours (${{matrix.arch}}) | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
Enter-VsDevShell ${{matrix.arch}} | |
.\detours.ps1 | |
- name: Build MsRdpEx.dll (${{matrix.arch}}) | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
$ArchDir = "${{matrix.arch}}" | |
$BuildDir = "build-$ArchDir" | |
$MsvcArch = @{"x86"="Win32";"x64"="x64";"arm64"="ARM64"}["${{matrix.arch}}"] | |
cmake -G "Visual Studio 17 2022" -A $MsvcArch -DWITH_DOTNET=OFF -B $BuildDir | |
cmake --build $BuildDir --config Release | |
New-Item -ItemType Directory -Path "dependencies/MsRdpEx/$ArchDir" | Out-Null | |
Copy-Item "$BuildDir/Release/MsRdpEx.dll" "dependencies/MsRdpEx/$ArchDir" | |
- name: Upload native components | |
uses: actions/upload-artifact@v3 | |
with: | |
name: MsRdpEx-${{matrix.arch}} | |
path: dependencies/MsRdpEx/${{matrix.arch}} | |
build-managed: | |
name: Build and package managed library | |
runs-on: windows-2022 | |
needs: build-native | |
steps: | |
- name: Check out ${{ github.repository }} | |
uses: actions/checkout@v3 | |
- name: Prepare dependencies | |
shell: pwsh | |
run: | | |
New-Item -ItemType Directory -Path "dependencies/MsRdpEx" | Out-Null | |
- name: Download native components | |
uses: actions/download-artifact@v3 | |
with: | |
path: dependencies/MsRdpEx | |
- name: Rename dependencies | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
Set-Location "dependencies/MsRdpEx" | |
$(Get-Item ".\MsRdpEx-*") | ForEach-Object { ($p1,$p2) = $_.Name -Split '-'; Rename-Item $_ $p2 } | |
Get-ChildItem * -Recurse | |
- name: Build MsRdpEx.dll (managed) | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
$BuildDir = "build-dotnet" | |
cmake -G "Visual Studio 17 2022" -A x64 -DWITH_DOTNET=ON -DWITH_NATIVE=OFF -B $BuildDir | |
cmake --build $BuildDir --config Release | |
& dotnet pack .\dotnet\Devolutions.MsRdpEx -o package | |
- name: Upload managed components | |
uses: actions/upload-artifact@v3 | |
with: | |
name: MsRdpEx-nupkg | |
path: package/*.nupkg | |
publish: | |
name: Publish NuGet package | |
runs-on: ubuntu-20.04 | |
environment: nuget-publish | |
if: needs.preflight.outputs.dry-run == 'false' | |
needs: | |
- preflight | |
- build-managed | |
steps: | |
- name: Download NuGet package artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: MsRdpEx-nupkg | |
path: package | |
- name: Publish to nuget.org | |
shell: pwsh | |
run: | | |
Set-PSDebug -Trace 1 | |
$Files = Get-ChildItem -Recurse package/*.nupkg | |
foreach ($File in $Files) { | |
$PushCmd = @( | |
'dotnet', | |
'nuget', | |
'push', | |
"$File", | |
'--api-key', | |
'${{ secrets.NUGET_API_KEY }}', | |
'--source', | |
'https://api.nuget.org/v3/index.json', | |
'--skip-duplicate' | |
) | |
Write-Host "Publishing $($File.Name)..." | |
$PushCmd = $PushCmd -Join ' ' | |
Invoke-Expression $PushCmd | |
} |