Skip to content

Commit 2d1abfc

Browse files
author
rahul-infra
committed
refactor: simplify version preview using semantic-release action
1 parent ae276d0 commit 2d1abfc

File tree

1 file changed

+24
-88
lines changed

1 file changed

+24
-88
lines changed

.github/workflows/version-preview.yaml

Lines changed: 24 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -21,98 +21,34 @@ jobs:
2121
with:
2222
fetch-depth: 0
2323

24-
- name: Fetch base branch
25-
run: git fetch origin ${{ github.base_ref }}
26-
27-
- name: Analyze PR Commits
28-
id: analyze
29-
run: |
30-
# Get commits from this PR
31-
COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s")
32-
echo "Commits in this PR:"
33-
echo "$COMMITS"
34-
35-
# Determine release type
36-
if echo "$COMMITS" | grep -qE "^[a-z]+(\(.+\))?!:|BREAKING CHANGE:"; then
37-
TYPE="major"
38-
elif echo "$COMMITS" | grep -qE "^feat(\(.+\))?:"; then
39-
TYPE="minor"
40-
elif echo "$COMMITS" | grep -qE "^fix(\(.+\))?:"; then
41-
TYPE="patch"
42-
else
43-
TYPE="none"
44-
fi
45-
46-
echo "release_type=$TYPE" >> $GITHUB_OUTPUT
47-
echo "Release type: $TYPE"
48-
49-
# Calculate next version if releasing
50-
if [ "$TYPE" != "none" ]; then
51-
CURRENT=$(git tag --sort=-v:refname | head -1 | sed 's/^v//')
52-
IFS='.' read -r maj min pat <<< "$CURRENT"
53-
54-
[ "$TYPE" = "major" ] && maj=$((maj + 1)) && min=0 && pat=0
55-
[ "$TYPE" = "minor" ] && min=$((min + 1)) && pat=0
56-
[ "$TYPE" = "patch" ] && pat=$((pat + 1))
57-
58-
VERSION="$maj.$min.$pat"
59-
echo "next_version=$VERSION" >> $GITHUB_OUTPUT
60-
echo "will_release=true" >> $GITHUB_OUTPUT
61-
echo "Next version: v$VERSION"
62-
63-
# Generate notes
64-
{
65-
echo "release_notes<<EOF"
66-
echo "## Changes in this PR"
67-
echo ""
68-
echo "$COMMITS" | sed 's/^/- /'
69-
echo "EOF"
70-
} >> $GITHUB_OUTPUT
71-
else
72-
echo "will_release=false" >> $GITHUB_OUTPUT
73-
fi
24+
- name: Preview Release
25+
id: semantic
26+
uses: cycjimmy/semantic-release-action@v2
27+
with:
28+
semantic_version: 18.0.0
29+
dry_run: true
30+
extra_plugins: |
31+
@semantic-release/changelog@6.0.0
32+
@semantic-release/git@10.0.0
33+
conventional-changelog-conventionalcommits@4.6.3
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7436

7537
- name: Comment PR
76-
uses: actions/github-script@v7
38+
if: always()
39+
uses: marocchino/sticky-pull-request-comment@v2
7740
with:
78-
script: |
79-
const willRelease = '${{ steps.analyze.outputs.will_release }}';
80-
let body = '';
81-
82-
if (willRelease === 'true') {
83-
const releaseType = '${{ steps.analyze.outputs.release_type }}';
84-
const version = '${{ steps.analyze.outputs.next_version }}';
85-
const notes = `${{ steps.analyze.outputs.release_notes }}`;
41+
header: release-preview
42+
message: |
43+
## 📦 Release Preview
8644
87-
body = `## Release Preview\n\n**Release Type:** \`${releaseType}\`\n**Next Version:** \`v${version}\`\n\n### Release Notes\n${notes}\n\n---\n*This shows what release will be created when this PR is merged.*`;
88-
} else {
89-
body = '## Release Preview\n\nNo new release will be created from this PR.\n\nThis PR does not contain conventional commits that trigger a release.';
90-
}
45+
${{ steps.semantic.outputs.new_release_published == 'true' && format('**Release Type:** `{0}`
46+
**Next Version:** `v{1}`
9147
92-
// Find existing comment
93-
const comments = await github.rest.issues.listComments({
94-
owner: context.repo.owner,
95-
repo: context.repo.repo,
96-
issue_number: context.issue.number
97-
});
48+
### Release Notes
49+
{2}
9850
99-
const botComment = comments.data.find(comment =>
100-
comment.user.type === 'Bot' && comment.body.includes('## Release Preview')
101-
);
51+
---
52+
*This shows what release will be created when this PR is merged.*', steps.semantic.outputs.new_release_type, steps.semantic.outputs.new_release_version, steps.semantic.outputs.new_release_notes) || 'No new release will be created from this PR.
10253
103-
// Update existing or create new
104-
if (botComment) {
105-
await github.rest.issues.updateComment({
106-
owner: context.repo.owner,
107-
repo: context.repo.repo,
108-
comment_id: botComment.id,
109-
body: body
110-
});
111-
} else {
112-
await github.rest.issues.createComment({
113-
owner: context.repo.owner,
114-
repo: context.repo.repo,
115-
issue_number: context.issue.number,
116-
body: body
117-
});
118-
}
54+
This PR does not contain conventional commits that trigger a release.' }}

0 commit comments

Comments
 (0)