@@ -12,58 +12,103 @@ jobs:
1212 permissions :
1313 contents : write
1414 packages : write
15+ id-token : write
1516
1617 steps :
1718 - name : Checkout
1819 uses : actions/checkout@v4
1920 with :
2021 fetch-depth : 0
2122
23+ - name : Validate tag format
24+ run : |
25+ if [[ ! $GITHUB_REF_NAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
26+ echo "❌ Invalid tag format: $GITHUB_REF_NAME"
27+ echo "Expected format: v{major}.{minor}.{patch} (e.g., v1.2.3)"
28+ exit 1
29+ fi
30+ echo "✅ Valid tag format: $GITHUB_REF_NAME"
31+
2232 - name : Setup Node.js
2333 uses : actions/setup-node@v4
2434 with :
25- node-version : ' 18 '
35+ node-version : ' 20 '
2636 registry-url : ' https://registry.npmjs.org'
37+ cache : ' npm'
2738
2839 - name : Install dependencies
2940 run : npm ci
3041
3142 - name : Run tests
3243 run : npm test
3344
34- - name : Build
45+ - name : Build project
3546 run : npm run build
3647
3748 - name : Extract version from tag
3849 id : version
39- run : echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
50+ run : |
51+ VERSION=${GITHUB_REF#refs/tags/v}
52+ echo "version=$VERSION" >> $GITHUB_OUTPUT
53+ echo "tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
54+
55+ - name : Verify package.json version matches tag
56+ run : |
57+ PACKAGE_VERSION=$(node -p "require('./package.json').version")
58+ TAG_VERSION="${{ steps.version.outputs.version }}"
59+ if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
60+ echo "❌ Version mismatch!"
61+ echo "package.json: $PACKAGE_VERSION"
62+ echo "Git tag: $TAG_VERSION"
63+ exit 1
64+ fi
65+ echo "✅ Version verified: $PACKAGE_VERSION"
4066
4167 - name : Generate changelog
4268 id : changelog
4369 run : |
44- # Extract changelog for current version
70+ VERSION="${{ steps. version.outputs.version }}"
4571 if [ -f "CHANGELOG.md" ]; then
46- # Get content between current version and previous version
47- awk '/^## \[${{ steps.version.outputs.version }}\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md > current_changelog.md
48- echo "changelog<<EOF" >> $GITHUB_OUTPUT
49- cat current_changelog.md >> $GITHUB_OUTPUT
50- echo "EOF" >> $GITHUB_OUTPUT
72+ # Extract changelog for current version
73+ awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md > current_changelog.md
74+ if [ -s current_changelog.md ]; then
75+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
76+ cat current_changelog.md >> $GITHUB_OUTPUT
77+ echo "EOF" >> $GITHUB_OUTPUT
78+ else
79+ echo "changelog=🚀 Release $VERSION" >> $GITHUB_OUTPUT
80+ fi
5181 else
52- echo "changelog=Release ${{ steps.version.outputs.version }} " >> $GITHUB_OUTPUT
82+ echo "changelog=🚀 Release $VERSION " >> $GITHUB_OUTPUT
5383 fi
5484
5585 - name : Create GitHub Release
56- uses : softprops/action-gh-release@v1
86+ uses : softprops/action-gh-release@v2
5787 with :
58- tag_name : ${{ github.ref_name }}
59- name : " 🚀 Release ${{ steps.version.outputs.version }}"
88+ tag_name : ${{ steps.version.outputs.tag }}
89+ name : " 🚀 Release v ${{ steps.version.outputs.version }}"
6090 body : ${{ steps.changelog.outputs.changelog }}
6191 draft : false
62- prerelease : false
92+ prerelease : ${{ contains(steps.version.outputs.version, '-') }}
93+ generate_release_notes : true
6394 env :
6495 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6596
6697 - name : Publish to NPM
67- run : npm publish
98+ run : |
99+ echo "📦 Publishing to NPM..."
100+ if [[ "${{ steps.version.outputs.version }}" == *"-"* ]]; then
101+ echo "🔄 Pre-release version detected, publishing with 'next' tag"
102+ npm publish --tag next
103+ else
104+ echo "✅ Stable version, publishing with 'latest' tag"
105+ npm publish
106+ fi
68107 env :
69- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
108+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
109+
110+ - name : Success notification
111+ run : |
112+ echo "🎉 Release completed successfully!"
113+ echo "📦 Package: https://www.npmjs.com/package/@253eosam/commit-from-branch"
114+ echo "🏷️ Release: https://github.com/$GITHUB_REPOSITORY/releases/tag/${{ steps.version.outputs.tag }}"
0 commit comments