Skip to content

Commit c510d43

Browse files
authored
Merge pull request #1 from vNugglets/feat_PublishModule
🏗️ Add workflow for publishing PS module
2 parents 1aca14d + 3dd0641 commit c510d43

File tree

4 files changed

+116
-3
lines changed

4 files changed

+116
-3
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 -OutVariable oPSModuleInfo
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+
Add-Content -Path $env:GITHUB_OUTPUT -Encoding utf8 -Value "strModuleInfo_JSON=$($oPSModuleInfo | Select-Object -Property Name, Description, Author, @{n="VersionString"; e={$_.Version.ToString()}} | Convertto-Json -Compress)"
66+
}
67+
## throw the error if any, so future steps know outcome
68+
catch {throw $_}
69+
}
70+
71+
- name: 📝 Write summary of publishing
72+
if: always()
73+
run: |
74+
$strResultOfPublish = switch ('${{ steps.publish_ps_module.outcome }}') {
75+
"success" {"✅ Succeeded"}
76+
"failure" {"😡 Failed"}
77+
"cancelled" {"❌ Canceled"}
78+
"skipped" {"🦘 Skipped"}
79+
}
80+
$oPSModuleInfo_fromJson = @"
81+
${{ steps.publish_ps_module.outputs.strModuleInfo_JSON }}
82+
"@ | ConvertFrom-Json
83+
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Value (@'
84+
# Publish Summary
85+
| What | Value |
86+
|------|-------|
87+
Module Name | `{0}`
88+
Version | `{1}`
89+
Description | {2}
90+
Author | {3}
91+
Gallery URI | ${{ vars.PSGALLERY_URI }}
92+
Publishing Result | {4}
93+
'@ -f $oPSModuleInfo_fromJson.Name, $oPSModuleInfo_fromJson.VersionString, $oPSModuleInfo_fromJson.Description, $oPSModuleInfo_fromJson.Author, $strResultOfPublish)

.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)

Update-ThisModuleManifest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ begin {
3030
# NestedModules = Write-Output "${strModuleName}_functions.psm1"
3131
# PassThru = $true
3232
PowerShellVersion = [System.Version]"7.0"
33-
ProjectUri = "https://github.com/vNugglets/something"
33+
ProjectUri = "https://github.com/vNugglets/vNPSMod_AWSSSO"
3434
ReleaseNotes = "See release notes / ReadMe at the project URI"
3535
RootModule = "${strModuleName}_functions.psm1"
3636
# RequiredModules = "Some.Other.Module"

vN.AWSSSO/vN.AWSSSO.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Matt Boren, vNugglets
55
#
6-
# Generated on: 9/18/2025
6+
# Generated on: 10/2/2025
77
#
88

99
@{
@@ -104,7 +104,7 @@ PrivateData = @{
104104
# LicenseUri = ''
105105

106106
# A URL to the main website for this project.
107-
ProjectUri = 'https://github.com/vNugglets/something'
107+
ProjectUri = 'https://github.com/vNugglets/vNPSMod_AWSSSO'
108108

109109
# A URL to an icon representing this module.
110110
# IconUri = ''

0 commit comments

Comments
 (0)