|
| 1 | +name: Test PowerShell on Ubuntu |
| 2 | +on: push |
| 3 | + |
| 4 | +jobs: |
| 5 | + pester-test: |
| 6 | + name: Pester test |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Check out repository code |
| 10 | + uses: actions/checkout@v5 |
| 11 | + - name: Perform a Pester test from the command-line |
| 12 | + shell: pwsh |
| 13 | + run: Test-Path resultsfile.log | Should -Be $true |
| 14 | + - name: Perform a Pester test from the Tests.ps1 file |
| 15 | + shell: pwsh |
| 16 | + run: | |
| 17 | + Invoke-Pester Unit.Tests.ps1 -Passthru |
| 18 | +
|
| 19 | +
|
| 20 | +jobs: |
| 21 | + install-dependencies: |
| 22 | + name: Install dependencies |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v5 |
| 26 | + - name: Install from PSGallery |
| 27 | + shell: pwsh |
| 28 | + run: | |
| 29 | + Set-PSRepository PSGallery -InstallationPolicy Trusted |
| 30 | + Install-Module SqlServer, PSScriptAnalyzer |
| 31 | +
|
| 32 | +
|
| 33 | +steps: |
| 34 | + - uses: actions/checkout@v5 |
| 35 | + - name: Setup PowerShell module cache |
| 36 | + id: cacher |
| 37 | + uses: actions/cache@v4 |
| 38 | + with: |
| 39 | + path: "~/.local/share/powershell/Modules" |
| 40 | + key: ${{ runner.os }}-SqlServer-PSScriptAnalyzer |
| 41 | + - name: Install required PowerShell modules |
| 42 | + if: steps.cacher.outputs.cache-hit != 'true' |
| 43 | + shell: pwsh |
| 44 | + run: | |
| 45 | + Set-PSRepository PSGallery -InstallationPolicy Trusted |
| 46 | + Install-Module SqlServer, PSScriptAnalyzer -ErrorAction Stop |
| 47 | +
|
| 48 | +
|
| 49 | +lint-with-PSScriptAnalyzer: |
| 50 | + name: Install and run PSScriptAnalyzer |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v5 |
| 54 | + - name: Install PSScriptAnalyzer module |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + Set-PSRepository PSGallery -InstallationPolicy Trusted |
| 58 | + Install-Module PSScriptAnalyzer -ErrorAction Stop |
| 59 | + - name: Lint with PSScriptAnalyzer |
| 60 | + shell: pwsh |
| 61 | + run: | |
| 62 | + Invoke-ScriptAnalyzer -Path *.ps1 -Recurse -Outvariable issues |
| 63 | + $errors = $issues.Where({$_.Severity -eq 'Error'}) |
| 64 | + $warnings = $issues.Where({$_.Severity -eq 'Warning'}) |
| 65 | + if ($errors) { |
| 66 | + Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop |
| 67 | + } else { |
| 68 | + Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total." |
| 69 | + } |
| 70 | +
|
| 71 | +name: Publish PowerShell Module |
| 72 | + |
| 73 | +on: |
| 74 | + release: |
| 75 | + types: [created] |
| 76 | + |
| 77 | +jobs: |
| 78 | + publish-to-gallery: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - uses: actions/checkout@v5 |
| 82 | + - name: Build and publish |
| 83 | + env: |
| 84 | + NUGET_KEY: ${{ secrets.NUGET_KEY }} |
| 85 | + shell: pwsh |
| 86 | + run: | |
| 87 | + ./build.ps1 -Path /tmp/samplemodule |
| 88 | + Publish-Module -Path /tmp/samplemodule -NuGetApiKey $env:NUGET_KEY -Verbose |
| 89 | +
|
| 90 | +
|
| 91 | +name: Upload artifact from Ubuntu |
| 92 | + |
| 93 | +on: [push] |
| 94 | + |
| 95 | +jobs: |
| 96 | + upload-pester-results: |
| 97 | + name: Run Pester and upload results |
| 98 | + runs-on: ubuntu-latest |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v5 |
| 101 | + - name: Test with Pester |
| 102 | + shell: pwsh |
| 103 | + run: Invoke-Pester Unit.Tests.ps1 -Passthru | Export-CliXml -Path Unit.Tests.xml |
| 104 | + - name: Upload test results |
| 105 | + uses: actions/upload-artifact@v4 |
| 106 | + with: |
| 107 | + name: ubuntu-Unit-Tests |
| 108 | + path: Unit.Tests.xml |
| 109 | + if: ${{ always() }} |
0 commit comments