Add version comparison support to Microsoft/OSInfo
#4598
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Rust | |
| on: | |
| push: | |
| branches: [ "main", "release/*" ] | |
| pull_request: | |
| branches: [ "main", "release/*" ] | |
| paths-ignore: | |
| - "docs/**" | |
| - "*.md" | |
| - ".vscode/*.json" | |
| - ".github/ISSUE_TEMPLATE/**" | |
| env: | |
| CARGO_TERM_COLOR: always | |
| defaults: | |
| run: | |
| shell: pwsh | |
| jobs: | |
| docs: | |
| strategy: | |
| matrix: | |
| platform: [ubuntu-latest, macos-latest, windows-latest] | |
| runs-on: ${{matrix.platform}} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Add WinGet links to PATH | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| "$env:LOCALAPPDATA\\Microsoft\\WinGet\\Links" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_PATH | |
| - name: Install prerequisites | |
| run: ./build.ps1 -SkipBuild -Clippy -Verbose | |
| - name: Generate documentation | |
| run: ./build.ps1 -RustDocs -Verbose | |
| - name: Test documentation | |
| run: |- | |
| $testParams = @{ | |
| SkipBuild = $true | |
| RustDocs = $true | |
| Test = $true | |
| ExcludeRustTests = $true | |
| ExcludePesterTests = $true | |
| Verbose = $true | |
| } | |
| ./build.ps1 @testParams | |
| linux-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install prerequisites | |
| run: ./build.ps1 -SkipBuild -Clippy -Verbose | |
| - name: Build and test with code coverage | |
| id: rust-tests | |
| continue-on-error: true | |
| run: ./build.ps1 -Clippy -Test -CodeCoverage -ExcludePesterTests -Verbose | |
| - name: Upload coverage data | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-coverage | |
| path: lcov.info | |
| if-no-files-found: ignore | |
| - name: Prepare build artifact | |
| if: always() | |
| run: tar -cvf bin.tar bin/ | |
| - name: Upload build artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-bin | |
| path: bin.tar | |
| - name: Fail if rust tests failed | |
| if: steps.rust-tests.outcome == 'failure' | |
| run: exit 1 | |
| linux-pester: | |
| needs: linux-build | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| group: [dsc, adapters, extensions, resources] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-bin | |
| - name: Expand build artifact | |
| run: tar -xvf bin.tar | |
| - name: Test ${{matrix.group}} | |
| run: |- | |
| $params = @{ | |
| SkipBuild = $true | |
| Test = $true | |
| ExcludeRustTests = $true | |
| Verbose = $true | |
| } | |
| ./build.ps1 @params -PesterTestGroup ${{matrix.group}} | |
| macos-build: | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install prerequisites | |
| run: ./build.ps1 -SkipBuild -Clippy -Verbose | |
| - name: Build and test with code coverage | |
| id: rust-tests | |
| continue-on-error: true | |
| run: ./build.ps1 -Clippy -Test -CodeCoverage -ExcludePesterTests -Verbose | |
| - name: Upload coverage data | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-coverage | |
| path: lcov.info | |
| if-no-files-found: ignore | |
| - name: Prepare build artifact | |
| if: always() | |
| run: tar -cvf bin.tar bin/ | |
| - name: Upload build artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-bin | |
| path: bin.tar | |
| - name: Fail if rust tests failed | |
| if: steps.rust-tests.outcome == 'failure' | |
| run: exit 1 | |
| macos-pester: | |
| needs: macos-build | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| group: [dsc, adapters, extensions, resources] | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-bin | |
| - name: Expand build artifact | |
| run: tar -xvf bin.tar | |
| - name: Test ${{matrix.group}} | |
| run: |- | |
| $params = @{ | |
| SkipBuild = $true | |
| Test = $true | |
| ExcludeRustTests = $true | |
| Verbose = $true | |
| } | |
| ./build.ps1 @params -PesterTestGroup ${{matrix.group}} | |
| # Windows | |
| windows-build: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Add WinGet links to PATH | |
| run: | | |
| "$env:LOCALAPPDATA\\Microsoft\\WinGet\\Links" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_PATH | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install prerequisites | |
| run: ./build.ps1 -SkipBuild -Clippy -Verbose | |
| - name: Build and test with code coverage | |
| id: rust-tests | |
| continue-on-error: true | |
| run: ./build.ps1 -Clippy -Test -CodeCoverage -ExcludePesterTests -Verbose | |
| - name: Upload coverage data | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-coverage | |
| path: lcov.info | |
| if-no-files-found: ignore | |
| - name: List bin folder files | |
| if: always() | |
| run: Get-ChildItem bin | |
| - name: Prepare build artifact | |
| if: always() | |
| run: tar -cvf bin.tar bin | |
| - name: Upload build artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-bin | |
| path: bin.tar | |
| - name: Fail if rust tests failed | |
| if: steps.rust-tests.outcome == 'failure' | |
| run: exit 1 | |
| windows-pester: | |
| needs: windows-build | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| group: [dsc, adapters, extensions, resources] | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-bin | |
| - name: Expand build artifact | |
| run: tar -xvf bin.tar | |
| - name: Test ${{matrix.group}} | |
| run: |- | |
| $params = @{ | |
| SkipBuild = $true | |
| Test = $true | |
| ExcludeRustTests = $true | |
| Verbose = $true | |
| } | |
| ./build.ps1 @params -PesterTestGroup ${{matrix.group}} | |
| coverage-report: | |
| if: github.event_name == 'pull_request' | |
| needs: [linux-build, macos-build, windows-build, linux-pester, macos-pester, windows-pester] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download coverage artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: '*-coverage' | |
| path: coverage-data | |
| - name: Consolidate coverage data | |
| id: coverage | |
| run: |- | |
| Import-Module ./helpers.build.psm1 -Force | |
| $baseSha = '${{ github.event.pull_request.base.sha }}' | |
| $headSha = '${{ github.event.pull_request.head.sha }}' | |
| # Determine if any Rust files changed from git diff | |
| $changedFiles = git diff --name-only --diff-filter=ACMR "$baseSha...$headSha" -- '*.rs' | Where-Object { $_ } | |
| if (-not $changedFiles) { | |
| "has_rust_changes=false" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| return | |
| } | |
| "has_rust_changes=true" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| # Find the first available lcov.info from the platform coverage artifacts | |
| $lcovFile = Get-ChildItem -Path 'coverage-data' -Filter 'lcov.info' -Recurse | Select-Object -First 1 | |
| if (-not $lcovFile) { | |
| Write-Warning 'No coverage data found from any platform.' | |
| "coverage_failed=true" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| return | |
| } | |
| "coverage_failed=false" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| $report = Get-CodeCoverageReport -LcovPath $lcovFile.FullName -BaseSha $baseSha -HeadSha $headSha -Verbose | |
| "percentage=$($report.Percentage)" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| "covered=$($report.CoveredLines)" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| "total=$($report.TotalLines)" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| "emoji=$($report.Emoji)" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| "label=$($report.Label)" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_OUTPUT | |
| - name: Post coverage comment | |
| if: >- | |
| steps.coverage.outputs.has_rust_changes == 'true' | |
| && steps.coverage.outputs.coverage_failed != 'true' | |
| && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| header: coverage-report | |
| message: | | |
| ## ${{ steps.coverage.outputs.emoji }} Code Coverage Report | |
| **Changed code coverage: ${{ steps.coverage.outputs.percentage }}%** (${{ steps.coverage.outputs.label }}) | |
| | Metric | Value | | |
| |--------|-------| | |
| | Changed lines analyzed | ${{ steps.coverage.outputs.total }} | | |
| | Lines covered by tests | ${{ steps.coverage.outputs.covered }} | | |
| | Coverage percentage | ${{ steps.coverage.outputs.percentage }}% | | |
| > Coverage is measured only on changed Rust code in this PR. | |
| - name: Post coverage comment (report failed) | |
| if: >- | |
| steps.coverage.outputs.has_rust_changes == 'true' | |
| && steps.coverage.outputs.coverage_failed == 'true' | |
| && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| header: coverage-report | |
| message: | | |
| ## :x: Code Coverage Report | |
| **Coverage report could not be generated.** The build or test run failed before | |
| producing coverage data. Check the workflow logs for details. | |
| - name: Post no-changes comment | |
| if: >- | |
| steps.coverage.outputs.has_rust_changes == 'false' | |
| && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: marocchino/sticky-pull-request-comment@v2 | |
| with: | |
| header: coverage-report | |
| message: | | |
| ## Code Coverage Report | |
| No Rust files were changed in this PR. Coverage analysis skipped. | |
| - name: Fail if coverage is below 70% | |
| if: >- | |
| steps.coverage.outputs.has_rust_changes == 'true' | |
| && steps.coverage.outputs.coverage_failed != 'true' | |
| && steps.coverage.outputs.percentage < 70 | |
| run: | | |
| Write-Error "Code coverage is ${{ steps.coverage.outputs.percentage }}%, which is below the 70% minimum threshold." | |
| exit 1 |