|
| 1 | +name: PSParallelPipeline Workflow |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | + release: |
| 12 | + types: |
| 13 | + - published |
| 14 | + |
| 15 | +env: |
| 16 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 17 | + POWERSHELL_TELEMETRY_OPTOUT: 1 |
| 18 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 |
| 19 | + DOTNET_NOLOGO: true |
| 20 | + BUILD_CONFIGURATION: ${{ fromJSON('["Debug", "Release"]')[startsWith(github.ref, 'refs/tags/v')] }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + name: build |
| 25 | + runs-on: windows-latest |
| 26 | + steps: |
| 27 | + - name: Check out repository |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + - name: Build module - Debug |
| 31 | + shell: pwsh |
| 32 | + run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build |
| 33 | + if: ${{ env.BUILD_CONFIGURATION == 'Debug' }} |
| 34 | + |
| 35 | + - name: Build module - Publish |
| 36 | + shell: pwsh |
| 37 | + run: ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Build |
| 38 | + if: ${{ env.BUILD_CONFIGURATION == 'Release' }} |
| 39 | + |
| 40 | + - name: Capture PowerShell Module |
| 41 | + uses: actions/upload-artifact@v3 |
| 42 | + with: |
| 43 | + name: PSModule |
| 44 | + path: output/*.nupkg |
| 45 | + |
| 46 | + test: |
| 47 | + name: test |
| 48 | + needs: |
| 49 | + - build |
| 50 | + runs-on: ${{ matrix.info.os }} |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + info: |
| 55 | + - name: PS_5.1 |
| 56 | + psversion: '5.1' |
| 57 | + os: windows-latest |
| 58 | + - name: PS_7_Windows |
| 59 | + psversion: '7' |
| 60 | + os: windows-latest |
| 61 | + - name: PS_7_Linux |
| 62 | + psversion: '7' |
| 63 | + os: ubuntu-latest |
| 64 | + |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v3 |
| 67 | + |
| 68 | + - name: Restore Built PowerShell Module |
| 69 | + uses: actions/download-artifact@v3 |
| 70 | + with: |
| 71 | + name: PSModule |
| 72 | + path: output |
| 73 | + |
| 74 | + - name: Install Built PowerShell Module |
| 75 | + shell: pwsh |
| 76 | + run: | |
| 77 | + $manifestItem = Get-Item ([IO.Path]::Combine('Module', '*.psd1')) |
| 78 | + $moduleName = $manifestItem.BaseName |
| 79 | + $manifest = Test-ModuleManifest -Path $manifestItem.FullName -ErrorAction SilentlyContinue -WarningAction Ignore |
| 80 | +
|
| 81 | + $destPath = [IO.Path]::Combine('output', $moduleName, $manifest.Version) |
| 82 | + if (-not (Test-Path -LiteralPath $destPath)) { |
| 83 | + New-Item -Path $destPath -ItemType Directory | Out-Null |
| 84 | + } |
| 85 | +
|
| 86 | + Get-ChildItem output/*.nupkg | Rename-Item -NewName { $_.Name -replace '.nupkg', '.zip' } |
| 87 | +
|
| 88 | + Expand-Archive -Path output/*.zip -DestinationPath $destPath -Force -ErrorAction Stop |
| 89 | +
|
| 90 | + - name: Run Tests - Windows PowerShell |
| 91 | + if: ${{ matrix.info.psversion == '5.1' }} |
| 92 | + shell: pwsh |
| 93 | + run: | |
| 94 | + powershell.exe -NoProfile -File ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test |
| 95 | + exit $LASTEXITCODE |
| 96 | +
|
| 97 | + - name: Run Tests - PowerShell |
| 98 | + if: ${{ matrix.info.psversion != '5.1' }} |
| 99 | + shell: pwsh |
| 100 | + run: | |
| 101 | + pwsh -NoProfile -File ./build.ps1 -Configuration $env:BUILD_CONFIGURATION -Task Test |
| 102 | + exit $LASTEXITCODE |
| 103 | +
|
| 104 | + - name: Upload Test Results |
| 105 | + if: always() |
| 106 | + uses: actions/upload-artifact@v3 |
| 107 | + with: |
| 108 | + name: Unit Test Results (${{ matrix.info.name }}) |
| 109 | + path: ./output/TestResults/Pester.xml |
| 110 | + |
| 111 | + - name: Upload Coverage Results |
| 112 | + if: always() && !startsWith(github.ref, 'refs/tags/v') |
| 113 | + uses: actions/upload-artifact@v3 |
| 114 | + with: |
| 115 | + name: Coverage Results (${{ matrix.info.name }}) |
| 116 | + path: ./output/TestResults/Coverage.xml |
| 117 | + |
| 118 | + - name: Upload Coverage to codecov |
| 119 | + if: always() && !startsWith(github.ref, 'refs/tags/v') |
| 120 | + uses: codecov/codecov-action@v3 |
| 121 | + with: |
| 122 | + files: ./output/TestResults/Coverage.xml |
| 123 | + flags: ${{ matrix.info.name }} |
| 124 | + |
| 125 | + publish: |
| 126 | + name: publish |
| 127 | + if: startsWith(github.ref, 'refs/tags/v') |
| 128 | + needs: |
| 129 | + - build |
| 130 | + - test |
| 131 | + runs-on: windows-latest |
| 132 | + steps: |
| 133 | + - name: Restore Built PowerShell Module |
| 134 | + uses: actions/download-artifact@v3 |
| 135 | + with: |
| 136 | + name: PSModule |
| 137 | + path: ./ |
| 138 | + |
| 139 | + - name: Publish to Gallery |
| 140 | + if: github.event_name == 'release' |
| 141 | + shell: pwsh |
| 142 | + run: >- |
| 143 | + dotnet nuget push '*.nupkg' |
| 144 | + --api-key $env:PSGALLERY_TOKEN |
| 145 | + --source 'https://www.powershellgallery.com/api/v2/package' |
| 146 | + --no-symbols |
| 147 | + env: |
| 148 | + PSGALLERY_TOKEN: ${{ secrets.PSGALLERY_TOKEN }} |
0 commit comments