Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 178 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,104 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
build-and-test:
name: Build & Test
standard-build:
name: Standard .NET Build & Test (Linux)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
lfs: true

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
9.0.x

- name: Generate Code
run: dotnet run --project CodeGen

- name: Build All Projects
run: |
echo "::group::Building all .NET projects..."
dotnet build UnitsNet.slnx --configuration Release
echo "::endgroup::"

- name: Run Tests (Linux-compatible)
run: |
echo "::group::Running tests..."
# Run tests only for frameworks that work on Linux
dotnet test UnitsNet.Tests/UnitsNet.Tests.csproj --configuration Release --no-build \
--collect:"XPlat Code Coverage" \
--logger:trx \
--results-directory "Artifacts/TestResults"

dotnet test UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj --configuration Release --no-build \
--collect:"XPlat Code Coverage" \
--logger:trx \
--results-directory "Artifacts/TestResults"

# For NumberExtensions, only test non-net48 frameworks
dotnet test UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj --configuration Release --no-build \
--framework net8.0 \
--collect:"XPlat Code Coverage" \
--logger:trx \
--results-directory "Artifacts/TestResults"

dotnet test UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj --configuration Release --no-build \
--framework net9.0 \
--collect:"XPlat Code Coverage" \
--logger:trx \
--results-directory "Artifacts/TestResults"
echo "::endgroup::"

- name: Pack Standard NuGets
run: |
echo "::group::Packing Standard NuGets..."
# These packages include all their target frameworks in one package
dotnet pack UnitsNet/UnitsNet.csproj --configuration Release --no-build --output Artifacts/NuGet
dotnet pack UnitsNet.NumberExtensions/UnitsNet.NumberExtensions.csproj --configuration Release --no-build --output Artifacts/NuGet
dotnet pack UnitsNet.Serialization.JsonNet/UnitsNet.Serialization.JsonNet.csproj --configuration Release --no-build --output Artifacts/NuGet
echo "::endgroup::"

- name: Upload Coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: Artifacts/TestResults/**/*.xml
flags: standard
name: standard-coverage

- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: standard-test-results
path: Artifacts/TestResults/*.trx
retention-days: 30

- name: Upload Standard NuGets
uses: actions/upload-artifact@v4
with:
name: standard-nugets
path: |
Artifacts/NuGet/*.nupkg
Artifacts/NuGet/*.snupkg
retention-days: 30

- name: Upload Standard Artifacts
uses: actions/upload-artifact@v4
with:
name: standard-artifacts
path: Artifacts/
retention-days: 30

windows-nano-net48-build:
name: Windows net48 Tests & NanoFramework Build
runs-on: windows-latest

steps:
Expand All @@ -32,78 +128,122 @@ jobs:
with:
dotnet-version: |
6.0.x
8.0.x
9.0.x

- name: Setup .NET nanoFramework build components
uses: nanoframework/nanobuild@v1
with:
workload: 'nanoFramework'

- name: Build, Test and Pack
- name: Generate Code
shell: pwsh
run: |
./Build/build.ps1 -IncludeNanoFramework
working-directory: ${{ github.workspace }}
run: dotnet run --project CodeGen

- name: Upload to codecov.io
- name: Build for net48 Tests
shell: pwsh
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
Write-Host -Foreground Green "Downloading codecov binaries..."
Write-Host "::group::Building projects with net48 targets..."
# Only NumberExtensions.Tests has net48 target
dotnet build UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj --configuration Release --framework net48
Write-Host "::endgroup::"

Invoke-WebRequest -Uri https://uploader.codecov.io/verification.gpg -OutFile codecov.asc
gpg.exe --import codecov.asc

Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe -Outfile codecov.exe
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe.SHA256SUM -Outfile codecov.exe.SHA256SUM
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/windows/codecov.exe.SHA256SUM.sig -Outfile codecov.exe.SHA256SUM.sig

gpg.exe --verify codecov.exe.SHA256SUM.sig codecov.exe.SHA256SUM
If ($(Compare-Object -ReferenceObject $(($(certUtil -hashfile codecov.exe SHA256)[1], "codecov.exe") -join " ") -DifferenceObject $(Get-Content codecov.exe.SHA256SUM)).length -eq 0) { echo "SHASUM verified" } Else {exit 1}

Write-Host -Foreground Green "Uploading to codecov..."
- name: Run net48 Tests
shell: pwsh
run: |
Write-Host "::group::Running net48 tests..."
dotnet test UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj --configuration Release --no-build `
--framework net48 `
--logger:trx `
--results-directory "Artifacts/TestResults"
Write-Host "::endgroup::"

- name: Build and Pack NanoFramework
shell: pwsh
run: |
Write-Host "::group::Building NanoFramework..."
# Initialize build tools
& "${{ github.workspace }}/Build/init.ps1"

.\codecov.exe --dir "Artifacts/Coverage" -t "$env:CODECOV_TOKEN" --build "${{ github.run_number }}"
# Import build functions
Remove-Module build-functions -ErrorAction SilentlyContinue
Import-Module "${{ github.workspace }}/Build/build-functions.psm1"

Write-Host -Foreground Green "✅ Uploaded to codecov."
# Build and pack NanoFramework
Start-BuildNanoFramework
Start-PackNugetsNanoFramework
Write-Host "::endgroup::"

- name: Upload Artifacts
- name: Upload net48 Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: artifacts
path: Artifacts/
name: net48-test-results
path: Artifacts/TestResults/*.trx
retention-days: 30

- name: Upload NuGet packages
- name: Upload NanoFramework NuGets
uses: actions/upload-artifact@v4
with:
name: nuget-packages
name: nano-nugets
path: |
Artifacts/**/*.nupkg
Artifacts/**/*.snupkg
Artifacts/NuGet/*.nupkg
Artifacts/NuGet/*.snupkg
retention-days: 30

- name: Upload Windows Artifacts
uses: actions/upload-artifact@v4
with:
name: windows-artifacts
path: Artifacts/
retention-days: 30

publish-nuget:
name: Publish to NuGet
needs: build-and-test
needs: [standard-build, windows-nano-net48-build]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.repository_owner == 'angularsen'
environment: Publish

steps:
- name: Download NuGet packages
- name: Download Standard NuGets
uses: actions/download-artifact@v4
with:
name: standard-nugets
path: nugets/standard

- name: Download Nano NuGets
uses: actions/download-artifact@v4
with:
name: nuget-packages
path: nugets
name: nano-nugets
path: nugets/nano

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Push to nuget.org
env:
NUGET_ORG_APIKEY: ${{ secrets.NUGET_ORG_APIKEY }}
run: |
echo "::group::Publishing all NuGets to nuget.org..."
dotnet nuget push "**/*.nupkg" --skip-duplicate --api-key $NUGET_ORG_APIKEY --source https://api.nuget.org/v3/index.json
echo "::endgroup::"
working-directory: nugets

check-status:
name: Check Build Status
needs: [standard-build, windows-nano-net48-build]
runs-on: ubuntu-latest
if: always()

steps:
- name: Check Status
run: |
dotnet nuget push "**/*.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_ORG_APIKEY }} --source https://api.nuget.org/v3/index.json
working-directory: nugets
if [[ "${{ needs.standard-build.result }}" != "success" ]] || [[ "${{ needs.windows-nano-net48-build.result }}" != "success" ]]; then
echo "❌ One or more builds failed"
echo "Standard Build: ${{ needs.standard-build.result }}"
echo "Windows/Nano/net48 Build: ${{ needs.windows-nano-net48-build.result }}"
exit 1
fi
echo "✅ All builds succeeded"
Loading
Loading