Skip to content

Commit 79dc78f

Browse files
committed
Publish to GitHub releases in publish.yml
1 parent 973777a commit 79dc78f

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.github/workflows/publish.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
tags:
77
- 'v*'
88

9+
permissions:
10+
contents: write
11+
912
jobs:
1013
publish:
1114
runs-on: windows-latest
@@ -41,6 +44,7 @@ jobs:
4144
}
4245
4346
- name: Validate and Stage Release Notes
47+
id: module_meta
4448
shell: pwsh
4549
run: |
4650
$manifestPath = Resolve-Path -LiteralPath .\git-aliases-extra.psd1 |
@@ -54,6 +58,10 @@ jobs:
5458
}
5559
5660
Update-ModuleManifest -Path $manifestPath -ReleaseNotes $releaseNotes
61+
$releaseNotesPath = Join-Path $env:RUNNER_TEMP ("release-notes-{0}.md" -f $moduleVersion)
62+
Set-Content -LiteralPath $releaseNotesPath -Value $releaseNotes -Encoding utf8
63+
"module_version=$moduleVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
64+
"release_notes_path=$releaseNotesPath" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
5765
Write-Host "Release notes for version '$moduleVersion' loaded from CHANGELOG.md."
5866
5967
- name: Prepare Publish Layout
@@ -90,3 +98,12 @@ jobs:
9098
}
9199
92100
Publish-Module -Path $publishPath -Repository PSGallery -NuGetApiKey $env:PSGALLERY_API_KEY -ErrorAction Stop
101+
102+
- name: Create or Update GitHub Release
103+
if: startsWith(github.ref, 'refs/tags/v')
104+
uses: softprops/action-gh-release@v2
105+
with:
106+
tag_name: ${{ github.ref_name }}
107+
name: ${{ github.ref_name }}
108+
body_path: ${{ steps.module_meta.outputs.release_notes_path }}
109+
generate_release_notes: false

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,18 @@ Checks are skipped when:
282282
This repository includes:
283283

284284
- `.github/workflows/ci.yml` for lint + tests
285-
- `.github/workflows/publish.yml` for PSGallery publishing
285+
- `.github/workflows/publish.yml` for PSGallery publish + GitHub Release creation
286286

287287
To publish from CI:
288288

289289
1. Add repository secret `PSGALLERY_API_KEY`.
290290
2. Add release notes to `CHANGELOG.md` under `## [<ModuleVersion>] - YYYY-MM-DD`.
291291
3. Bump `ModuleVersion` in `git-aliases-extra.psd1`.
292-
4. Push a tag `v<ModuleVersion>` (for example, `v0.1.0`) or run the publish workflow manually.
292+
4. Push a tag `v<ModuleVersion>` (for example, `v0.1.1`) or run the publish workflow manually.
293+
294+
On tag push, the publish workflow does both:
295+
- publishes the module to PSGallery;
296+
- creates/updates GitHub Release for the same tag using notes from `CHANGELOG.md`.
293297

294298
## What CI checks
295299

tests/git-aliases-extra.Module.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ Describe 'git-aliases-extra tooling' {
7272
(Test-Path -LiteralPath (Join-Path $script:RepoRoot 'tools\prepare-publish.ps1')) | Should -BeTrue
7373
}
7474

75+
It 'publishes GitHub release from publish workflow' {
76+
$workflowPath = Join-Path $script:RepoRoot '.github\workflows\publish.yml'
77+
$workflowText = Get-Content -LiteralPath $workflowPath -Raw
78+
$workflowText | Should -Match 'Create or Update GitHub Release'
79+
$workflowText | Should -Match 'softprops/action-gh-release@v2'
80+
}
81+
7582
It 'resolves release notes from changelog for manifest version' {
7683
$manifest = Test-ModuleManifest -Path $script:ModuleManifest -ErrorAction Stop
7784
$version = $manifest.Version.ToString()

0 commit comments

Comments
 (0)