Skip to content

Commit 73c9f78

Browse files
author
rahul-infra
committed
fix: changes versionpreview.yaml
1 parent bfbed2c commit 73c9f78

File tree

1 file changed

+73
-36
lines changed

1 file changed

+73
-36
lines changed

.github/workflows/version-preview.yaml

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,95 @@ jobs:
1616
name: Preview Release
1717
runs-on: ubuntu-latest
1818
steps:
19-
- name: Checkout PR
19+
- name: Checkout
2020
uses: actions/checkout@v4
2121
with:
2222
fetch-depth: 0
23-
ref: refs/pull/${{ github.event.pull_request.number }}/merge
2423

25-
- name: Debug git info
24+
- name: Fetch base branch
25+
run: git fetch origin ${{ github.base_ref }}
26+
27+
- name: Analyze PR Commits
28+
id: analyze
2629
run: |
27-
echo "Current branch: $(git branch --show-current)"
28-
echo "Current commit: $(git rev-parse HEAD)"
29-
echo "Latest commits:"
30-
git log --oneline -10
31-
echo ""
32-
echo "Latest tag:"
33-
git describe --tags --abbrev=0
30+
echo "Analyzing commits in this PR..."
31+
32+
# Get commits only from this PR (not on base branch)
33+
PR_COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s")
34+
35+
echo "PR Commits:"
36+
echo "$PR_COMMITS"
3437
echo ""
35-
echo "Commits since last tag:"
36-
git log $(git describe --tags --abbrev=0)..HEAD --oneline
3738
38-
- name: Preview Next Version
39-
id: preview
40-
uses: cycjimmy/semantic-release-action@v2
41-
with:
42-
semantic_version: 18.0.0
43-
dry_run: true
44-
branches: |
45-
[
46-
'main',
47-
'master'
48-
]
49-
extra_plugins: |
50-
@semantic-release/changelog@6.0.0
51-
@semantic-release/git@10.0.0
52-
conventional-changelog-conventionalcommits@4.6.3
53-
env:
54-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
# Check for breaking changes
40+
if echo "$PR_COMMITS" | grep -qE "^(feat|fix|chore|docs|style|refactor|perf|test)(\(.+\))?!:|^BREAKING CHANGE:"; then
41+
RELEASE_TYPE="major"
42+
elif echo "$PR_COMMITS" | grep -qE "^feat(\(.+\))?:"; then
43+
RELEASE_TYPE="minor"
44+
elif echo "$PR_COMMITS" | grep -qE "^fix(\(.+\))?:"; then
45+
RELEASE_TYPE="patch"
46+
else
47+
RELEASE_TYPE="none"
48+
fi
49+
50+
echo "RELEASE_TYPE=$RELEASE_TYPE"
51+
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
52+
53+
# Get current version (latest tag overall, not just reachable from current commit)
54+
CURRENT_VERSION=$(git tag --sort=-v:refname | head -1 || echo "v0.0.0")
55+
CURRENT_VERSION=${CURRENT_VERSION#v}
56+
echo "Current version: v$CURRENT_VERSION"
57+
58+
# Calculate next version
59+
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
60+
61+
if [ "$RELEASE_TYPE" = "major" ]; then
62+
major=$((major + 1))
63+
minor=0
64+
patch=0
65+
elif [ "$RELEASE_TYPE" = "minor" ]; then
66+
minor=$((minor + 1))
67+
patch=0
68+
elif [ "$RELEASE_TYPE" = "patch" ]; then
69+
patch=$((patch + 1))
70+
fi
71+
72+
if [ "$RELEASE_TYPE" != "none" ]; then
73+
NEXT_VERSION="$major.$minor.$patch"
74+
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
75+
echo "will_release=true" >> $GITHUB_OUTPUT
76+
echo "Next version: $NEXT_VERSION"
77+
else
78+
echo "will_release=false" >> $GITHUB_OUTPUT
79+
echo "No release will be created"
80+
fi
81+
82+
# Generate release notes
83+
if [ "$RELEASE_TYPE" != "none" ]; then
84+
NOTES="## Changes in this PR\n\n"
85+
while IFS= read -r commit; do
86+
NOTES="${NOTES}- ${commit}\n"
87+
done <<< "$PR_COMMITS"
88+
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
89+
echo -e "$NOTES" >> $GITHUB_OUTPUT
90+
echo "EOF" >> $GITHUB_OUTPUT
91+
fi
5592
5693
- name: Comment PR
5794
uses: actions/github-script@v7
5895
with:
5996
script: |
60-
const published = '${{ steps.preview.outputs.new_release_published }}';
97+
const willRelease = '${{ steps.analyze.outputs.will_release }}';
6198
let body = '';
6299
63-
if (published === 'true') {
64-
const releaseType = '${{ steps.preview.outputs.new_release_type }}';
65-
const version = '${{ steps.preview.outputs.new_release_version }}';
66-
const notes = `${{ steps.preview.outputs.new_release_notes }}`;
100+
if (willRelease === 'true') {
101+
const releaseType = '${{ steps.analyze.outputs.release_type }}';
102+
const version = '${{ steps.analyze.outputs.next_version }}';
103+
const notes = `${{ steps.analyze.outputs.release_notes }}`;
67104
68-
body = `## Release Preview\n\n**Release Type:** \`${releaseType}\`\n**Next Version:** \`${version}\`\n\n### Release Notes\n${notes}`;
105+
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.*`;
69106
} else {
70-
body = '## Release Preview\n\nNo new release will be created from this PR.';
107+
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.';
71108
}
72109
73110
github.rest.issues.createComment({

0 commit comments

Comments
 (0)