Skip to content

Commit 4d71349

Browse files
ci: reuse last merged PR notes on manual release
1 parent a91f82c commit 4d71349

1 file changed

Lines changed: 72 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ on:
55
types: [closed]
66
branches:
77
- main
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: "Release tag to build (e.g. v0.1.7)"
12+
required: false
13+
type: string
14+
version_number:
15+
description: "Version number for compilation (e.g. 0.1.7)"
16+
required: false
17+
type: string
18+
notes:
19+
description: "Release notes override"
20+
required: false
21+
type: string
822

923
permissions:
1024
contents: write
@@ -15,16 +29,55 @@ jobs:
1529
name: Prepare release (check files, version, notes)
1630
runs-on: ubuntu-latest
1731
outputs:
18-
should_release: ${{ steps.check_files.outputs.should_release }}
19-
version: ${{ steps.next_version.outputs.version }}
20-
version_number: ${{ steps.next_version.outputs.version_number }}
21-
notes: ${{ steps.parse_commit.outputs.notes }}
32+
should_release: ${{ steps.override.outputs.should_release || steps.check_files.outputs.should_release }}
33+
version: ${{ steps.override.outputs.version || steps.next_version.outputs.version }}
34+
version_number: ${{ steps.override.outputs.version_number || steps.next_version.outputs.version_number }}
35+
notes: ${{ steps.override.outputs.notes || steps.parse_commit.outputs.notes }}
2236
steps:
2337
- uses: actions/checkout@v4
2438
with:
2539
fetch-depth: 0
2640

41+
- name: Override outputs for manual runs
42+
if: github.event_name == 'workflow_dispatch'
43+
id: override
44+
shell: pwsh
45+
run: |
46+
Write-Output "should_release=true" >> $env:GITHUB_OUTPUT
47+
if (-not [string]::IsNullOrWhiteSpace("${{ inputs.version }}")) {
48+
Write-Output "version=${{ inputs.version }}" >> $env:GITHUB_OUTPUT
49+
}
50+
if (-not [string]::IsNullOrWhiteSpace("${{ inputs.version_number }}")) {
51+
Write-Output "version_number=${{ inputs.version_number }}" >> $env:GITHUB_OUTPUT
52+
}
53+
if (-not [string]::IsNullOrWhiteSpace("${{ inputs.notes }}")) {
54+
Write-Output "notes=${{ inputs.notes }}" >> $env:GITHUB_OUTPUT
55+
}
56+
57+
- name: Resolve last merged PR for manual runs
58+
if: github.event_name == 'workflow_dispatch'
59+
id: resolve_pr
60+
shell: pwsh
61+
env:
62+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
$repo = "${{ github.repository }}"
65+
$headers = @{"Authorization" = "token $env:GITHUB_TOKEN"; "Accept" = "application/vnd.github.v3+json"}
66+
$prs = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/pulls?state=closed&base=main&sort=updated&direction=desc&per_page=50" -Headers $headers -UseBasicParsing
67+
$merged = $prs | Where-Object { $_.merged_at -ne $null } | Select-Object -First 1
68+
if (-not $merged) {
69+
Write-Error "No merged PR found for base=main"
70+
exit 1
71+
}
72+
Write-Output "base_sha=$($merged.base.sha)" >> $env:GITHUB_OUTPUT
73+
Write-Output "head_sha=$($merged.head.sha)" >> $env:GITHUB_OUTPUT
74+
$body = $merged.body
75+
if ([string]::IsNullOrWhiteSpace($body)) { $body = "" }
76+
$body = $body -replace "`r?`n", " "
77+
Write-Output "merge_body=$body" >> $env:GITHUB_OUTPUT
78+
2779
- name: Check if source files changed
80+
if: github.event_name != 'workflow_dispatch'
2881
id: check_files
2982
shell: pwsh
3083
run: |
@@ -55,7 +108,7 @@ jobs:
55108
}
56109
57110
- name: Get latest release tag
58-
if: steps.check_files.outputs.should_release == 'true'
111+
if: github.event_name != 'workflow_dispatch' && steps.check_files.outputs.should_release == 'true'
59112
id: get_latest_tag
60113
shell: pwsh
61114
env:
@@ -120,7 +173,7 @@ jobs:
120173
}
121174
122175
- name: Determine next version
123-
if: steps.check_files.outputs.should_release == 'true'
176+
if: github.event_name != 'workflow_dispatch' && steps.check_files.outputs.should_release == 'true'
124177
id: next_version
125178
shell: pwsh
126179
run: |
@@ -142,21 +195,30 @@ jobs:
142195
}
143196
144197
- name: Parse commit message for release notes
145-
if: steps.check_files.outputs.should_release == 'true'
198+
if: (github.event_name == 'workflow_dispatch' && steps.override.outputs.should_release == 'true') || (github.event_name != 'workflow_dispatch' && steps.check_files.outputs.should_release == 'true')
146199
id: parse_commit
147200
shell: pwsh
148201
run: |
149202
Write-Output "DEBUG: Starting parse_commit"
150203
151204
# Get all commits from the PR (base to head)
152-
$baseSha = "${{ github.event.pull_request.base.sha }}"
153-
$headSha = "${{ github.event.pull_request.head.sha }}"
205+
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
206+
$baseSha = "${{ steps.resolve_pr.outputs.base_sha }}"
207+
$headSha = "${{ steps.resolve_pr.outputs.head_sha }}"
208+
} else {
209+
$baseSha = "${{ github.event.pull_request.base.sha }}"
210+
$headSha = "${{ github.event.pull_request.head.sha }}"
211+
}
154212
155213
Write-Output "DEBUG: Base SHA: $baseSha"
156214
Write-Output "DEBUG: Head SHA: $headSha"
157215
158216
# Get the merge commit (HEAD) message body for personal release notes
159-
$mergeCommitBody = git log -1 --pretty=format:"%b" HEAD
217+
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
218+
$mergeCommitBody = "${{ steps.resolve_pr.outputs.merge_body }}"
219+
} else {
220+
$mergeCommitBody = git log -1 --pretty=format:"%b" HEAD
221+
}
160222
Write-Output "DEBUG: Merge commit body: $mergeCommitBody"
161223
162224
# Get all commit messages in the PR

0 commit comments

Comments
 (0)