|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: PSScriptAnalyzer Lint |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Cache PowerShell modules |
| 21 | + uses: actions/cache@v4 |
| 22 | + with: |
| 23 | + path: ~/.local/share/powershell/Modules |
| 24 | + key: ${{ runner.os }}-psmodules-lint-${{ hashFiles('build.depend.psd1') }} |
| 25 | + restore-keys: | |
| 26 | + ${{ runner.os }}-psmodules-lint- |
| 27 | +
|
| 28 | + - name: Install PSScriptAnalyzer |
| 29 | + shell: pwsh |
| 30 | + run: | |
| 31 | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted |
| 32 | + Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser |
| 33 | +
|
| 34 | + - name: Run PSScriptAnalyzer |
| 35 | + shell: pwsh |
| 36 | + run: | |
| 37 | + $results = Invoke-ScriptAnalyzer -Path ./{{ModuleName}} -Recurse -Settings PSGallery -ReportSummary |
| 38 | + $errors = $results | Where-Object { $_.Severity -eq 'Error' } |
| 39 | +
|
| 40 | + if ($results) { |
| 41 | + Write-Host "::group::PSScriptAnalyzer Results" |
| 42 | + $results | Format-Table -AutoSize |
| 43 | + Write-Host "::endgroup::" |
| 44 | + } |
| 45 | +
|
| 46 | + if ($errors) { |
| 47 | + Write-Host "::error::PSScriptAnalyzer found $($errors.Count) error(s)" |
| 48 | + exit 1 |
| 49 | + } |
| 50 | +
|
| 51 | + Write-Host "PSScriptAnalyzer passed with no errors" |
| 52 | +
|
| 53 | + unit-tests: |
| 54 | + name: Unit Tests (${{ matrix.os }}) |
| 55 | + runs-on: ${{ matrix.os }} |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: |
| 59 | + os: [ubuntu-latest, windows-latest, macOS-latest] |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Cache PowerShell modules |
| 64 | + uses: actions/cache@v4 |
| 65 | + with: |
| 66 | + path: | |
| 67 | + ~/Documents/PowerShell/Modules |
| 68 | + ~/.local/share/powershell/Modules |
| 69 | + key: ${{ runner.os }}-psmodules-${{ hashFiles('build.depend.psd1') }} |
| 70 | + restore-keys: | |
| 71 | + ${{ runner.os }}-psmodules- |
| 72 | +
|
| 73 | + - name: Build and Test |
| 74 | + shell: pwsh |
| 75 | + run: | |
| 76 | + New-Item -Path out -ItemType Directory -Force | Out-Null |
| 77 | + ./build.ps1 -Task Build,Test -Bootstrap |
| 78 | +
|
| 79 | + - name: Upload Coverage to Codecov |
| 80 | + uses: codecov/codecov-action@v5 |
| 81 | + if: success() |
| 82 | + with: |
| 83 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 84 | + files: out/codeCoverage.xml |
| 85 | + flags: ${{ matrix.os }} |
| 86 | + fail_ci_if_error: false |
| 87 | + |
| 88 | + - name: Upload Test Results |
| 89 | + uses: actions/upload-artifact@v4 |
| 90 | + if: always() |
| 91 | + with: |
| 92 | + name: test-results-${{ matrix.os }} |
| 93 | + path: out/ |
| 94 | + retention-days: 30 |
0 commit comments