|
| 1 | +name: Publish PowerShell Module |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - 'vN.AWSSSO/**' |
| 7 | + release: |
| 8 | + types: [released] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + GHDeploymentEnv: |
| 12 | + description: 'GH Deployment Environment to use for this workflow run' |
| 13 | + required: true |
| 14 | + default: 'Dev' |
| 15 | + type: choice |
| 16 | + options: |
| 17 | + - dev |
| 18 | + - bogus_for_failure_testing |
| 19 | + |
| 20 | +defaults: |
| 21 | + run: |
| 22 | + shell: pwsh |
| 23 | + |
| 24 | +jobs: |
| 25 | + publish-module: |
| 26 | + name: 🧾 Publish Module |
| 27 | + runs-on: ubuntu-latest |
| 28 | + ## if the event is a release, then the GHDeploymentEnv is prod, else if workflow_dispatch, then use the input, else dev |
| 29 | + environment: ${{ github.event_name == 'release' && 'prod' || (github.event_name == 'workflow_dispatch' && github.event.inputs.GHDeploymentEnv || 'dev') }} |
| 30 | + steps: |
| 31 | + - name: 🌿 Checkout repository (ref '${{ github.ref_name }}') |
| 32 | + uses: actions/checkout@v5 |
| 33 | + |
| 34 | + - name: Ensure given PS Gallery is registered ('${{ vars.PSGALLERY_URI }}') |
| 35 | + run: | |
| 36 | + if (-not ($oExistingPSResRepoRegistration = Get-PSResourceRepository -Name '${{ vars.PSGALLERY_DISPLAYNAME }}' -ErrorAction:SilentlyContinue)) { |
| 37 | + Write-Verbose -Verbose "PSResource Repository '${{ vars.PSGALLERY_DISPLAYNAME }}' (URL '${{ vars.PSGALLERY_URI }}') is not registered. Registering now" |
| 38 | + $hshParamForRegisterPSRepository = @{ |
| 39 | + Name = '${{ vars.PSGALLERY_DISPLAYNAME }}' |
| 40 | + URI = '${{ vars.PSGALLERY_URI }}' |
| 41 | + ErrorAction = "Stop" |
| 42 | + Verbose = $true |
| 43 | + } |
| 44 | + Register-PSResourceRepository @hshParamForRegisterPSRepository |
| 45 | + } |
| 46 | + else { |
| 47 | + Write-Verbose -Verbose "PSResource Repository '${{ vars.PSGALLERY_DISPLAYNAME }}' is already registered (URL '$($oExistingPSResRepoRegistration.Uri)'). Skipping registration." |
| 48 | + } |
| 49 | +
|
| 50 | + - name: 📦 Publish module to PSGallery |
| 51 | + id: publish_ps_module |
| 52 | + run: | |
| 53 | + Get-ChildItem -Path . -Recurse -Filter *.psd1 | ForEach-Object { |
| 54 | + Write-Verbose -Verbose "Found module manifest: '$($_.FullName)'" |
| 55 | + try { |
| 56 | + Test-ModuleManifest -Path $_.FullName -ErrorAction:Stop |
| 57 | + $hshParamForPublishPSResource = @{ |
| 58 | + ApiKey = '${{ secrets.PSGALLERY_APIKEY }}' |
| 59 | + Repository = '${{ vars.PSGALLERY_DISPLAYNAME }}' |
| 60 | + Path = $_.FullName |
| 61 | + ErrorAction = "Stop" |
| 62 | + Verbose = $true |
| 63 | + } |
| 64 | + Publish-PSResource @hshParamForPublishPSResource |
| 65 | + } |
| 66 | + ## throw the error if any, so future steps know outcome |
| 67 | + catch {throw $_} |
| 68 | + } |
| 69 | +
|
| 70 | + - name: 📝 Write summary of publishing |
| 71 | + if: always() |
| 72 | + run: | |
| 73 | + $strResultOfPublish = switch ('${{ steps.publish_ps_module.outcome }}') { |
| 74 | + "success" {"✅ Succeeded"} |
| 75 | + "failure" {"😡 Failed"} |
| 76 | + "cancelled" {"❌ Canceled"} |
| 77 | + "skipped" {"🦘 Skipped"} |
| 78 | + } |
| 79 | + Add-Content -Path $GITHUB_STEP_SUMMARY -Encoding utf8 -Value @" |
| 80 | + # Publish Summary |
| 81 | + | What | Value | |
| 82 | + |------|-------| |
| 83 | + Module | ${{ steps.get-module-version.outputs.module-name }} |
| 84 | + Version | ${{ steps.get-module-version.outputs.module-version }} |
| 85 | + Result | $strResultOfPublish |
| 86 | + "@ |
0 commit comments