45
45
fetch-depth : 0 # Fetch complete history for accurate changelog generation
46
46
token : ${{ secrets.GITHUB_TOKEN }}
47
47
48
+ - name : Setup Node.js
49
+ uses : actions/setup-node@v4
50
+ with :
51
+ node-version : ' 18'
52
+
48
53
- name : Generate changelog
49
54
uses : TriPSs/conventional-changelog-action@v5
50
55
id : changelog
@@ -65,12 +70,58 @@ jobs:
65
70
release-count : 0
66
71
# Update package.json version
67
72
skip-version-file : false
73
+ version-file : ' ./package.json'
74
+ version-path : ' version'
68
75
# Skip commit and tag creation - we'll handle this via PR
69
76
skip-commit : true
70
77
skip-tag : true
78
+ # Skip git pull to avoid conflicts
79
+ skip-git-pull : true
71
80
# Generate GitHub Action summary
72
81
create-summary : true
73
82
83
+ # Debug: Show what files were modified
84
+ - name : Debug - Check modified files
85
+ if : ${{ steps.changelog.outputs.skipped == 'false' }}
86
+ run : |
87
+ echo "=== Git Status ==="
88
+ git status
89
+ echo ""
90
+ echo "=== Git Diff ==="
91
+ git diff --name-only
92
+ echo ""
93
+ echo "=== Package.json version ==="
94
+ cat package.json | grep '"version"'
95
+ echo ""
96
+ echo "=== CHANGELOG.md first 10 lines ==="
97
+ head -10 CHANGELOG.md
98
+
99
+ # Verify that package.json was updated
100
+ - name : Verify version update
101
+ if : ${{ steps.changelog.outputs.skipped == 'false' }}
102
+ run : |
103
+ EXPECTED_VERSION="${{ steps.changelog.outputs.version }}"
104
+ ACTUAL_VERSION=$(node -p "require('./package.json').version")
105
+
106
+ if [ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]; then
107
+ echo "❌ Error: package.json version ($ACTUAL_VERSION) does not match expected version ($EXPECTED_VERSION)"
108
+ echo "This indicates the conventional-changelog-action failed to update package.json"
109
+
110
+ # Manually update package.json if needed
111
+ echo "Attempting manual version update..."
112
+ npm version $EXPECTED_VERSION --no-git-tag-version
113
+
114
+ # Verify the manual update worked
115
+ NEW_VERSION=$(node -p "require('./package.json').version")
116
+ if [ "$NEW_VERSION" != "$EXPECTED_VERSION" ]; then
117
+ echo "❌ Manual version update failed"
118
+ exit 1
119
+ fi
120
+ echo "✅ Manually updated package.json to version $EXPECTED_VERSION"
121
+ else
122
+ echo "✅ package.json version correctly updated to $EXPECTED_VERSION"
123
+ fi
124
+
74
125
# Create a new branch for the changelog update
75
126
- name : Create changelog branch
76
127
if : ${{ steps.changelog.outputs.skipped == 'false' }}
@@ -79,18 +130,38 @@ jobs:
79
130
git config --local user.name "zopio-bot"
80
131
BRANCH_NAME="changelog-update-${{ steps.changelog.outputs.version }}"
81
132
git checkout -b $BRANCH_NAME
133
+
134
+ # Check if files were actually modified
135
+ if git diff --quiet CHANGELOG.md; then
136
+ echo "❌ Error: CHANGELOG.md was not modified"
137
+ exit 1
138
+ fi
139
+
140
+ # Add files and show what's being committed
82
141
git add CHANGELOG.md package.json
83
- git commit -m "chore(release): update changelog for v${{ steps.changelog.outputs.version }}"
142
+ echo "Files to be committed:"
143
+ git status --porcelain
144
+
145
+ # Commit with detailed message
146
+ git commit -m "chore(release): update changelog for v${{ steps.changelog.outputs.version }}" \
147
+ -m "- Updated CHANGELOG.md with version ${{ steps.changelog.outputs.version }}" \
148
+ -m "- Updated package.json version to ${{ steps.changelog.outputs.version }}"
149
+
84
150
git push origin $BRANCH_NAME
85
151
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
86
152
87
153
# Create PR for changelog update
88
154
- name : Create Pull Request
155
+ id : create-pr
89
156
if : ${{ steps.changelog.outputs.skipped == 'false' }}
90
157
uses : actions/github-script@v7
91
158
with :
92
159
github-token : ${{ secrets.GITHUB_TOKEN }}
93
160
script : |
161
+ // Get the modified files
162
+ const { stdout: modifiedFiles } = await exec.getExecOutput('git', ['diff', '--name-only', 'origin/main']);
163
+ const filesList = modifiedFiles.trim().split('\n').filter(f => f);
164
+
94
165
const { data: pr } = await github.rest.pulls.create({
95
166
owner: context.repo.owner,
96
167
repo: context.repo.repo,
@@ -102,18 +173,71 @@ jobs:
102
173
This PR updates the CHANGELOG.md for version v${{ steps.changelog.outputs.version }}.
103
174
104
175
### Changes included:
105
- - Updated CHANGELOG.md with latest changes
106
- - Bumped version in package.json to ${{ steps.changelog.outputs.version }}
176
+ - ✅ Updated CHANGELOG.md with latest changes
177
+ - ✅ Bumped version in package.json to ${{ steps.changelog.outputs.version }}
178
+
179
+ ### Modified files:
180
+ ${filesList.map(f => `- \`${f}\``).join('\n')}
107
181
108
182
### Release notes:
109
183
${{ steps.changelog.outputs.clean_changelog }}
110
184
185
+ ### Validation:
186
+ - Repository: \`${{ github.repository }}\`
187
+ - Version: \`${{ steps.changelog.outputs.version }}\`
188
+ - Tag: \`${{ steps.changelog.outputs.tag }}\`
189
+
111
190
---
112
191
*This PR was automatically generated by the changelog workflow.*`
113
192
});
114
193
115
194
core.setOutput('pull-request-number', pr.number);
116
195
core.setOutput('pull-request-url', pr.html_url);
196
+
197
+ // Log PR creation details
198
+ console.log(`✅ Created PR #${pr.number}: ${pr.html_url}`);
199
+
200
+ # Add PR validation comment
201
+ - name : Add validation comment to PR
202
+ if : ${{ steps.changelog.outputs.skipped == 'false' && steps.create-pr.outputs.pull-request-number }}
203
+ uses : actions/github-script@v7
204
+ with :
205
+ github-token : ${{ secrets.GITHUB_TOKEN }}
206
+ script : |
207
+ const prNumber = ${{ steps.create-pr.outputs.pull-request-number }};
208
+
209
+ // Verify files in the PR
210
+ const { data: files } = await github.rest.pulls.listFiles({
211
+ owner: context.repo.owner,
212
+ repo: context.repo.repo,
213
+ pull_number: prNumber
214
+ });
215
+
216
+ const hasChangelog = files.some(f => f.filename === 'CHANGELOG.md');
217
+ const hasPackageJson = files.some(f => f.filename === 'package.json');
218
+
219
+ let validationMessage = '## 🔍 Automated Validation Results\n\n';
220
+
221
+ if (hasChangelog && hasPackageJson) {
222
+ validationMessage += '✅ **All required files updated successfully:**\n';
223
+ validationMessage += '- CHANGELOG.md ✓\n';
224
+ validationMessage += '- package.json ✓\n\n';
225
+ validationMessage += '### Version Information\n';
226
+ validationMessage += `- New version: \`${{ steps.changelog.outputs.version }}\`\n`;
227
+ validationMessage += `- Tag to be created: \`${{ steps.changelog.outputs.tag }}\`\n`;
228
+ } else {
229
+ validationMessage += '❌ **Missing required files:**\n';
230
+ validationMessage += `- CHANGELOG.md: ${hasChangelog ? '✓' : '✗ MISSING'}\n`;
231
+ validationMessage += `- package.json: ${hasPackageJson ? '✓' : '✗ MISSING'}\n\n`;
232
+ validationMessage += '⚠️ **Action Required:** Please review and fix the missing files.\n';
233
+ }
234
+
235
+ await github.rest.issues.createComment({
236
+ owner: context.repo.owner,
237
+ repo: context.repo.repo,
238
+ issue_number: prNumber,
239
+ body: validationMessage
240
+ });
117
241
118
242
# Create GitHub release after PR is created
119
243
- name : Create Release
@@ -123,7 +247,15 @@ jobs:
123
247
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124
248
with :
125
249
tag_name : ${{ steps.changelog.outputs.tag }} # e.g., v1.2.3
126
- release_name : ${{ steps.changelog.outputs.tag }} # Release title
127
- body : ${{ steps.changelog.outputs.clean_changelog }} # Changelog content for this release
250
+ release_name : Release ${{ steps.changelog.outputs.tag }} # Release title
251
+ body : |
252
+ ## What's Changed
253
+
254
+ ${{ steps.changelog.outputs.clean_changelog }}
255
+
256
+ ---
257
+ **Full Changelog**: https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md
258
+
259
+ 📝 Note: This release is in draft mode. It will be published when PR #${{ steps.create-pr.outputs.pull-request-number }} is merged.
128
260
draft : true # Create as draft until PR is merged
129
261
prerelease : false # Mark as stable release
0 commit comments