Skip to content

Commit 201b0bd

Browse files
Merge pull request #5 from WarehouseFinds/feat/release_notes
Introduce Github release notes generation based on merged PRs
2 parents 4565ad0 + 1170d60 commit 201b0bd

6 files changed

Lines changed: 231 additions & 37 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build PowerShell Module
2+
description: Build module, generate help, and upload artifacts
3+
inputs:
4+
module-list:
5+
description: Comma-separated list of PowerShell modules to cache
6+
required: true
7+
release-type:
8+
description: Type of release (Release, Prerelease, Debug)
9+
default: Debug
10+
required: false
11+
outputs:
12+
build-version:
13+
description: Semantic build version
14+
value: ${{ steps.compute.outputs.build-version }}
15+
release-version:
16+
description: Release version from GitVersion
17+
value: ${{ steps.gitversion.outputs.majorMinorPatch }}
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Install GitVersion tool
22+
uses: gittools/actions/gitversion/setup@d0139503a9321f76b4a417dfdc8aebcec24decdd #v4.2.0
23+
with:
24+
versionSpec: '6.5.1'
25+
26+
- name: Get semantic build version
27+
id: gitversion
28+
uses: gittools/actions/gitversion/execute@d0139503a9321f76b4a417dfdc8aebcec24decdd #v4.2.0
29+
with:
30+
configFilePath: GitVersion.yml
31+
disableShallowCloneCheck: true
32+
33+
- name: Determine build version
34+
id: compute
35+
shell: pwsh
36+
run: |
37+
switch ('${{ inputs.release-type }}') {
38+
'Release' {
39+
$buildVersion = '${{ steps.gitversion.outputs.semVer }}'.Split('-', 2)[0]
40+
}
41+
'Prerelease' {
42+
$buildVersion = '${{ steps.gitversion.outputs.semVer }}'.Split('-', 2)[0] + '-Prerelease'
43+
}
44+
'Debug' {
45+
$buildVersion = '${{ steps.gitversion.outputs.semVer }}'
46+
}
47+
}
48+
echo "build-version=$buildVersion" >> $env:GITHUB_OUTPUT
49+
50+
- name: Setup PowerShell
51+
shell: pwsh
52+
run: |
53+
Install-PSResource -Name InvokeBuild -TrustRepository -AcceptLicense
54+
55+
- name: Build Module
56+
shell: pwsh
57+
run: |
58+
Invoke-Build -Task Build -SemanticVersion ${{ steps.gitversion.outputs.majorMinorPatch }} -Configuration Release
59+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Release PowerShell Module
2+
description: Create GitHub release and optionally publish to PSGallery
3+
inputs:
4+
release-type:
5+
description: Release type
6+
required: true
7+
release-version:
8+
description: Release version
9+
required: true
10+
publish-psgallery:
11+
description: Publish to PowerShell Gallery
12+
required: true
13+
secrets:
14+
PSGALLERY_API_KEY:
15+
description: API Key for PowerShell Gallery
16+
required: false
17+
runs:
18+
using: composite
19+
steps:
20+
- name: Generate release notes
21+
shell: pwsh
22+
id: generate_release_notes
23+
env:
24+
GITHUB_TOKEN: ${{ github.token }}
25+
run: |
26+
git fetch --tags
27+
$tags = @(git tag --sort=-v:refname)
28+
$previousTag = if ($tags.Count -gt 0) { $tags[0] } else { $null }
29+
$uri = "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes"
30+
$body = @{
31+
tag_name = "v${{ inputs.release-version }}"
32+
target_commitish = "main"
33+
}
34+
# Only include previous_tag_name if a previous tag exists
35+
if ($previousTag) {
36+
$body['previous_tag_name'] = $previousTag
37+
}
38+
$requestParams = @{
39+
Method = 'Post'
40+
Uri = $uri
41+
Headers = @{
42+
Authorization = "Bearer ${{ env.GITHUB_TOKEN }}"
43+
Accept = 'application/vnd.github+json'
44+
}
45+
Body = ($body | ConvertTo-Json -Depth 3)
46+
ContentType = 'application/json'
47+
}
48+
$result = Invoke-RestMethod @requestParams
49+
Write-Output 'releaseNotes<<EOF' >> $env:GITHUB_OUTPUT
50+
Write-Output ($result.body.ToString()) >> $env:GITHUB_OUTPUT
51+
Write-Output 'EOF' >> $env:GITHUB_OUTPUT
52+
53+
- name: Create release
54+
id: create_release
55+
uses: actions/create-release@v1
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
with:
59+
tag_name: v${{ inputs.release-version }}
60+
release_name: Release v${{ inputs.release-version }}
61+
body: ${{ steps.generate_release_notes.outputs.releaseNotes }}
62+
draft: false
63+
prerelease: ${{ inputs.release-type == 'Prerelease' }}
64+
65+
- name: Publish build package to PSGallery
66+
if: ${{ inputs.publish-psgallery == 'true' && env.PSGALLERY_API_KEY != '' }}
67+
shell: pwsh
68+
run: |
69+
Set-StrictMode -Version Latest
70+
[void] (Import-Module InvokeBuild)
71+
Invoke-Build -NugetApiKey ${{ env.PSGALLERY_API_KEY }} -Task Publish
72+
73+
- name: Publish build package to Github Release
74+
shell: pwsh
75+
run: |
76+
Set-StrictMode -Version Latest
77+
[void] (Import-Module InvokeBuild)
78+
Invoke-Build -Task Package
79+
80+
- name: Upload build package to Github Release
81+
uses: actions/upload-release-asset@v1
82+
with:
83+
upload_url: ${{ steps.create_release.outputs.upload_url }}
84+
asset_path: ./build/package/${{ github.event.repository.name }}.${{ inputs.release-version }}.nupkg
85+
asset_name: ${{ github.event.repository.name }}-v${{ inputs.release-version }}.nupkg
86+
asset_content_type: application/octet-stream
87+
env:
88+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
permissions:
9595
contents: write
9696
outputs:
97-
release-version: ${{ steps.gitversion.outputs.semVer }}
97+
release-version: ${{ steps.gitversion.outputs.majorMinorPatch }}
9898
steps:
9999
- name: Checkout repository
100100
uses: actions/checkout@v4

.github/workflows/cleanup.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Cleanup
2+
run-name: "${{ github.event.repository.name }} | Cleanup | ${{ github.run_id }} | ${{ github.event_name }}"
3+
on:
4+
schedule:
5+
# Every day at midnight
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
inputs:
9+
minimum-runs:
10+
description: 'Minimum number of recent workflow runs to retain'
11+
required: false
12+
type: number
13+
default: 2
14+
retain-days:
15+
description: 'Number of days to retain workflow runs'
16+
required: false
17+
type: number
18+
default: 5
19+
20+
jobs:
21+
cleanup-runs:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
actions: write
25+
contents: read
26+
steps:
27+
- name: Delete workflow runs
28+
uses: Mattraks/delete-workflow-runs@5bf9a1dac5c4d041c029f0a8370ddf0c5cb5aeb7 #v2.1
29+
with:
30+
token: ${{ github.token }}
31+
repository: ${{ github.repository }}
32+
keep_minimum_runs: ${{ github.event.inputs.minimum-runs || 5 }}
33+
check_pullrequest_exist: true
34+
retain_days: ${{ github.event.inputs.retain-days || 5 }}

.github/workflows/release.yml

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ run-name: "${{ github.event.repository.name }} | Release | ${{ github.run_id }}"
33
permissions: read-all
44

55
on:
6-
push:
7-
branches:
8-
- main
9-
paths:
10-
- 'src/**'
11-
- 'tests/**'
12-
- '*.sln'
13-
- '*.csproj'
14-
156
workflow_dispatch:
167
inputs:
17-
force-publish:
18-
description: 'Publish to PSGallery'
8+
release-type:
9+
description: 'Release type'
10+
required: true
11+
default: 'Release'
12+
type: choice
13+
options:
14+
- Release
15+
- Prerelease
16+
publish-psgallery:
17+
description: 'Publish release to PSGallery'
1918
required: false
20-
default: false
2119
type: boolean
20+
default: true
2221

2322
jobs:
2423
release:
@@ -61,30 +60,16 @@ jobs:
6160
run: |
6261
Invoke-Build -Task Build, Test -SemanticVersion ${{ steps.gitversion.outputs.majorMinorPatch }} -Configuration Release
6362
64-
- name: Create GitHub Release
65-
if: github.event_name == 'workflow_dispatch'
66-
uses: ncipollo/release-action@v1
63+
- name: Build Module
64+
id: build
65+
uses: ./.github/actions/ps-build
6766
with:
68-
tag: v${{ steps.gitversion.outputs.majorMinorPatch }}
69-
name: Release v${{ steps.gitversion.outputs.majorMinorPatch }}
70-
body: |
71-
## Changes in this Release
72-
- Version: ${{ steps.gitversion.outputs.majorMinorPatch }}
73-
- Commit: ${{ github.sha }}
74-
75-
See [CHANGELOG.md](CHANGELOG.md) for detailed changes.
76-
artifacts: "build/out/PSBinaryModule/**/*"
77-
draft: false
78-
prerelease: ${{ steps.gitversion.outputs.preReleaseLabel != '' }}
67+
release-type: ${{ inputs['release-type'] }}
7968

80-
- name: Publish to PowerShell Gallery
81-
if: (github.event_name == 'workflow_dispatch' || github.event.inputs.publish-psgallery == 'true')
82-
shell: pwsh
69+
- name: Release Module
70+
uses: ./.github/actions/ps-release
8371
env:
84-
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
85-
run: |
86-
if ([string]::IsNullOrEmpty($env:PSGALLERY_API_KEY)) {
87-
Write-Warning "PSGallery API key not found. Skipping publish."
88-
exit 0
89-
}
90-
Invoke-Build -Task Publish -NugetApiKey $env:PSGALLERY_API_KEY
72+
PSGALLERY_API_KEY: ${{ secrets.NUGETAPIKEY_PSGALLERY }}
73+
with:
74+
release-version: ${{ steps.build.outputs.release-version }}
75+
publish-psgallery: ${{ inputs.publish-psgallery }}

PSBinaryModule.build.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ task Build Compile, {
183183
Write-Build Green "Module built successfully at: $outputPath"
184184
}
185185

186+
# Synopsis: Create a NuGet package for the module
187+
task Package {
188+
$packageOutputPath = Join-Path -Path $buildPath -ChildPath 'package'
189+
if (!(Test-Path $packageOutputPath)) {
190+
[void] (New-Item -Path $packageOutputPath -ItemType Directory -Force)
191+
}
192+
193+
$requestParam = @{
194+
Name = "$($moduleName)_local_feed"
195+
SourceLocation = $packageOutputPath
196+
PublishLocation = $packageOutputPath
197+
InstallationPolicy = 'Trusted'
198+
ErrorAction = 'Stop'
199+
}
200+
[void] (Register-PSRepository @requestParam)
201+
202+
$requestParam = @{
203+
Path = (Join-Path -Path $buildPath -ChildPath "out/$moduleName")
204+
Repository = "$($moduleName)_local_feed"
205+
NuGetApiKey = 'ABC123'
206+
ErrorAction = 'Stop'
207+
}
208+
[void] (Publish-Module @requestParam)
209+
210+
[void] (Unregister-PSRepository -Name "$($moduleName)_local_feed")
211+
212+
}
213+
186214
# Synopsis: Publish the module to PSGallery
187215
task Publish -If ($NugetApiKey) {
188216
$requestParam = @{

0 commit comments

Comments
 (0)