Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/PublishPSModuleToGallery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Publish PowerShell Module

on:
push:
paths:
- 'vN.AWSSSO/**'
release:
types: [released]
workflow_dispatch:
inputs:
GHDeploymentEnv:
description: 'GH Deployment Environment to use for this workflow run'
required: true
default: 'Dev'
type: choice
options:
- Dev
- bogus_for_failure_testing

defaults:
run:
shell: pwsh

jobs:
publish-module:
name: 🧾 Publish Module
runs-on: ubuntu-latest
## if the event is a release, then the GHDeploymentEnv is prod, else if workflow_dispatch, then use the input, else dev
environment: ${{ github.event_name == 'release' && 'prod' || (github.event_name == 'workflow_dispatch' && github.event.inputs.GHDeploymentEnv || 'dev') }}
steps:
- name: 🌿 Checkout repository (ref '${{ github.ref_name }}')
uses: actions/checkout@v5

- name: Ensure given PS Gallery is registered ('${{ vars.PSGALLERY_URI }}')
run: |
if (-not ($oExistingPSResRepoRegistration = Get-PSResourceRepository -Name '${{ vars.PSGALLERY_DISPLAYNAME }}' -ErrorAction:SilentlyContinue)) {
Write-Verbose -Verbose "PSResource Repository '${{ vars.PSGALLERY_DISPLAYNAME }}' (URL '${{ vars.PSGALLERY_URI }}') is not registered. Registering now"
$hshParamForRegisterPSRepository = @{
Name = '${{ vars.PSGALLERY_DISPLAYNAME }}'
URI = '${{ vars.PSGALLERY_URI }}'
ErrorAction = "Stop"
Verbose = $true
}
Register-PSResourceRepository @hshParamForRegisterPSRepository
}
else {
Write-Verbose -Verbose "PSResource Repository '${{ vars.PSGALLERY_DISPLAYNAME }}' is already registered (URL '$($oExistingPSResRepoRegistration.Uri)'). Skipping registration."
}

- name: 📦 Publish module to PSGallery
id: publish_ps_module
run: |
Get-ChildItem -Path . -Recurse -Filter *.psd1 | ForEach-Object {
Write-Verbose -Verbose "Found module manifest: '$($_.FullName)'"
try {
Test-ModuleManifest -Path $_.FullName -ErrorAction:Stop -OutVariable oPSModuleInfo
$hshParamForPublishPSResource = @{
ApiKey = '${{ secrets.PSGALLERY_APIKEY }}'
Repository = '${{ vars.PSGALLERY_DISPLAYNAME }}'
Path = $_.FullName
ErrorAction = "Stop"
Verbose = $true
}
Publish-PSResource @hshParamForPublishPSResource
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)"
}
## throw the error if any, so future steps know outcome
catch {throw $_}
}

- name: 📝 Write summary of publishing
if: always()
run: |
$strResultOfPublish = switch ('${{ steps.publish_ps_module.outcome }}') {
"success" {"✅ Succeeded"}
"failure" {"😡 Failed"}
"cancelled" {"❌ Canceled"}
"skipped" {"🦘 Skipped"}
}
$oPSModuleInfo_fromJson = @"
${{ steps.publish_ps_module.outputs.strModuleInfo_JSON }}
"@ | ConvertFrom-Json
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Value (@'
# Publish Summary
| What | Value |
|------|-------|
Module Name | `{0}`
Version | `{1}`
Description | {2}
Author | {3}
Gallery URI | ${{ vars.PSGALLERY_URI }}
Publishing Result | {4}
'@ -f $oPSModuleInfo_fromJson.Name, $oPSModuleInfo_fromJson.VersionString, $oPSModuleInfo_fromJson.Description, $oPSModuleInfo_fromJson.Author, $strResultOfPublish)
20 changes: 20 additions & 0 deletions .github/workflows/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# GitHub Workflows
Info about the GitHub Actions workflows here

## 📦 PublishPSModuleToGallery
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.

GitHub Deployment Environment info for variables / secrets for this workflow:

### Variables

| Variable | Example Value | Description |
| -------- | ------------- | ----------- |
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
PSGALLERY_URI | https://www.powershellgallery.com/api/v2 | URI of target PS Resource repository to which to publish PowerShell module

### Secrets

| Secret | Example Value | Description |
| ------ | ------------- | ----------- |
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)
2 changes: 1 addition & 1 deletion Update-ThisModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ begin {
# NestedModules = Write-Output "${strModuleName}_functions.psm1"
# PassThru = $true
PowerShellVersion = [System.Version]"7.0"
ProjectUri = "https://github.com/vNugglets/something"
ProjectUri = "https://github.com/vNugglets/vNPSMod_AWSSSO"
ReleaseNotes = "See release notes / ReadMe at the project URI"
RootModule = "${strModuleName}_functions.psm1"
# RequiredModules = "Some.Other.Module"
Expand Down
4 changes: 2 additions & 2 deletions vN.AWSSSO/vN.AWSSSO.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Matt Boren, vNugglets
#
# Generated on: 9/18/2025
# Generated on: 10/2/2025
#

@{
Expand Down Expand Up @@ -104,7 +104,7 @@ PrivateData = @{
# LicenseUri = ''

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

# A URL to an icon representing this module.
# IconUri = ''
Expand Down