Skip to content
Open
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
82 changes: 40 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,98 +7,96 @@ on:
- 'release/**'
- 'maintenance/**'
paths-ignore:
- '**/*.png'
- '**/*.md'
- '**/*.png'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
build-and-test:
name: Build & Test
runs-on: windows-latest
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
id-token: write

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

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

- name: Build, Test and Pack
shell: pwsh
run: |
./Build/build.ps1
working-directory: ${{ github.workspace }}

- name: Upload to codecov.io
- name: Build, test and pack
shell: pwsh
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
Write-Host -Foreground Green "Downloading codecov binaries..."

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}
run: ./Build/build.ps1

Write-Host -Foreground Green "Uploading to codecov..."

.\codecov.exe --dir "Artifacts/Coverage" -t "$env:CODECOV_TOKEN" --build "${{ github.run_number }}"

Write-Host -Foreground Green "✅ Uploaded to codecov."
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v6
with:
directory: Artifacts/Coverage
fail_ci_if_error: true
plugins: noop
use_oidc: true

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

- name: Upload NuGet packages
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: nuget-packages
path: |
Artifacts/**/*.nupkg
Artifacts/**/*.snupkg
if-no-files-found: error
retention-days: 30

publish-nuget:
name: Publish to NuGet
name: Publish NuGet packages
needs: build-and-test
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.ref == 'refs/heads/master' && github.repository_owner == 'angularsen'
environment: Publish

steps:
- name: Download NuGet packages
uses: actions/download-artifact@v4
uses: actions/download-artifact@v8
with:
name: nuget-packages
path: nugets

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

- name: Push to nuget.org
run: |
dotnet nuget push "**/*.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_ORG_APIKEY }} --source https://api.nuget.org/v3/index.json
working-directory: nugets
env:
NUGET_ORG_APIKEY: ${{ secrets.NUGET_ORG_APIKEY }}
run: dotnet nuget push "**/*.nupkg" --skip-duplicate --api-key "$NUGET_ORG_APIKEY" --source https://api.nuget.org/v3/index.json
working-directory: nugets
119 changes: 119 additions & 0 deletions .github/workflows/net48-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: .NET Framework 4.8 Compatibility

on:
# Remove `pull_request` for post-merge validation only, or remove `push` for PR validation only.
# Test and coverage behavior is identical for every enabled trigger.
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:

permissions:
contents: read
id-token: write

concurrency:
group: net48-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
test:
name: Test and coverage on CLR 4
runs-on: windows-latest
timeout-minutes: 45

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

- name: Setup .NET SDK
uses: actions/setup-dotnet@v6
with:
dotnet-version: 10.0.x

- name: Restore .NET tools
run: dotnet tool restore

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

- name: Run the complete test suite with coverage on .NET Framework 4.8
shell: pwsh
run: |
$testProjects = @(
'UnitsNet.Tests/UnitsNet.Tests.csproj',
'UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj',
'UnitsNet.NumberExtensions.CS14.Tests/UnitsNet.NumberExtensions.CS14.Tests.csproj',
'UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj'
)

New-Item -ItemType Directory -Force -Path Artifacts/Coverage | Out-Null

foreach ($testProject in $testProjects) {
$projectName = [IO.Path]::GetFileNameWithoutExtension($testProject)

dotnet dotcover test $testProject `
--configuration Release `
--framework net48 `
--logger trx `
--results-directory Artifacts/TestResults `
-p:ContinuousIntegrationBuild=true `
-p:IncludeNet48=true `
--dotCoverFilters="+:module=UnitsNet*;-:module=*Tests" `
--dotCoverOutput="Artifacts/Coverage/$projectName.coverage.xml" `
--dcReportType=DetailedXML

if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
}

- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: net48-test-results
path: Artifacts/TestResults/*.trx
if-no-files-found: ignore
retention-days: 30

# publish-net48-test-results.yml defines the "Publish .NET Framework 4.8 Test Results"
# workflow_run workflow that publishes these results with checks: write. Keeping that permission
# out of this workflow lets fork PRs execute contributor code with a read-only token.
- name: Upload workflow event
if: always()
uses: actions/upload-artifact@v7
with:
name: net48-event
path: ${{ github.event_path }}
retention-days: 30

- name: Upload coverage to Codecov
if: ${{ success() && hashFiles('Artifacts/Coverage/*.coverage.xml') != '' }}
uses: codecov/codecov-action@v6
with:
directory: Artifacts/Coverage
fail_ci_if_error: ${{ github.event_name != 'pull_request' }}
flags: net48
name: net48-clr4
plugins: noop
use_oidc: true

- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v7
with:
name: net48-coverage
path: Artifacts/Coverage/*.coverage.xml
if-no-files-found: ignore
retention-days: 30
81 changes: 37 additions & 44 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ on:
- 'release/**'
- 'maintenance/**'
paths-ignore:
- '*.md'
- '*.png'
- '*.gitignore'
- '**/*.gitignore'
- '**/*.md'
- '**/*.png'

concurrency:
group: pr-${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
Expand All @@ -18,71 +22,60 @@ env:
jobs:
build-and-test:
name: Build & Test
runs-on: windows-latest
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
checks: write
id-token: write

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

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

- name: Build, Test and Pack
- name: Build, test and pack
shell: pwsh
run: |
./Build/build.ps1
working-directory: ${{ github.workspace }}
run: ./Build/build.ps1

- name: Upload Test Results
uses: actions/upload-artifact@v4
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results
path: Artifacts/TestResults/*.trx
if-no-files-found: ignore
retention-days: 7

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/windows@v2
if: always()
- name: Publish test results
if: ${{ !cancelled() && github.event.pull_request.head.repo.full_name == github.repository && hashFiles('Artifacts/TestResults/*.trx') != '' }}
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: |
Artifacts/TestResults/*.trx
files: Artifacts/TestResults/*.trx
check_name: Test Results
comment_mode: off

- name: Upload to codecov.io
shell: pwsh
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
Write-Host -Foreground Green "Downloading codecov binaries..."

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..."

.\codecov.exe --dir "Artifacts/Coverage" -t "$env:CODECOV_TOKEN" --build "${{ github.run_number }}"

Write-Host -Foreground Green "✅ Uploaded to codecov."
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v6
with:
directory: Artifacts/Coverage
fail_ci_if_error: false
plugins: noop
use_oidc: true

- name: Upload Artifacts
uses: actions/upload-artifact@v4
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: artifacts
path: Artifacts/
retention-days: 7
retention-days: 7
Loading
Loading