-
Notifications
You must be signed in to change notification settings - Fork 127
115 lines (98 loc) · 3.91 KB
/
build-nuget.yml
File metadata and controls
115 lines (98 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Build and Pack NuGet
on:
workflow_dispatch: # Manual trigger
push:
tags:
- 'v*' # Trigger on version tags like v1.6.11
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set version number
id: version
run: |
$version = "1.6.11"
echo "VERSION=$version" >> $env:GITHUB_ENV
echo "Version will be: $version"
shell: pwsh
- name: Update GlobalAssemblyInfo.cs
run: |
$file = "Source/Common/GlobalAssemblyInfo.cs"
$content = Get-Content $file -Raw
$content = $content -replace '\[assembly: AssemblyVersion\("[\d\.]+"\)\]', "[assembly: AssemblyVersion(""$env:VERSION.0"")]"
$content = $content -replace '\[assembly: AssemblyFileVersion\("[\d\.]+"\)\]', "[assembly: AssemblyFileVersion(""$env:VERSION.0"")]"
Set-Content $file $content
echo "Updated GlobalAssemblyInfo.cs to version $env:VERSION.0"
shell: pwsh
- name: Update nuspec version
run: |
$file = "Nuget/WriteableBitmapEx.nuspec"
$content = Get-Content $file -Raw
$content = $content -replace '<version>[\d\.]+</version>', "<version>$env:VERSION</version>"
Set-Content $file $content
echo "Updated nuspec to version $env:VERSION"
shell: pwsh
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.x
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Restore NuGet packages
run: nuget restore Solution/WriteableBitmapEx_All.sln
- name: Build WPF Library
run: dotnet build Source/WriteableBitmapEx.Wpf/WriteableBitmapEx.Wpf.csproj -c Release /p:EnableWindowsTargeting=true
- name: List Build outputs
run: |
echo "Build/Release directory contents:"
dir Build\Release /s
shell: cmd
- name: Pack NuGet package
run: |
cd Nuget
..\3rdParty\nuget\nuget pack WriteableBitmapEx.nuspec -OutputDirectory ..\Build\nuget
shell: cmd
- name: Upload NuGet package as artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: Build/nuget/*.nupkg
- name: Publish to NuGet
run: |
# Check for .nupkg files (must exist)
$nupkgFiles = Get-ChildItem -Path "Build\nuget\*.nupkg" -ErrorAction SilentlyContinue
if ($null -eq $nupkgFiles -or $nupkgFiles.Count -eq 0) {
Write-Error "No .nupkg files found in Build\nuget\"
exit 1
}
# Push all .nupkg files
Write-Host "Pushing $($nupkgFiles.Count) .nupkg file(s)..."
foreach ($pkg in $nupkgFiles) {
Write-Host "Pushing $($pkg.Name)..."
& "3rdParty\nuget\nuget.exe" push $pkg.FullName -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to push $($pkg.Name)"
exit $LASTEXITCODE
}
}
# Check for .snupkg files (optional)
$snupkgFiles = Get-ChildItem -Path "Build\nuget\*.snupkg" -ErrorAction SilentlyContinue
if ($null -eq $snupkgFiles -or $snupkgFiles.Count -eq 0) {
Write-Host "No .snupkg found - skipping."
} else {
Write-Host "Pushing $($snupkgFiles.Count) .snupkg file(s)..."
foreach ($pkg in $snupkgFiles) {
Write-Host "Pushing $($pkg.Name)..."
& "3rdParty\nuget\nuget.exe" push $pkg.FullName -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to push $($pkg.Name)"
exit $LASTEXITCODE
}
}
}
Write-Host "Publish completed successfully!"
shell: pwsh