Skip to content

Commit f1dad12

Browse files
committed
👶 Initial add of PSModule publishing workflow
1 parent 1aca14d commit f1dad12

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
"@

.github/workflows/ReadMe.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# GitHub Workflows
2+
Info about the GitHub Actions workflows here
3+
4+
## 📦 PublishPSModuleToGallery
5+
For publishing a PowerShell module to the corresponding PSResourceRepository. Has some logic to publish to dev/prod PSResourceRepo based on the triggering event, like a GitHub Release, or a direct workflow invocation.
6+
7+
GitHub Deployment Environment info for variables / secrets for this workflow:
8+
9+
### Variables
10+
11+
| Variable | Example Value | Description |
12+
| -------- | ------------- | ----------- |
13+
PSGALLERY_DISPLAYNAME | `PSGallery` | Value to use a display name of PSResource Repo that will be temporarily registered in the runner, and to which to publish the PowerShell module
14+
PSGALLERY_URI | https://www.powershellgallery.com/api/v2 | URI of target PS Resource repository to which to publish PowerShell module
15+
16+
### Secrets
17+
18+
| Secret | Example Value | Description |
19+
| ------ | ------------- | ----------- |
20+
PSGALLERY_APIKEY | `mysuperAPIKey-70821435-764a-4e6a-a397-9a48977be13b` | API key that provides write rights to the given PS Resource reposity (like myget.org or powershellgallery.com)

0 commit comments

Comments
 (0)