Skip to content

Commit 9be2670

Browse files
committed
Merge branch 'master' into net8
2 parents 498b3b9 + 20f12a7 commit 9be2670

1 file changed

Lines changed: 113 additions & 106 deletions

File tree

.github/workflows/publish-nugetorg.yml

Lines changed: 113 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ on:
55
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
66
push:
77
branches:
8-
- 'net8'
9-
- 'net9'
10-
- 'net10'
8+
- 'net8' # Run the workflow when pushing to net8 branch
9+
- 'net9' # Run the workflow when pushing to net9 branch
10+
- 'net10' # Run the workflow when pushing to net10 branch
1111
pull_request:
1212
branches:
1313
- '*' # Run the workflow for all pull requests
@@ -32,29 +32,83 @@ jobs:
3232
with:
3333
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
3434

35-
# Detect .NET SDK version based on branch
36-
- name: Determine .NET SDK Version
37-
id: dotnet_version
35+
# Determine target framework based on branch or release version
36+
- name: Determine Target Framework
37+
id: target_framework
3838
run: |
3939
$branch = "${{ github.ref_name }}"
40+
$targetFramework = "net9.0"
4041
$dotnetVersion = "9.0.101"
4142
42-
if ($branch -eq "net8" -or $branch.StartsWith("net8-")) {
43-
$dotnetVersion = "8.0"
44-
} elseif ($branch -eq "net9" -or $branch.StartsWith("net9-")) {
45-
$dotnetVersion = "9.0.101"
46-
} elseif ($branch -eq "net10" -or $branch.StartsWith("net10-")) {
47-
$dotnetVersion = "10.0"
43+
# Check if it's a release event
44+
if ("${{ github.event_name }}" -eq "release") {
45+
$version = "${{ github.event.release.tag_name }}"
46+
Write-Host "Release version: $version"
47+
48+
# Determine framework based on version pattern
49+
if ($version -match "^v?1\.0\.") {
50+
$targetFramework = "net8.0"
51+
$dotnetVersion = "8.0.x"
52+
Write-Host "Version 1.0.x detected - targeting .NET 8"
53+
}
54+
elseif ($version -match "^v?1\.1\.") {
55+
$targetFramework = "net9.0"
56+
$dotnetVersion = "9.0.101"
57+
Write-Host "Version 1.1.x detected - targeting .NET 9"
58+
}
59+
elseif ($version -match "^v?1\.2\.") {
60+
$targetFramework = "net10.0"
61+
$dotnetVersion = "10.0.x"
62+
Write-Host "Version 1.2.x detected - targeting .NET 10"
63+
}
4864
}
65+
else {
66+
# Determine framework based on branch name
67+
Write-Host "Branch: $branch"
68+
69+
if ($branch -eq "net8" -or $branch -eq "refs/heads/net8") {
70+
$targetFramework = "net8.0"
71+
$dotnetVersion = "8.0.x"
72+
Write-Host "net8 branch detected - targeting .NET 8"
73+
}
74+
elseif ($branch -eq "net9" -or $branch -eq "refs/heads/net9") {
75+
$targetFramework = "net9.0"
76+
$dotnetVersion = "9.0.101"
77+
Write-Host "net9 branch detected - targeting .NET 9"
78+
}
79+
elseif ($branch -eq "net10" -or $branch -eq "refs/heads/net10") {
80+
$targetFramework = "net10.0"
81+
$dotnetVersion = "10.0.x"
82+
Write-Host "net10 branch detected - targeting .NET 10"
83+
}
84+
}
85+
86+
Write-Host "Target Framework: $targetFramework"
87+
Write-Host "Dotnet Version: $dotnetVersion"
4988
50-
echo "version=$dotnetVersion" >> $env:GITHUB_OUTPUT
51-
echo "Detected branch: $branch -> .NET SDK: $dotnetVersion"
89+
"target_framework=$targetFramework" >> $env:GITHUB_OUTPUT
90+
"dotnet_version=$dotnetVersion" >> $env:GITHUB_OUTPUT
5291
53-
# Install the .NET SDK based on detected branch
92+
# Install the .NET SDK based on detected version
5493
- name: Setup .NET
5594
uses: actions/setup-dotnet@v4
5695
with:
57-
dotnet-version: ${{ steps.dotnet_version.outputs.version }}
96+
dotnet-version: ${{ steps.target_framework.outputs.dotnet_version }}
97+
98+
# Update TargetFramework in csproj
99+
- name: Update Target Framework
100+
run: |
101+
$csprojPath = "Compila.AspNetCore.Utils/Compila.AspNetCore.Utils.csproj"
102+
$targetFramework = "${{ steps.target_framework.outputs.target_framework }}"
103+
104+
Write-Host "Updating TargetFramework to $targetFramework in $csprojPath"
105+
106+
$content = Get-Content $csprojPath -Raw
107+
$content = $content -replace '<TargetFramework>net\d+\.\d+</TargetFramework>', "<TargetFramework>$targetFramework</TargetFramework>"
108+
Set-Content $csprojPath $content
109+
110+
Write-Host "Updated content:"
111+
Get-Content $csprojPath | Select-String "TargetFramework"
58112
59113
# Create the NuGet package in the folder from the environment variable NuGetDirectory
60114
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
@@ -71,28 +125,24 @@ jobs:
71125
runs-on: ubuntu-latest
72126
needs: [ create_nuget ]
73127
steps:
74-
# Detect .NET SDK version based on branch
75-
- name: Determine .NET SDK Version
76-
id: dotnet_version
77-
run: |
78-
$branch = "${{ github.ref_name }}"
79-
$dotnetVersion = "9.0.101"
80-
81-
if ($branch -eq "net8" -or $branch.StartsWith("net8-")) {
82-
$dotnetVersion = "8.0"
83-
} elseif ($branch -eq "net9" -or $branch.StartsWith("net9-")) {
84-
$dotnetVersion = "9.0.101"
85-
} elseif ($branch -eq "net10" -or $branch.StartsWith("net10-")) {
86-
$dotnetVersion = "10.0"
87-
}
128+
# Install multiple .NET SDK versions to support all target frameworks
129+
- name: Setup .NET 8
130+
uses: actions/setup-dotnet@v4
131+
with:
132+
dotnet-version: 8.0.x
133+
continue-on-error: true
88134

89-
echo "version=$dotnetVersion" >> $env:GITHUB_OUTPUT
135+
- name: Setup .NET 9
136+
uses: actions/setup-dotnet@v4
137+
with:
138+
dotnet-version: 9.0.x
139+
continue-on-error: true
90140

91-
# Install the .NET SDK based on detected branch
92-
- name: Setup .NET
141+
- name: Setup .NET 10
93142
uses: actions/setup-dotnet@v4
94143
with:
95-
dotnet-version: ${{ steps.dotnet_version.outputs.version }}
144+
dotnet-version: 10.0.x
145+
continue-on-error: true
96146

97147
# Download the NuGet package created in the previous job
98148
- uses: actions/download-artifact@v4
@@ -115,27 +165,25 @@ jobs:
115165
steps:
116166
- uses: actions/checkout@v4
117167

118-
# Detect .NET SDK version based on branch
119-
- name: Determine .NET SDK Version
120-
id: dotnet_version
121-
run: |
122-
$branch = "${{ github.ref_name }}"
123-
$dotnetVersion = "9.0.101"
124-
125-
if ($branch -eq "net8" -or $branch.StartsWith("net8-")) {
126-
$dotnetVersion = "8.0"
127-
} elseif ($branch -eq "net9" -or $branch.StartsWith("net9-")) {
128-
$dotnetVersion = "9.0.101"
129-
} elseif ($branch -eq "net10" -or $branch.StartsWith("net10-")) {
130-
$dotnetVersion = "10.0"
131-
}
168+
# Install multiple .NET SDK versions to support all target frameworks
169+
- name: Setup .NET 8
170+
uses: actions/setup-dotnet@v4
171+
with:
172+
dotnet-version: 8.0.x
173+
continue-on-error: true
132174

133-
echo "version=$dotnetVersion" >> $env:GITHUB_OUTPUT
175+
- name: Setup .NET 9
176+
uses: actions/setup-dotnet@v4
177+
with:
178+
dotnet-version: 9.0.x
179+
continue-on-error: true
134180

135-
- name: Setup .NET
181+
- name: Setup .NET 10
136182
uses: actions/setup-dotnet@v4
137183
with:
138-
dotnet-version: ${{ steps.dotnet_version.outputs.version }}
184+
dotnet-version: 10.0.x
185+
continue-on-error: true
186+
139187
- name: Run tests
140188
run: dotnet test --configuration Release
141189

@@ -153,65 +201,24 @@ jobs:
153201
name: nuget
154202
path: ${{ env.NuGetDirectory }}
155203

156-
# Validate version matches branch
157-
- name: Validate Version and Branch
158-
run: |
159-
$branch = "${{ github.ref_name }}"
160-
$releaseTag = "${{ github.event.release.tag_name }}"
161-
162-
# Extract version from tag (remove 'v' prefix if present)
163-
$version = $releaseTag -replace '^v', ''
164-
165-
Write-Host "Branch: $branch"
166-
Write-Host "Release tag: $releaseTag"
167-
Write-Host "Version: $version"
168-
169-
# Validate version format and branch consistency
170-
if ($branch -eq "net8" -or $branch.StartsWith("net8-")) {
171-
if ($version -notmatch '^1\.0\.') {
172-
Write-Error "ERROR: Branch 'net8' must use version 1.0.x, but got $version"
173-
exit 1
174-
}
175-
Write-Host "✓ Valid: net8 branch with version $version"
176-
} elseif ($branch -eq "net9" -or $branch.StartsWith("net9-")) {
177-
if ($version -notmatch '^1\.1\.') {
178-
Write-Error "ERROR: Branch 'net9' must use version 1.1.x, but got $version"
179-
exit 1
180-
}
181-
Write-Host "✓ Valid: net9 branch with version $version"
182-
} elseif ($branch -eq "net10" -or $branch.StartsWith("net10-")) {
183-
if ($version -notmatch '^1\.2\.') {
184-
Write-Error "ERROR: Branch 'net10' must use version 1.2.x, but got $version"
185-
exit 1
186-
}
187-
Write-Host "✓ Valid: net10 branch with version $version"
188-
} else {
189-
Write-Error "ERROR: Release must be created from net8, net9, or net10 branch"
190-
exit 1
191-
}
192-
193-
# Detect .NET SDK version based on branch
194-
- name: Determine .NET SDK Version
195-
id: dotnet_version
196-
run: |
197-
$branch = "${{ github.ref_name }}"
198-
$dotnetVersion = "9.0.101"
199-
200-
if ($branch -eq "net8" -or $branch.StartsWith("net8-")) {
201-
$dotnetVersion = "8.0"
202-
} elseif ($branch -eq "net9" -or $branch.StartsWith("net9-")) {
203-
$dotnetVersion = "9.0.101"
204-
} elseif ($branch -eq "net10" -or $branch.StartsWith("net10-")) {
205-
$dotnetVersion = "10.0"
206-
}
204+
# Install multiple .NET SDK versions to support all target frameworks
205+
- name: Setup .NET 8
206+
uses: actions/setup-dotnet@v4
207+
with:
208+
dotnet-version: 8.0.x
209+
continue-on-error: true
207210

208-
echo "version=$dotnetVersion" >> $env:GITHUB_OUTPUT
211+
- name: Setup .NET 9
212+
uses: actions/setup-dotnet@v4
213+
with:
214+
dotnet-version: 9.0.x
215+
continue-on-error: true
209216

210-
# Install the .NET SDK based on detected branch
211-
- name: Setup .NET Core
217+
- name: Setup .NET 10
212218
uses: actions/setup-dotnet@v4
213219
with:
214-
dotnet-version: ${{ steps.dotnet_version.outputs.version }}
220+
dotnet-version: 10.0.x
221+
continue-on-error: true
215222

216223
# Publish all NuGet packages to NuGet.org
217224
# Use --skip-duplicate to prevent errors if a package with the same version already exists.

0 commit comments

Comments
 (0)