Skip to content

Commit 6935348

Browse files
committed
[Tests] Test nativeless package integration
1 parent db9743e commit 6935348

18 files changed

+505
-116
lines changed

.github/actions/copy-native-libraries/action.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Copy Native Libraries Near csproj'
1+
name: 'Copy native libraries locally'
22
description: 'Downloads and copies native libraries near csproj files'
33

44
inputs:
@@ -21,17 +21,7 @@ runs:
2121
path: ${{ runner.temp }}/NativeLibraries
2222
merge-multiple: false
2323

24-
- name: Copy native libraries near csproj
24+
- name: Copy native libraries locally
2525
shell: pwsh
2626
run: |
27-
$winX64Destination = "Native\win_x64"
28-
New-Item -ItemType Directory -Force -Path $winX64Destination
29-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_Win_x64/Melanchall_DryWetMidi_Native.dll" -Destination "$winX64Destination" -Force -Verbose
30-
31-
$winArm64Destination = "Native\win_arm64"
32-
New-Item -ItemType Directory -Force -Path $winArm64Destination
33-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_Win_arm64/Melanchall_DryWetMidi_Native.dll" -Destination "$winArm64Destination" -Force -Verbose
34-
35-
$macosX64Arm64Destination = "Native\macos_x64_arm64"
36-
New-Item -ItemType Directory -Force -Path $macosX64Arm64Destination
37-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_macOS_x64_arm64/Melanchall_DryWetMidi_Native.dylib" -Destination "$macosX64Arm64Destination" -Force -Verbose
27+
& "${{ github.workspace }}/Resources/Scripts/Copy native binaries locally.ps1" -fromDirectory "${{ runner.temp }}/NativeLibraries"

.github/workflows/build-package.yml

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
required: false
99
type: string
1010
default: 'Full'
11-
prerelease-number:
12-
description: 'Prerelease number (empty for release)'
13-
required: false
14-
type: string
15-
default: ''
1611

1712
jobs:
1813
build-package:
@@ -52,25 +47,6 @@ jobs:
5247
5348
$xml.Save($filePath)
5449
55-
- name: Setup prerelease version
56-
if: inputs.prerelease-number != ''
57-
shell: pwsh
58-
run: |
59-
$filePath = Resolve-Path "DryWetMidi/Melanchall.DryWetMidi.csproj"
60-
$xml = New-Object xml
61-
$xml.PreserveWhitespace = $true
62-
$xml.Load($filePath)
63-
$version = $xml.Project.PropertyGroup[1].Version
64-
Write-Host "Current version is $version"
65-
Write-Host "Prerelease number is ${{ inputs.prerelease-number }}"
66-
$newVersion = $version + "-prerelease${{ inputs.prerelease-number }}"
67-
$xml.Project.PropertyGroup[1].Version = $newVersion
68-
Write-Host "New version: $($xml.Project.PropertyGroup[1].Version)"
69-
Write-Host "Removing release notes..."
70-
$xml.Project.PropertyGroup[1].PackageReleaseNotes = ""
71-
Write-Host "Release notes: $($xml.Project.PropertyGroup[1].PackageReleaseNotes)"
72-
$xml.Save($filePath)
73-
7450
- name: Setup framework
7551
id: framework
7652
uses: ./.github/actions/setup-framework
@@ -81,21 +57,48 @@ jobs:
8157
netframework-tfm: ${{ vars.BUILD_FRAMEWORK_NETFRAMEWORK_TFM || 'net48' }}
8258
netframework-sdk-version: ${{ vars.BUILD_FRAMEWORK_NETFRAMEWORK_SDK_VERSION || '8.0.x' }}
8359

84-
- name: Copy native libraries near csproj
60+
- name: Setup nativeless project
61+
shell: pwsh
62+
run: |
63+
$encoding = [System.Text.Encoding]::UTF8
64+
$filePath = Resolve-Path "DryWetMidi\Melanchall.DryWetMidi.csproj"
65+
$csproj = [xml]([System.IO.File]::ReadAllText($filePath, $encoding))
66+
67+
Write-Host "Setting package metadata values..."
68+
$packageGroup = (Select-Xml -Xml $csproj.Project -XPath "//*[@Label='Package']").Node
69+
Write-Host "Current 'Package' group:"
70+
Write-Host ($packageGroup | Format-Table | Out-String)
71+
$packageGroup.PackageId = "Melanchall.DryWetMidi.Nativeless"
72+
$description = $packageGroup.Description
73+
$readmeNode = (Select-Xml -Xml $packageGroup -XPath "//PackageReadmeFile").Node
74+
$packageGroup.RemoveChild($readmeNode)
75+
Write-Host "New 'Package' group:"
76+
Write-Host ($packageGroup | Format-Table | Out-String)
77+
78+
$nativeGroup = (Select-Xml -Xml $csproj.Project -XPath "//*[@Label='Native']").Node
79+
Write-Host "'Native' group will be removed:"
80+
Write-Host ($nativeGroup | Format-Table | Out-String)
81+
$csproj.Project.RemoveChild($nativeGroup)
82+
83+
Write-Host "Removing README pack instruction..."
84+
$resourcesGroup = (Select-Xml -Xml $csproj.Project -XPath "//*[@Label='Resources']").Node
85+
Write-Host "'Resources' group:"
86+
Write-Host ($resourcesGroup | Format-Table | Out-String)
87+
$readmeNode = (Select-Xml -Xml $resourcesGroup -XPath "//*[contains(@Include,'README')]").Node
88+
Write-Host "'README' node:"
89+
Write-Host ($readmeNode | Format-Table | Out-String)
90+
$resourcesGroup.RemoveChild($readmeNode)
91+
92+
$csproj.Save($filePath)
93+
94+
Write-Host "Setting icon path..."
95+
(Get-Content $filePath) -replace 'icon.png', 'icon-nativeless.png' | Set-Content $filePath
96+
97+
- name: Copy native libraries locally
8598
if: inputs.package-type == 'Full'
8699
shell: pwsh
87100
run: |
88-
$winX64Destination = "Native\win_x64"
89-
New-Item -ItemType Directory -Force -Path $winX64Destination
90-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_Win_x64/Melanchall_DryWetMidi_Native.dll" -Destination "$winX64Destination" -Force -Verbose
91-
92-
$winArm64Destination = "Native\win_arm64"
93-
New-Item -ItemType Directory -Force -Path $winArm64Destination
94-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_Win_arm64/Melanchall_DryWetMidi_Native.dll" -Destination "$winArm64Destination" -Force -Verbose
95-
96-
$macosX64Arm64Destination = "Native\macos_x64_arm64"
97-
New-Item -ItemType Directory -Force -Path $macosX64Arm64Destination
98-
Copy-Item -Path "${{ runner.temp }}/NativeLibraries/Native_macOS_x64_arm64/Melanchall_DryWetMidi_Native.dylib" -Destination "$macosX64Arm64Destination" -Force -Verbose
101+
& "${{ github.workspace }}/Resources/Scripts/Copy native binaries locally.ps1" -fromDirectory "${{ runner.temp }}/NativeLibraries"
99102
100103
- name: Build project
101104
run: dotnet build DryWetMidi/Melanchall.DryWetMidi.csproj --configuration ${{ vars.BUILD_CONFIGURATION || 'Release' }}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Test nativeless package integration
2+
3+
run-name: TestNativelessPackageIntegration_${{ github.ref_name }}_${{ vars.LIBRARY_VERSION }}_${{ github.run_number }}
4+
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- master
10+
- develop
11+
- nativeless-pack-integ
12+
paths:
13+
- 'DryWetMidi/**'
14+
- '.github/workflows/test-nativeless-package-integration.yml'
15+
- '.github/workflows/build-native-libs.yml'
16+
- '.github/workflows/build-package.yml'
17+
- '.github/actions/**'
18+
- 'Resources/PackageIntegrationTestUtilities/DwmNativelessNetConsoleApp/**'
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
build-package:
26+
name: Build NuGet Package
27+
uses: ./.github/workflows/build-package.yml
28+
secrets: inherit
29+
with:
30+
package-type: 'Nativeless'
31+
32+
test-package-integration:
33+
name: Test package integration (${{ matrix.os }})
34+
needs: build-package
35+
runs-on: ${{ matrix.os }}
36+
timeout-minutes: 60
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
include:
41+
- os: windows-11-arm
42+
framework: Net
43+
rid: win-arm64
44+
- os: macos-latest
45+
framework: Net
46+
rid: osx-arm64
47+
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Download NuGet package
53+
uses: actions/download-artifact@v4
54+
with:
55+
name: NuGetPackage
56+
path: NuGetPackage
57+
58+
- name: Setup framework
59+
id: framework
60+
uses: ./.github/actions/setup-framework
61+
with:
62+
framework: ${{ matrix.framework }}
63+
net-tfm: ${{ vars.BUILD_FRAMEWORK_NET_TFM || 'net8.0' }}
64+
net-sdk-version: ${{ vars.BUILD_FRAMEWORK_NET_SDK_VERSION || '8.0.x' }}
65+
netframework-tfm: ${{ vars.BUILD_FRAMEWORK_NETFRAMEWORK_TFM || 'net48' }}
66+
netframework-sdk-version: ${{ vars.BUILD_FRAMEWORK_NETFRAMEWORK_SDK_VERSION || '8.0.x' }}
67+
68+
- name: Add package to the project
69+
shell: pwsh
70+
run: |
71+
Write-Host "Adding local NuGet source with the package..."
72+
dotnet nuget add source "${{ github.workspace }}/NuGetPackage"
73+
74+
Write-Host "Adding Melanchall.DryWetMidi.Nativeless.${{ vars.LIBRARY_VERSION }} package reference to the project..."
75+
$path = Resolve-Path 'Resources/PackageIntegrationTestUtilities/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp.csproj'
76+
dotnet add "$path" package Melanchall.DryWetMidi.Nativeless -v ${{ vars.LIBRARY_VERSION }} -s "${{ github.workspace }}/NuGetPackage"
77+
78+
- name: Check csproj package reference
79+
shell: pwsh
80+
run: |
81+
$path = "Resources/PackageIntegrationTestUtilities/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp.csproj"
82+
$expected = '<PackageReference Include="Melanchall.DryWetMidi.Nativeless" Version="${{ vars.LIBRARY_VERSION }}" />'
83+
Write-Host "Expecting: $expected"
84+
$found = Select-String -Path $path -Pattern $expected -SimpleMatch -Quiet
85+
if (-not $found) {
86+
Write-Error "Package reference not found: $expected"
87+
exit 1
88+
}
89+
Write-Host "Package reference found."
90+
91+
- name: Run app via dotnet
92+
shell: pwsh
93+
run: |
94+
$path = Resolve-Path 'Resources/PackageIntegrationTestUtilities/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp.csproj'
95+
dotnet run --project "$path" --configuration ${{ vars.BUILD_CONFIGURATION }}
96+
97+
- name: Run app after publish
98+
shell: pwsh
99+
run: |
100+
$projectPath = "Resources/PackageIntegrationTestUtilities/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp/DwmNativelessNetConsoleApp.csproj"
101+
102+
foreach ($psf in @('true', 'false')) {
103+
foreach ($prtr in @('true', 'false')) {
104+
foreach ($inlfse in @('true', 'false')) {
105+
foreach ($sc in @('true', 'false')) {
106+
foreach ($pt in @('true', 'false')) {
107+
$publishOptions = @"
108+
SelfContained = $sc
109+
PublishSingleFile = $psf
110+
PublishReadyToRun = $prtr
111+
IncludeNativeLibrariesForSelfExtract = $inlfse
112+
PublishTrimmed = $pt
113+
"@
114+
Write-Host "$publishOptions"
115+
116+
$outputPath = "${{ runner.temp }}/publish/$rid/sc-$sc-psf-$psf-prtr-$prtr-inlfse-$inlfse-pt-$pt"
117+
Write-Host "Output path set to '$outputPath'"
118+
119+
Write-Host "Publishing the app..."
120+
dotnet publish `
121+
--configuration ${{ vars.BUILD_CONFIGURATION }} `
122+
--runtime ${{ matrix.rid }} `
123+
--self-contained=$sc `
124+
-p:PublishSingleFile=$psf `
125+
-p:PublishReadyToRun=$prtr `
126+
-p:IncludeNativeLibrariesForSelfExtract=$inlfse `
127+
-p:PublishTrimmed=$pt `
128+
-p:SolutionDir="${{ github.workspace }}/" `
129+
--output $outputPath `
130+
$projectPath
131+
132+
if ($LASTEXITCODE -ne 0) {
133+
Write-Error "Publish failed with exit code $LASTEXITCODE"
134+
exit $LASTEXITCODE
135+
}
136+
137+
Write-Host "Listing published files..."
138+
Write-Host ""
139+
Get-ChildItem -Recurse -Force -Path "$outputPath" | Format-Table @{Label="File Name"; Expression={$_.Name}}, @{Label="Size (KB)"; Expression={"{0:N2}" -f ($_.Length / 1KB)}}
140+
Write-Host ""
141+
142+
$dllFile = Join-Path "$outputPath" "Melanchall_DryWetMidi_Native.dll"
143+
$dylibFile = Join-Path "$outputPath" "Melanchall_DryWetMidi_Native.dylib"
144+
145+
if ((Test-Path $dllFile) -or (Test-Path $dylibFile)) {
146+
Write-Output "Some native binaries exist."
147+
exit 1
148+
} else {
149+
Write-Output "There are no native binaries and that's OK.'"
150+
Write-Host ""
151+
}
152+
153+
Write-Host "Running the app..."
154+
Write-Host ""
155+
if ($IsWindows) {
156+
& "$outputPath/DwmNativelessNetConsoleApp.exe"
157+
} else {
158+
& "$outputPath/DwmNativelessNetConsoleApp"
159+
}
160+
161+
if ($LASTEXITCODE -ne 0) {
162+
Write-Error "App execution failed with exit code $LASTEXITCODE"
163+
exit $LASTEXITCODE
164+
}
165+
166+
Write-Host ""
167+
Write-Host "Configuration test completed successfully"
168+
Write-Host ""
169+
}
170+
}
171+
}
172+
}
173+
}

.github/workflows/test-net-package-integration.yml renamed to .github/workflows/test-package-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test package integration
22

3-
run-name: TestPackageIntegration_Net_${{ github.ref_name }}_${{ vars.LIBRARY_VERSION }}_${{ github.run_number }}
3+
run-name: TestPackageIntegration_${{ github.ref_name }}_${{ vars.LIBRARY_VERSION }}_${{ github.run_number }}
44

55
on:
66
workflow_dispatch:
@@ -10,7 +10,7 @@ on:
1010
- develop
1111
paths:
1212
- 'DryWetMidi/**'
13-
- '.github/workflows/test-net-package-integration.yml'
13+
- '.github/workflows/test-package-integration.yml'
1414
- '.github/workflows/build-native-libs.yml'
1515
- '.github/workflows/build-package.yml'
1616
- '.github/actions/**'

Resources/CI/Templates/job-build-package.yaml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
parameters:
2-
- name: buildConfiguration
3-
displayName: 'Build configuration'
4-
type: string
52
- name: prereleaseNumber
63
displayName: 'Pre-release number'
74
type: string
@@ -82,30 +79,20 @@ jobs:
8279
- template: step-setup-nativeless-project.yaml
8380

8481
- task: PowerShell@2
85-
displayName: Copy native libraries near csproj
82+
displayName: Copy native libraries locally
8683
condition: eq('${{ parameters.packageType }}', 'Full')
8784
inputs:
88-
targetType: 'inline'
89-
script: |
90-
$winX64Destination = "Native\win_x64"
91-
New-Item -ItemType Directory -Force -Path $winX64Destination
92-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_Win_x64/Melanchall_DryWetMidi_Native.dll" -Destination "$winX64Destination" -Force -Verbose
93-
94-
$winArm64Destination = "Native\win_arm64"
95-
New-Item -ItemType Directory -Force -Path $winArm64Destination
96-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_Win_arm64/Melanchall_DryWetMidi_Native.dll" -Destination "$winArm64Destination" -Force -Verbose
97-
98-
$macosX64Arm64Destination = "Native\macos_x64_arm64"
99-
New-Item -ItemType Directory -Force -Path $macosX64Arm64Destination
100-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_macOS_x64_arm64/Melanchall_DryWetMidi_Native.dylib" -Destination "$macosX64Arm64Destination" -Force -Verbose
85+
targetType: filePath
86+
filePath: '$(Build.SourcesDirectory)/Resources/Scripts/Copy native binaries locally.ps1'
87+
arguments: '-fromDirectory "$(Pipeline.Workspace)/NativeLibraries"'
10188

10289
- task: DotNetCoreCLI@2
10390
displayName: Build project
10491
inputs:
10592
command: 'build'
10693
projects: |
10794
DryWetMidi/Melanchall.DryWetMidi.csproj
108-
arguments: '--configuration ${{ parameters.buildConfiguration }}'
95+
arguments: '--configuration $(BuildConfiguration)'
10996

11097
- task: DotNetCoreCLI@2
11198
displayName: Create NuGet package

Resources/CI/Templates/step-copy-native-libraries-near-csproj.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,8 @@ steps:
1616
path: '$(Pipeline.Workspace)/NativeLibraries'
1717

1818
- task: PowerShell@2
19-
displayName: Copy native libraries near csproj
19+
displayName: Copy native libraries locally
2020
inputs:
21-
targetType: 'inline'
22-
script: |
23-
$winX64Destination = "Native\win_x64"
24-
New-Item -ItemType Directory -Force -Path $winX64Destination
25-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_Win_x64/Melanchall_DryWetMidi_Native.dll" -Destination "$winX64Destination" -Force -Verbose
26-
27-
$winArm64Destination = "Native\win_arm64"
28-
New-Item -ItemType Directory -Force -Path $winArm64Destination
29-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_Win_arm64/Melanchall_DryWetMidi_Native.dll" -Destination "$winArm64Destination" -Force -Verbose
30-
31-
$macosX64Arm64Destination = "Native\macos_x64_arm64"
32-
New-Item -ItemType Directory -Force -Path $macosX64Arm64Destination
33-
Copy-Item -Path "$(Pipeline.Workspace)/NativeLibraries/Native_macOS_x64_arm64/Melanchall_DryWetMidi_Native.dylib" -Destination "$macosX64Arm64Destination" -Force -Verbose
21+
targetType: filePath
22+
filePath: '$(Build.SourcesDirectory)/Resources/Scripts/Copy native binaries locally.ps1'
23+
arguments: '-fromDirectory "$(Pipeline.Workspace)/NativeLibraries"'

Resources/CI/build-artifacts-library-nativeless.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ stages:
2828
jobs:
2929
- template: Templates/job-build-package.yaml
3030
parameters:
31-
buildConfiguration: $(BuildConfiguration)
3231
packageType: 'Nativeless'
3332
- job: BuildBinaries
3433
displayName: Build binaries

0 commit comments

Comments
 (0)