Skip to content

Commit 505f99b

Browse files
authored
Automate to prepare release note with next version (#508)
To create release notes, the following steps are necessary, but currently, they cannot be enforced: 1. Decide on a title. 2. Create a version following semver. 3. Revise the automatically generated release notes. This change automates the creation of a draft release, forcing the release creator to complete steps 1 and 2. The version is automatically determined with a `v` prefix by simply choosing from major/minor/patch. The title will be a combination of steps 1 and 2. About 3, drafted note shows actor name, so I believe almost all of us can realize we need to revise note.(but I know it's not perfect) ### When we run the workflow When the workflow is executed, a draft like the following will be created. ![スクリーンショット 2024-11-25 15 55 00](https://github.com/user-attachments/assets/adf62705-55da-4096-a8ac-2bb4bb158fc8) By revising this and making a release, it will result in the same as usual. ![スクリーンショット 2024-11-25 15 55 20](https://github.com/user-attachments/assets/1ba38c80-5bdc-4627-8957-a8e9a32ae3ec)
1 parent 9d8450c commit 505f99b

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Create Draft Release with Auto-Generated Notes
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: "Select the version type to increment (major, minor, patch)"
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
release_title:
15+
description: "Enter the title of the release"
16+
required: true
17+
type: string
18+
acknowledge_draft:
19+
description: "I understand that I must re-edit and finalize the draft release (Y/N)"
20+
required: true
21+
type: choice
22+
options:
23+
- "No"
24+
- "Yes"
25+
26+
jobs:
27+
validate-input:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Validate Acknowledgement
31+
if: ${{ github.event.inputs.acknowledge_draft != 'Yes' }}
32+
run: |
33+
echo "You must select 'Yes' to acknowledge your responsibility for finalizing the draft release."
34+
exit 1
35+
- name: Validate title (no empty)
36+
if: ${{ github.event.inputs.release_title == '' }}
37+
run: |
38+
echo "You must enter a title for the release."
39+
exit 1
40+
41+
create-draft-release:
42+
runs-on: ubuntu-latest
43+
needs: validate-input
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
- name: Fetch Latest Release
48+
id: get-latest-release
49+
uses: actions/github-script@v6
50+
with:
51+
script: |
52+
const latestRelease = await github.rest.repos.getLatestRelease({
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
}).catch(() => null);
56+
57+
if (latestRelease) {
58+
core.setOutput('latest_tag', latestRelease.data.tag_name);
59+
} else {
60+
core.setOutput('latest_tag', 'v0.0.0'); // Default for first release
61+
}
62+
63+
- name: Calculate New Version
64+
id: calculate-version
65+
uses: actions/github-script@v6
66+
with:
67+
script: |
68+
const latestTag = '${{ steps.get-latest-release.outputs.latest_tag }}';
69+
const versionType = '${{ github.event.inputs.version_type }}';
70+
71+
const [major, minor, patch] = latestTag.replace('v', '').split('.').map(Number);
72+
73+
let newVersion;
74+
if (versionType === 'major') {
75+
newVersion = `v${major + 1}.0.0`;
76+
} else if (versionType === 'minor') {
77+
newVersion = `v${major}.${minor + 1}.0`;
78+
} else {
79+
newVersion = `v${major}.${minor}.${patch + 1}`;
80+
}
81+
82+
core.setOutput('new_version', newVersion);
83+
84+
- name: Generate Release Notes
85+
id: generate-release-notes
86+
uses: actions/github-script@v6
87+
with:
88+
script: |
89+
const { data: releaseNotes } = await github.rest.repos.generateReleaseNotes({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
tag_name: "${{ steps.calculate-version.outputs.new_version }}"
93+
});
94+
95+
const actor = context.actor;
96+
const noteToAdd = `**@${actor} 👈 TODO: Write detailed release note for this version before release**\n`;
97+
98+
const footer = `---\nThis release is prepared by @${actor}`;
99+
100+
const modifiedBody = releaseNotes.body.replace(
101+
'## What\'s Changed',
102+
`## What's Changed\n\n${noteToAdd}`
103+
)
104+
.concat(`\n\n${footer}`);
105+
106+
console.log(`releaseNotes (modified): ${JSON.stringify(modifiedBody, null, 2)}`);
107+
core.setOutput("release_body", modifiedBody);
108+
109+
- name: Create Draft Release
110+
run: |
111+
gh release create "${{ steps.calculate-version.outputs.new_version }}" \
112+
--title "${{ steps.calculate-version.outputs.new_version }} ${{ github.event.inputs.release_title }}" \
113+
--notes "${{ steps.generate-release-notes.outputs.release_body }}" \
114+
--draft \
115+
--repo "${{ github.repository }}"
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)