Skip to content

Commit c35c065

Browse files
feat: Add optimized CI/CD workflows with Nano/Standard separation
- Created separate Standard (Linux) and Nano (Windows) build targets - Standard builds include tests running on Linux for better performance - Build and test steps separated for better time measurements - Each target publishes NuGets immediately upon success - Added build.sh script for Linux/macOS builds - Created comprehensive migration guide Co-authored-by: Andreas Gullberg Larsen <[email protected]>
1 parent bde4d1a commit c35c065

File tree

4 files changed

+617
-0
lines changed

4 files changed

+617
-0
lines changed

.github/workflows/ci-optimized.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
name: CI Build (Optimized)
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- 'release/**'
8+
- 'maintenance/**'
9+
paths-ignore:
10+
- '**/*.png'
11+
- '**/*.md'
12+
workflow_dispatch:
13+
14+
env:
15+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
16+
DOTNET_CLI_TELEMETRY_OPTOUT: true
17+
18+
jobs:
19+
standard-build:
20+
name: Standard - Build & Test (Linux)
21+
runs-on: ubuntu-latest
22+
outputs:
23+
version: ${{ steps.version.outputs.version }}
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 1
30+
lfs: true
31+
32+
- name: Setup .NET SDK
33+
uses: actions/setup-dotnet@v4
34+
with:
35+
dotnet-version: |
36+
6.0.x
37+
8.0.x
38+
39+
- name: Get Version
40+
id: version
41+
run: |
42+
VERSION=$(grep -oP '(?<=<Version>)[^<]+' UnitsNet/UnitsNet.csproj | head -1)
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
45+
- name: Generate Code
46+
run: dotnet run --project CodeGen
47+
48+
- name: Build Projects
49+
run: |
50+
echo "::group::Building Standard projects..."
51+
dotnet build UnitsNet.slnx --configuration Release
52+
echo "::endgroup::"
53+
54+
- name: Run Tests
55+
run: |
56+
echo "::group::Running tests..."
57+
dotnet test UnitsNet.slnx --configuration Release --no-build \
58+
--collect:"XPlat Code Coverage" \
59+
--logger:trx \
60+
--results-directory "Artifacts/TestResults"
61+
echo "::endgroup::"
62+
63+
- name: Pack NuGets
64+
run: |
65+
echo "::group::Packing Standard NuGets..."
66+
dotnet pack UnitsNet.slnx --configuration Release --no-build \
67+
--output Artifacts/NuGet
68+
echo "::endgroup::"
69+
70+
- name: Upload Test Results
71+
uses: actions/upload-artifact@v4
72+
if: always()
73+
with:
74+
name: standard-test-results
75+
path: Artifacts/TestResults/*.trx
76+
retention-days: 30
77+
78+
- name: Upload Coverage
79+
uses: codecov/codecov-action@v4
80+
with:
81+
token: ${{ secrets.CODECOV_TOKEN }}
82+
files: Artifacts/TestResults/**/*.xml
83+
flags: standard
84+
name: standard-coverage
85+
86+
- name: Upload Standard NuGets
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: standard-nugets
90+
path: |
91+
Artifacts/NuGet/*.nupkg
92+
Artifacts/NuGet/*.snupkg
93+
retention-days: 30
94+
95+
- name: Publish Standard NuGets
96+
if: github.ref == 'refs/heads/master' && github.repository_owner == 'angularsen'
97+
run: |
98+
echo "::group::Publishing Standard NuGets to nuget.org..."
99+
dotnet nuget push "Artifacts/NuGet/*.nupkg" \
100+
--skip-duplicate \
101+
--api-key ${{ secrets.NUGET_ORG_APIKEY }} \
102+
--source https://api.nuget.org/v3/index.json
103+
echo "::endgroup::"
104+
105+
nano-build:
106+
name: Nano - Build (Windows)
107+
runs-on: windows-latest
108+
needs: [] # Run in parallel, no dependencies
109+
110+
steps:
111+
- name: Checkout
112+
uses: actions/checkout@v4
113+
with:
114+
fetch-depth: 1
115+
lfs: true
116+
117+
- name: Setup .NET SDK
118+
uses: actions/setup-dotnet@v4
119+
with:
120+
dotnet-version: |
121+
6.0.x
122+
8.0.x
123+
124+
- name: Setup .NET nanoFramework
125+
uses: nanoframework/nanobuild@v1
126+
with:
127+
workload: 'nanoFramework'
128+
129+
- name: Generate Code
130+
shell: pwsh
131+
run: dotnet run --project CodeGen
132+
133+
- name: Build Nano Projects
134+
shell: pwsh
135+
run: |
136+
Write-Host "::group::Building NanoFramework projects..."
137+
138+
# Build NanoFramework projects with MSBuild
139+
$msbuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
140+
-latest -requires Microsoft.Component.MSBuild `
141+
-find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1
142+
143+
if (-not $msbuildPath) {
144+
Write-Error "MSBuild not found. Ensure Visual Studio Build Tools are installed."
145+
exit 1
146+
}
147+
148+
& $msbuildPath UnitsNet.NanoFramework/UnitsNet.NanoFramework.nfproj `
149+
/p:Configuration=Release /p:Platform="Any CPU" /restore
150+
151+
& $msbuildPath UnitsNet.NumberExtensions.NanoFramework/UnitsNet.NumberExtensions.NanoFramework.nfproj `
152+
/p:Configuration=Release /p:Platform="Any CPU" /restore
153+
154+
Write-Host "::endgroup::"
155+
156+
- name: Pack Nano NuGets
157+
shell: pwsh
158+
run: |
159+
Write-Host "::group::Packing NanoFramework NuGets..."
160+
161+
$msbuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
162+
-latest -requires Microsoft.Component.MSBuild `
163+
-find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1
164+
165+
& $msbuildPath UnitsNet.NanoFramework/UnitsNet.NanoFramework.nfproj `
166+
/t:Pack /p:Configuration=Release /p:PackageOutputPath="$PWD\Artifacts\NuGet"
167+
168+
& $msbuildPath UnitsNet.NumberExtensions.NanoFramework/UnitsNet.NumberExtensions.NanoFramework.nfproj `
169+
/t:Pack /p:Configuration=Release /p:PackageOutputPath="$PWD\Artifacts\NuGet"
170+
171+
Write-Host "::endgroup::"
172+
173+
- name: Upload Nano NuGets
174+
uses: actions/upload-artifact@v4
175+
with:
176+
name: nano-nugets
177+
path: |
178+
Artifacts/NuGet/*.nupkg
179+
Artifacts/NuGet/*.snupkg
180+
retention-days: 30
181+
182+
- name: Publish Nano NuGets
183+
if: github.ref == 'refs/heads/master' && github.repository_owner == 'angularsen'
184+
shell: pwsh
185+
run: |
186+
Write-Host "::group::Publishing NanoFramework NuGets to nuget.org..."
187+
188+
dotnet nuget push "Artifacts\NuGet\*.nupkg" `
189+
--skip-duplicate `
190+
--api-key "${{ secrets.NUGET_ORG_APIKEY }}" `
191+
--source https://api.nuget.org/v3/index.json
192+
193+
Write-Host "::endgroup::"
194+
195+
check-status:
196+
name: Check Build Status
197+
needs: [standard-build, nano-build]
198+
runs-on: ubuntu-latest
199+
if: always()
200+
201+
steps:
202+
- name: Check Status
203+
run: |
204+
if [[ "${{ needs.standard-build.result }}" != "success" ]] || [[ "${{ needs.nano-build.result }}" != "success" ]]; then
205+
echo "❌ One or more builds failed"
206+
echo "Standard Build: ${{ needs.standard-build.result }}"
207+
echo "Nano Build: ${{ needs.nano-build.result }}"
208+
exit 1
209+
fi
210+
echo "✅ All builds succeeded"

.github/workflows/pr-optimized.yml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: PR Build (Optimized)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- 'release/**'
8+
- 'maintenance/**'
9+
paths-ignore:
10+
- '*.md'
11+
- '*.png'
12+
- '*.gitignore'
13+
14+
env:
15+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
16+
DOTNET_CLI_TELEMETRY_OPTOUT: true
17+
18+
jobs:
19+
standard-build:
20+
name: Standard - Build & Test (Linux)
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 1
28+
lfs: true
29+
30+
- name: Setup .NET SDK
31+
uses: actions/setup-dotnet@v4
32+
with:
33+
dotnet-version: |
34+
6.0.x
35+
8.0.x
36+
37+
- name: Generate Code
38+
run: dotnet run --project CodeGen
39+
40+
- name: Build Projects
41+
run: |
42+
echo "::group::Building Standard projects..."
43+
dotnet build UnitsNet.slnx --configuration Release
44+
echo "::endgroup::"
45+
46+
- name: Run Tests
47+
run: |
48+
echo "::group::Running tests..."
49+
dotnet test UnitsNet.slnx --configuration Release --no-build \
50+
--collect:"XPlat Code Coverage" \
51+
--logger:trx \
52+
--results-directory "Artifacts/TestResults"
53+
echo "::endgroup::"
54+
55+
- name: Upload Test Results
56+
uses: actions/upload-artifact@v4
57+
if: always()
58+
with:
59+
name: standard-test-results
60+
path: Artifacts/TestResults/*.trx
61+
retention-days: 7
62+
63+
- name: Publish Test Results
64+
uses: EnricoMi/publish-unit-test-result-action@v2
65+
if: always()
66+
with:
67+
files: |
68+
Artifacts/TestResults/*.trx
69+
check_name: Standard Test Results
70+
comment_mode: off
71+
72+
- name: Upload Coverage
73+
uses: codecov/codecov-action@v4
74+
with:
75+
token: ${{ secrets.CODECOV_TOKEN }}
76+
files: Artifacts/TestResults/**/*.xml
77+
flags: standard
78+
name: standard-coverage
79+
80+
- name: Upload Artifacts
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: standard-artifacts
84+
path: Artifacts/
85+
retention-days: 7
86+
87+
nano-build:
88+
name: Nano - Build (Windows)
89+
runs-on: windows-latest
90+
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
with:
95+
fetch-depth: 1
96+
lfs: true
97+
98+
- name: Setup .NET SDK
99+
uses: actions/setup-dotnet@v4
100+
with:
101+
dotnet-version: |
102+
6.0.x
103+
8.0.x
104+
105+
- name: Setup .NET nanoFramework
106+
uses: nanoframework/nanobuild@v1
107+
with:
108+
workload: 'nanoFramework'
109+
110+
- name: Generate Code
111+
shell: pwsh
112+
run: dotnet run --project CodeGen
113+
114+
- name: Build Nano Projects
115+
shell: pwsh
116+
run: |
117+
Write-Host "::group::Building NanoFramework projects..."
118+
119+
# Build NanoFramework projects with MSBuild
120+
$msbuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
121+
-latest -requires Microsoft.Component.MSBuild `
122+
-find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1
123+
124+
if (-not $msbuildPath) {
125+
Write-Error "MSBuild not found. Ensure Visual Studio Build Tools are installed."
126+
exit 1
127+
}
128+
129+
& $msbuildPath UnitsNet.NanoFramework/UnitsNet.NanoFramework.nfproj `
130+
/p:Configuration=Release /p:Platform="Any CPU" /restore
131+
132+
& $msbuildPath UnitsNet.NumberExtensions.NanoFramework/UnitsNet.NumberExtensions.NanoFramework.nfproj `
133+
/p:Configuration=Release /p:Platform="Any CPU" /restore
134+
135+
Write-Host "::endgroup::"
136+
137+
- name: Upload Nano Artifacts
138+
uses: actions/upload-artifact@v4
139+
with:
140+
name: nano-artifacts
141+
path: |
142+
UnitsNet.NanoFramework/bin/Release/**
143+
UnitsNet.NumberExtensions.NanoFramework/bin/Release/**
144+
retention-days: 7
145+
146+
pr-status:
147+
name: PR Build Status
148+
needs: [standard-build, nano-build]
149+
runs-on: ubuntu-latest
150+
if: always()
151+
152+
steps:
153+
- name: Check Status
154+
run: |
155+
echo "## Build Results"
156+
echo "Standard Build: ${{ needs.standard-build.result }}"
157+
echo "Nano Build: ${{ needs.nano-build.result }}"
158+
159+
if [[ "${{ needs.standard-build.result }}" != "success" ]] || [[ "${{ needs.nano-build.result }}" != "success" ]]; then
160+
echo "❌ PR builds failed"
161+
exit 1
162+
fi
163+
echo "✅ All PR builds succeeded"

0 commit comments

Comments
 (0)