Skip to content
This repository was archived by the owner on Sep 11, 2026. It is now read-only.

Commit 3d2d03d

Browse files
feat(ci): Refactor release notes generation
This commit overhauls the `release.yml` workflow to improve how release notes are generated when a new version tag is pushed. The previous shell-based script, which relied on milestones and commit logs, has been replaced with a more robust `github-script` action. The new approach automatically identifies pull requests merged between the current and previous tags. **Key Changes:** * **Replaced manual scripting with `github-script`**: The `run` step for generating release notes is replaced by `actions/github-script@v7`. * **Automated PR detection**: The script now uses the GitHub API to compare commits between the new and previous tags. It extracts PR numbers from commit messages (both merge and squash commits) to build the release notes. * **Focus on PRs, not milestones**: The logic no longer depends on associating issues with a specific milestone. It instead lists the titles and authors of the merged pull requests. * **Updated action version**: The `softprops/action-gh-release` action is updated from `v1` to `v2`. * **Simplified output**: The new process produces a cleaner list of fixed issues and improvements based directly on merged PRs.
1 parent 18e843a commit 3d2d03d

1 file changed

Lines changed: 66 additions & 35 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 66 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,87 @@
1-
name: Android Release Notifier
1+
name: Create Release Notes
22

33
on:
44
push:
55
tags:
6-
- 'v*' # Triggers on any tag starting with 'v'
6+
- 'v*' # Triggers on any tag starting with 'v' (e.g., v1.6.7)
77

88
jobs:
99
build-release:
1010
runs-on: ubuntu-latest
1111
permissions:
1212
contents: write
13-
issues: read
1413
pull-requests: read
14+
issues: read
1515

1616
steps:
1717
- name: Checkout Code
1818
uses: actions/checkout@v4
1919
with:
20-
fetch-depth: 0 # Important: Fetch all history for tags and commits
20+
fetch-depth: 0 # Necessary to find the previous tag
2121

22-
- name: Generate Release Notes
23-
id: generate_notes
24-
env:
25-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26-
run: |
27-
# 1. Get current and previous tags
28-
CURRENT_TAG=${GITHUB_REF#refs/tags/}
29-
PREVIOUS_TAG=$(git describe --abbrev=0 --tags $CURRENT_TAG^ 2>/dev/null || echo "")
30-
31-
# 2. Extract version number for Milestone (e.g., v1.6.7 -> 1.6.7)
32-
MILESTONE_NAME=${CURRENT_TAG#v}
33-
34-
echo "## 🚀 Release $CURRENT_TAG" > release_body.md
35-
36-
# 3. Fetch Issues from Milestone
37-
echo -e "\n### 🛠 Issues Fixed in this Milestone ($MILESTONE_NAME)" >> release_body.md
38-
gh issue list --milestone "$MILESTONE_NAME" --state closed --json number,title,assignees --template \
39-
'{{range .}}* #{{.number}} {{.title}} (Fixed by: {{range .assignees}}{{.login}} {{else}}Unassigned{{end}}){{"\n"}}{{end}}' >> release_body.md
40-
41-
# 4. Fetch Commits since previous tag
42-
echo -e "\n### 📝 Commits" >> release_body.md
43-
if [ -z "$PREVIOUS_TAG" ]; then
44-
git log --pretty=format:"* %s (by %an)" >> release_body.md
45-
else
46-
git log ${PREVIOUS_TAG}..${CURRENT_TAG} --pretty=format:"* %s (by %an)" >> release_body.md
47-
fi
22+
- name: Generate Release Body
23+
id: generate_body
24+
uses: actions/github-script@v7
25+
with:
26+
script: |
27+
const { owner, repo } = context.repo;
28+
const currentTag = context.ref.replace('refs/tags/', '');
29+
30+
// 1. Get all tags to find the previous one
31+
const tags = execSync('git tag --sort=-v:refname').toString().split('\n').filter(t => t);
32+
const prevTag = tags[1]; // The tag before the one just pushed
33+
34+
console.log(`Comparing ${prevTag} to ${currentTag}`);
35+
36+
let body = `## 🚀 Release ${currentTag}\n\n`;
37+
38+
// 2. Get the list of commits between tags
39+
// We look for merged PRs which usually follow the "Merge pull request #XX" format
40+
const comparison = await github.rest.repos.compareCommits({
41+
owner,
42+
repo,
43+
base: prevTag,
44+
head: currentTag,
45+
});
46+
47+
const processedIssues = new Set();
48+
let issueList = "### Fixed Issues & Improvements\n";
49+
50+
for (const commit of comparison.data.commits) {
51+
// Extract PR number from merge commits or squash commits
52+
// Matches patterns like "(#123)" or "Merge pull request #123"
53+
const prMatch = commit.commit.message.match(/#(\d+)/);
54+
if (prMatch) {
55+
const prNumber = prMatch[1];
56+
57+
if (!processedIssues.has(prNumber)) {
58+
try {
59+
const { data: pr } = await github.rest.pulls.get({
60+
owner,
61+
repo,
62+
pull_number: prNumber,
63+
});
64+
65+
issueList += `* [#${pr.number}] ${pr.title} - **Fixed by @${pr.user.login}**\n`;
66+
processedIssues.add(prNumber);
67+
} catch (e) {
68+
console.log(`Could not fetch PR #${prNumber}: ${e.message}`);
69+
}
70+
}
71+
}
72+
}
73+
74+
if (processedIssues.size === 0) {
75+
issueList += "_No specific issues identified for this release._";
76+
}
77+
78+
core.setOutput('body', body + issueList);
4879
4980
- name: Create GitHub Release
50-
uses: softprops/action-gh-release@v1
81+
uses: softprops/action-gh-release@v2
5182
with:
52-
body_path: release_body.md
53-
tag_name: ${{ github.ref_name }}
54-
name: Release ${{ github.ref_name }}
83+
body: ${{ steps.generate_body.outputs.body }}
5584
draft: false
56-
prerelease: false
85+
prerelease: false
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)