-
-
Notifications
You must be signed in to change notification settings - Fork 2
ci: add major/minor release heading in GitHub release notes #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Updated release notes extraction to prepend heading based on release type - π Major Release - β¨ Minor Release - Ensures GitHub release body includes contextual heading + changelog content
WalkthroughAdds a new GitHub Actions workflow to tag and create GitHub Releases after merges to main by comparing the new package.json version to the last tag, classifying the change (major/minor/patch), tagging and releasing for major/minor, and assembling release notes from CHANGELOG.md. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Merge to main
participant GH as GitHub Actions Runner
participant Repo as Repo (git)
participant Chg as CHANGELOG.md
participant GHRel as GitHub Releases
Dev->>GH: Trigger workflow (push to main)
GH->>Repo: actions/checkout (fetch-depth: 0)
GH->>Repo: Read package.json (version)
GH->>Repo: Get last tag (or v0.0.0)
GH->>GH: Compare versions (major/minor/patch)
alt Major or Minor
GH->>Repo: git tag v<version> & push
GH->>Chg: Extract notes for <version>
GH->>GHRel: Create Release (tag v<version>, name, body)
Note right of GHRel: Release published
else Patch
Note right of GH: Skip tagging and release
end
Estimated code review effortπ― 2 (Simple) | β±οΈ ~10 minutes Poem
Tip π Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. β¨ Finishing Touchesπ§ͺ Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
π§Ή Nitpick comments (2)
.github/workflows/tag-after-merge.yml (2)
31-50
: Constrain βminorβ detection to the same major.If the major ever regresses accidentally, the current logic could classify a βminorβ based solely on NEW_MINOR > OLD_MINOR. Add a guard that the majors match before considering it βminorβ.
Apply this diff:
if [ "$NEW_MAJOR" -gt "$OLD_MAJOR" ]; then echo "release_type=major" >> $GITHUB_ENV - elif [ "$NEW_MINOR" -gt "$OLD_MINOR" ]; then + elif [ "$NEW_MAJOR" -eq "$OLD_MAJOR" ] && [ "$NEW_MINOR" -gt "$OLD_MINOR" ]; then echo "release_type=minor" >> $GITHUB_ENV else echo "release_type=patch" >> $GITHUB_ENV fiOptional: If you expect pre-release versions (e.g., 1.2.3-beta.1), consider a semver-aware comparison to avoid βinteger expression expectedβ errors.
70-70
: Remove trailing whitespace to satisfy yamllint.Line 70 contains trailing spaces flagged by yamllint.
Apply this diff:
- +
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π‘ Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
π Files selected for processing (1)
.github/workflows/tag-after-merge.yml
(1 hunks)
π§° Additional context used
πͺ YAMLlint (1.37.1)
.github/workflows/tag-after-merge.yml
[error] 70-70: trailing spaces
(trailing-spaces)
π Additional comments (4)
.github/workflows/tag-after-merge.yml (4)
25-30
: Heads-up: last-tag resolution depends on tags being fetched.Once you enable
fetch-tags: true
in checkout (see prior comment), this step will behave correctly. Without it,git describe --tags --abbrev=0
may not find existing tags on the runner.Do you want me to wire a safeguard that falls back to the latest semver tag from
git tag --list 'v*'
ifgit describe
fails?
71-76
: Nice: clear contextual heading in the release body.Prepending "π Major Release" / "β¨ Minor Release" hits the PR goal and improves release readability.
20-24
: LGTM on version extraction.Using jq to read package.json version is simple and robust on ubuntu-latest.
81-89
: Release creation looks correct.softprops/action-gh-release@v2 with GITHUB_TOKEN and a multi-line body from env is a solid approach.
uses: actions/checkout@v5 | ||
with: | ||
fetch-depth: 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Fix checkout action version and fetch tags to enable tag discovery.
actions/checkout@v5
is not a valid published version today, and tags are not fetched by default. Without tags, git describe --tags
may return nothing even when tags exist, and the job will misclassify or skip releases.
Apply this diff:
- - name: Checkout code
- uses: actions/checkout@v5
- with:
- fetch-depth: 0
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ fetch-tags: true
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true |
π€ Prompt for AI Agents
In .github/workflows/tag-after-merge.yml around lines 16 to 19, the checkout
step uses an invalid action version and does not enable fetching tags; update
the uses to a published version (e.g., actions/checkout@v4) and add fetch-tags:
true alongside fetch-depth: 0 under the with block so the job fetches tags and
git describe --tags can discover them.
- name: Create and push git tag | ||
if: env.release_type != 'patch' | ||
run: | | ||
git config user.name "github-actions[bot]" | ||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
git tag v${{ env.version }} | ||
git push origin v${{ env.version }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Avoid failures when tag already exists; create annotated tags.
Re-runs or manual tags will cause git tag vX.Y.Z
to fail. Guard against existing tags and prefer annotated tags for better provenance.
Apply this diff:
- name: Create and push git tag
if: env.release_type != 'patch'
run: |
- git config user.name "github-actions[bot]"
- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- git tag v${{ env.version }}
- git push origin v${{ env.version }}
+ set -euo pipefail
+ git config user.name "github-actions[bot]"
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+ if git rev-parse -q --verify "refs/tags/v${{ env.version }}" >/dev/null; then
+ echo "Tag v${{ env.version }} already exists. Skipping tag creation."
+ else
+ git tag -a "v${{ env.version }}" -m "Release v${{ env.version }}"
+ git push origin "v${{ env.version }}"
+ fi
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- name: Create and push git tag | |
if: env.release_type != 'patch' | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git tag v${{ env.version }} | |
git push origin v${{ env.version }} | |
- name: Create and push git tag | |
if: env.release_type != 'patch' | |
run: | | |
set -euo pipefail | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
if git rev-parse -q --verify "refs/tags/v${{ env.version }}" >/dev/null; then | |
echo "Tag v${{ env.version }} already exists. Skipping tag creation." | |
else | |
git tag -a "v${{ env.version }}" -m "Release v${{ env.version }}" | |
git push origin "v${{ env.version }}" | |
fi |
π€ Prompt for AI Agents
In .github/workflows/tag-after-merge.yml around lines 56 to 63, the workflow
currently runs git tag v${{ env.version }} which fails if the tag already exists
and creates lightweight tags; change it to check for an existing tag and create
an annotated tag only when missing. Add a check like git rev-parse -q --verify
"refs/tags/v${{ env.version }}" and if it returns non-zero create an annotated
tag with git tag -a v${{ env.version }} -m "Release v${{ env.version }}" and
push that tag with git push origin v${{ env.version }}, otherwise skip tagging
(echo that tag exists) so re-runs do not fail.
# Match lines starting with "## vX.Y.Z " until the next "## " | ||
awk "/^## v${{ env.version }}[[:space:]]/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md > RELEASE_NOTES.md | ||
|
||
echo "notes<<EOF" >> $GITHUB_ENV | ||
if [ "${{ env.release_type }}" = "major" ]; then | ||
echo "## π Major Release" >> $GITHUB_ENV | ||
elif [ "${{ env.release_type }}" = "minor" ]; then | ||
echo "## β¨ Minor Release" >> $GITHUB_ENV | ||
fi | ||
echo "" >> $GITHUB_ENV | ||
cat RELEASE_NOTES.md >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Make changelog extraction robust and fail if notes are missing; also streamline env write.
The current AWK requires a space after the version (^## vX.Y.Z[[:space:]]
) and may miss headings like ## v1.2.3
or [v1.2.3] - 2025-08-19
. Also, we should fail fast if no section is found to avoid empty releases.
Apply this diff:
- name: Extract release notes from CHANGELOG
if: env.release_type != 'patch'
id: changelog
run: |
- # Match lines starting with "## vX.Y.Z " until the next "## "
- awk "/^## v${{ env.version }}[[:space:]]/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md > RELEASE_NOTES.md
-
- echo "notes<<EOF" >> $GITHUB_ENV
- if [ "${{ env.release_type }}" = "major" ]; then
- echo "## π Major Release" >> $GITHUB_ENV
- elif [ "${{ env.release_type }}" = "minor" ]; then
- echo "## β¨ Minor Release" >> $GITHUB_ENV
- fi
- echo "" >> $GITHUB_ENV
- cat RELEASE_NOTES.md >> $GITHUB_ENV
- echo "EOF" >> $GITHUB_ENV
+ # Extract lines from the "## vX.Y.Z" (or "[vX.Y.Z]") section until the next "##"
+ awk -v VER="v${{ env.version }}" '
+ $0 ~ "^##[[:space:]]*\\[?" VER "\\]?([[:space:]]|$)" {flag=1; next}
+ /^##[[:space:]]/ && flag {exit}
+ flag
+ ' CHANGELOG.md > RELEASE_NOTES.md
+
+ if [ ! -s RELEASE_NOTES.md ]; then
+ echo "No changelog section found for v${{ env.version }} in CHANGELOG.md"
+ exit 1
+ fi
+
+ {
+ echo "notes<<EOF"
+ if [ "${{ env.release_type }}" = "major" ]; then
+ echo "## π Major Release"
+ elif [ "${{ env.release_type }}" = "minor" ]; then
+ echo "## β¨ Minor Release"
+ fi
+ echo ""
+ cat RELEASE_NOTES.md
+ echo "EOF"
+ } >> "$GITHUB_ENV"
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
# Match lines starting with "## vX.Y.Z " until the next "## " | |
awk "/^## v${{ env.version }}[[:space:]]/{flag=1; next} /^## /{flag=0} flag" CHANGELOG.md > RELEASE_NOTES.md | |
echo "notes<<EOF" >> $GITHUB_ENV | |
if [ "${{ env.release_type }}" = "major" ]; then | |
echo "## π Major Release" >> $GITHUB_ENV | |
elif [ "${{ env.release_type }}" = "minor" ]; then | |
echo "## β¨ Minor Release" >> $GITHUB_ENV | |
fi | |
echo "" >> $GITHUB_ENV | |
cat RELEASE_NOTES.md >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Extract release notes from CHANGELOG | |
if: env.release_type != 'patch' | |
id: changelog | |
run: | | |
# Extract lines from the "## vX.Y.Z" (or "[vX.Y.Z]") section until the next "##" | |
awk -v VER="v${{ env.version }}" ' | |
$0 ~ "^##[[:space:]]*\\[?" VER "\\]?([[:space:]]|$)" {flag=1; next} | |
/^##[[:space:]]/ && flag {exit} | |
flag | |
' CHANGELOG.md > RELEASE_NOTES.md | |
if [ ! -s RELEASE_NOTES.md ]; then | |
echo "No changelog section found for v${{ env.version }} in CHANGELOG.md" | |
exit 1 | |
fi | |
{ | |
echo "notes<<EOF" | |
if [ "${{ env.release_type }}" = "major" ]; then | |
echo "## π Major Release" | |
elif [ "${{ env.release_type }}" = "minor" ]; then | |
echo "## β¨ Minor Release" | |
fi | |
echo "" | |
cat RELEASE_NOTES.md | |
echo "EOF" | |
} >> "$GITHUB_ENV" |
π§° Tools
πͺ YAMLlint (1.37.1)
[error] 70-70: trailing spaces
(trailing-spaces)
Summary by CodeRabbit