Skip to content

Commit ddf4319

Browse files
committed
imporoved version for versioning system
1 parent daab6e8 commit ddf4319

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

.github/workflows/update-stable.yml

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@ jobs:
1010
update-stable:
1111
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'stable-release')
1212
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: read
1316

1417
steps:
1518
- uses: actions/checkout@v4
1619
with:
1720
fetch-depth: 0
21+
token: ${{ secrets.GITHUB_TOKEN }}
1822

1923
- name: Configure Git
2024
run: |
21-
git config --global user.name 'GitHub Action'
22-
git config --global user.email 'action@github.com'
25+
git config --global user.name 'github-actions[bot]'
26+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
2327
2428
- name: Setup Node.js
2529
uses: actions/setup-node@v4
2630
with:
2731
node-version: '20'
32+
cache: 'npm'
2833

2934
- name: Determine Version Bump
3035
id: version_bump
3136
run: |
32-
if contains(github.event.pull_request.labels.*.name, 'major')
37+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
3338
echo "bump=major" >> $GITHUB_OUTPUT
34-
elif contains(github.event.pull_request.labels.*.name, 'minor')
39+
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
3540
echo "bump=minor" >> $GITHUB_OUTPUT
3641
else
3742
echo "bump=patch" >> $GITHUB_OUTPUT
@@ -43,37 +48,43 @@ jobs:
4348
CURRENT_VERSION=$(node -p "require('./package.json').version")
4449
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
4550
51+
- name: Install semver
52+
run: npm install -g semver
53+
4654
- name: Bump Version
4755
id: bump_version
4856
run: |
49-
npm install -g semver
5057
NEW_VERSION=$(semver -i ${{ steps.version_bump.outputs.bump }} ${{ steps.current_version.outputs.version }})
5158
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
5259
5360
- name: Update Package.json
5461
run: |
5562
NEW_VERSION=${{ steps.bump_version.outputs.new_version }}
56-
npm version $NEW_VERSION --no-git-tag-version
63+
npm version $NEW_VERSION --no-git-tag-version --allow-same-version
5764
5865
- name: Generate Changelog
5966
id: changelog
6067
run: |
6168
# Get the latest tag
6269
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
6370
71+
# Start changelog file
72+
echo "# Release v${{ steps.bump_version.outputs.new_version }}" > changelog.md
73+
echo "" >> changelog.md
74+
6475
if [ -z "$LATEST_TAG" ]; then
65-
# If no tags exist, get all commits
6676
echo "### 🎉 First Release" >> changelog.md
6777
echo "" >> changelog.md
78+
COMPARE_BASE="$(git rev-list --max-parents=0 HEAD)"
6879
else
69-
# Get commits since last tag
7080
echo "### 🔄 Changes since $LATEST_TAG" >> changelog.md
7181
echo "" >> changelog.md
82+
COMPARE_BASE="$LATEST_TAG"
7283
fi
7384
7485
# Function to extract conventional commit type
7586
get_commit_type() {
76-
if [[ $1 =~ ^feat: ]]; then echo "✨ Features";
87+
if [[ $1 =~ ^feat:|^feature: ]]; then echo "✨ Features";
7788
elif [[ $1 =~ ^fix: ]]; then echo "🐛 Bug Fixes";
7889
elif [[ $1 =~ ^docs: ]]; then echo "📚 Documentation";
7990
elif [[ $1 =~ ^style: ]]; then echo "💎 Styles";
@@ -88,26 +99,28 @@ jobs:
8899
}
89100
90101
# Generate categorized changelog
91-
CATEGORIES=()
102+
declare -A CATEGORIES
92103
declare -A COMMITS_BY_CATEGORY
93104
94105
# Get commits since last tag or all commits if no tag exists
95-
if [ -z "$LATEST_TAG" ]; then
96-
git log --pretty=format:"%s" > temp_commits.txt
97-
else
98-
git log ${LATEST_TAG}..HEAD --pretty=format:"%s" > temp_commits.txt
99-
fi
100-
101-
while IFS= read -r commit; do
102-
CATEGORY=$(get_commit_type "$commit")
103-
if [[ ! " ${CATEGORIES[@]} " =~ " ${CATEGORY} " ]]; then
104-
CATEGORIES+=("$CATEGORY")
106+
while IFS= read -r commit_line; do
107+
HASH=$(echo "$commit_line" | cut -d'|' -f1)
108+
MSG=$(echo "$commit_line" | cut -d'|' -f2)
109+
PR_NUM=$(echo "$commit_line" | cut -d'|' -f3)
110+
111+
CATEGORY=$(get_commit_type "$MSG")
112+
CATEGORIES["$CATEGORY"]=1
113+
114+
# Format commit message with PR link if available
115+
if [ -n "$PR_NUM" ]; then
116+
COMMITS_BY_CATEGORY["$CATEGORY"]+="- ${MSG#*: } ([#$PR_NUM](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/pull/$PR_NUM))"$'\n'
117+
else
118+
COMMITS_BY_CATEGORY["$CATEGORY"]+="- ${MSG#*: }"$'\n'
105119
fi
106-
COMMITS_BY_CATEGORY["$CATEGORY"]+="- ${commit#*: }"$'\n'
107-
done < temp_commits.txt
120+
done < <(git log "${COMPARE_BASE}..HEAD" --pretty=format:"%H|%s|%(trailers:key=PR-Number,valueonly)" --reverse)
108121
109122
# Write categorized commits to changelog
110-
for category in "${CATEGORIES[@]}"; do
123+
for category in "✨ Features" "🐛 Bug Fixes" "📚 Documentation" "💎 Styles" "♻️ Code Refactoring" "⚡️ Performance Improvements" "✅ Tests" "🛠️ Build System" "⚙️ CI" "🔧 Chores" "🔍 Other Changes"; do
111124
if [ -n "${COMMITS_BY_CATEGORY[$category]}" ]; then
112125
echo "#### $category" >> changelog.md
113126
echo "" >> changelog.md
@@ -116,7 +129,10 @@ jobs:
116129
fi
117130
done
118131
119-
rm temp_commits.txt
132+
# Add compare link if not first release
133+
if [ -n "$LATEST_TAG" ]; then
134+
echo "**Full Changelog**: [\`$LATEST_TAG..v${{ steps.bump_version.outputs.new_version }}\`](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/$LATEST_TAG...v${{ steps.bump_version.outputs.new_version }})" >> changelog.md
135+
fi
120136
121137
# Save changelog content for the release
122138
CHANGELOG_CONTENT=$(cat changelog.md)
@@ -132,10 +148,11 @@ jobs:
132148
133149
- name: Update Stable Branch
134150
run: |
135-
git checkout stable
136-
git merge main
151+
# Ensure stable branch exists
152+
git checkout stable 2>/dev/null || git checkout -b stable
153+
git merge main --no-ff -m "chore: merge main into stable for version ${{ steps.bump_version.outputs.new_version }}"
137154
git push origin stable
138-
155+
139156
- name: Create and Push Tag
140157
run: |
141158
VERSION="v${{ steps.bump_version.outputs.new_version }}"
@@ -147,8 +164,7 @@ jobs:
147164
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148165
run: |
149166
VERSION="v${{ steps.bump_version.outputs.new_version }}"
150-
151-
# Create release with generated changelog
152167
gh release create "$VERSION" \
153168
--title "Release $VERSION" \
154-
--notes "${{ steps.changelog.outputs.content }}"
169+
--notes "${{ steps.changelog.outputs.content }}" \
170+
--target stable

0 commit comments

Comments
 (0)