Skip to content

v0.1.0-test1

v0.1.0-test1 #1

Workflow file for this run

name: Publish PowerShell Module
on:
# This workflow only runs when a GitHub Release is *published*.
# Practical meaning:
# - Draft releases do NOT trigger this workflow.
# - Editing an existing release does NOT trigger this workflow.
# - Clicking "Publish release" in GitHub *does* trigger this workflow.
#
# Why we care:
# - A release is our "official" version marker.
# - The release tag (e.g., v1.2.3) becomes the PowerShell module version.
release:
types: [published]
jobs:
publish:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare module version
shell: pwsh
run: |
# The GitHub release tag is exposed as GITHUB_REF_NAME.
# If the tag is "v1.2.3", we trim the leading "v" to get "1.2.3".
# If the tag is "v1.2.3-preview1", we split it into:
# - ModuleVersion: 1.2.3
# - Prerelease: preview1
$manifestPath = Join-Path $PWD 'OneNoteAutomation/OneNoteAutomation.psd1'
$versionTag = $env:GITHUB_REF_NAME.TrimStart('v')
$versionParts = $versionTag -split '-', 2
$moduleVersion = $versionParts[0]
$prerelease = if ($versionParts.Count -gt 1) { $versionParts[1] } else { $null }
Write-Host "Setting module version to $moduleVersion"
# Update-ModuleManifest writes the version into the .psd1 *in the CI workspace*.
# This change is NOT committed back to the repo; it only exists for this run.
if ($prerelease) {
Write-Host "Setting prerelease label to $prerelease"
Update-ModuleManifest -Path $manifestPath -ModuleVersion $moduleVersion -Prerelease $prerelease
} else {
Update-ModuleManifest -Path $manifestPath -ModuleVersion $moduleVersion
}
- name: Stage README for PowerShell Gallery
shell: pwsh
run: |
# PowerShell Gallery displays README.md when it is present in the module root.
# Copy the repo README into the module folder so it is packaged and published.
Copy-Item -Path ./README.md -Destination ./OneNoteAutomation/README.md -Force
- name: Publish module to PowerShell Gallery
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
run: |
# The API key must be configured as a GitHub Actions secret:
# Settings → Secrets and variables → Actions → New repository secret.
# Without it, publishing will fail (by design).
if (-not $env:PSGALLERY_API_KEY) {
throw 'PSGALLERY_API_KEY secret is not set.'
}
# Publish-Module packages the module from the path and pushes it to PSGallery.
# The version used is the one we wrote into the manifest above.
Publish-Module -Path ./OneNoteAutomation -NuGetApiKey $env:PSGALLERY_API_KEY -Repository PSGallery