Skip to content

Commit 3c00ceb

Browse files
sungjun-lee2claude
andcommitted
refactor: unify workflows and improve branch strategy
- Remove duplicate publish.yml workflow - Enhance release.yml with better validation and error handling - Delete develop branch and use main-only strategy - Improve logging messages with context information - Add pre-release support for NPM publishing - Add version verification and tag format validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4501deb commit 3c00ceb

File tree

3 files changed

+72
-92
lines changed

3 files changed

+72
-92
lines changed

.github/workflows/publish.yml

Lines changed: 0 additions & 67 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }}"

src/core.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ const applyValidationRules = (state: ProcessingState): ProcessingState => {
174174

175175
for (const rule of validationRules) {
176176
if (!rule.check(state)) {
177-
log(`exit: ${rule.reason}`, rule.name);
177+
const contextInfo = state.ticket || state.branch || 'unknown';
178+
log(`exit: ${rule.reason}`, `[${rule.name}]`, `context: ${contextInfo}`);
178179
return { ...state, shouldSkip: true, skipReason: rule.reason };
179180
}
180181
}
@@ -185,10 +186,10 @@ const logProcessingInfo = (state: ProcessingState): ProcessingState => {
185186
const log = createLogger(state.debug);
186187
const hasMsgToken = /\$\{msg\}|\$\{body\}/.test(state.template);
187188

188-
log('branch', state.branch, 'ticket', state.ticket || '(none)');
189-
log('tpl', state.template);
190-
log('rendered', state.renderedMessage);
191-
log('mode', hasMsgToken ? 'replace-line' : 'prefix-only');
189+
log('branch', `${state.branch}`, 'ticket', `${state.ticket || '(none)'}`, 'segs', `[${state.context.segs.join(', ')}]`);
190+
log('tpl', `"${state.template}"`);
191+
log('rendered', `"${state.renderedMessage}"`);
192+
log('mode', hasMsgToken ? 'replace-line' : 'prefix-only', `msg: "${state.originalMessage}"`);
192193

193194
return state;
194195
};
@@ -211,20 +212,21 @@ const writeResult = (state: ProcessingState): ProcessingState => {
211212
const log = createLogger(state.debug);
212213

213214
if (state.shouldSkip) {
214-
log(`skip: ${state.skipReason}`);
215+
const contextInfo = state.ticket || state.context.segs[0] || 'unknown';
216+
log(`skip: ${state.skipReason}`, `[${contextInfo}]`);
215217
return state;
216218
}
217219

218220
if (state.isDryRun) {
219-
log('dry-run: not writing');
221+
log('dry-run: not writing', `[${state.context.branch}]`);
220222
return state;
221223
}
222224

223225
try {
224226
fs.writeFileSync(state.commitMsgPath, state.lines.join('\n'), 'utf8');
225-
log('write ok');
227+
log('write ok', `[${state.context.branch}]`, `-> "${state.lines[0]}"`);
226228
} catch (error) {
227-
log('write error:', error);
229+
log('write error:', error, `[${state.context.branch}]`);
228230
}
229231

230232
return state;

0 commit comments

Comments
 (0)