Skip to content

Commit dc24ad8

Browse files
author
Umutcan ÖNER
committed
fix: changelog generation with proper package.json version updates
- Update repository owner from 'aicd' to 'zopiolabs' in .autorc - Add version validation and fallback mechanisms to changelog workflow - Enhance debugging output for troubleshooting version issues - Ensure both CHANGELOG.md and package.json are updated together
1 parent a08f2eb commit dc24ad8

File tree

2 files changed

+138
-6
lines changed

2 files changed

+138
-6
lines changed

.autorc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"plugins": ["npm", "first-time-contributor", "released"],
3-
"owner": "aicd",
3+
"owner": "zopiolabs",
44
"repo": "aicd",
55
"name": "AICD Team",
66
"email": "admin@aicd.com"

.github/workflows/changelog.yml

Lines changed: 137 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ jobs:
4545
fetch-depth: 0 # Fetch complete history for accurate changelog generation
4646
token: ${{ secrets.GITHUB_TOKEN }}
4747

48+
- name: Setup Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: '18'
52+
4853
- name: Generate changelog
4954
uses: TriPSs/conventional-changelog-action@v5
5055
id: changelog
@@ -65,12 +70,58 @@ jobs:
6570
release-count: 0
6671
# Update package.json version
6772
skip-version-file: false
73+
version-file: './package.json'
74+
version-path: 'version'
6875
# Skip commit and tag creation - we'll handle this via PR
6976
skip-commit: true
7077
skip-tag: true
78+
# Skip git pull to avoid conflicts
79+
skip-git-pull: true
7180
# Generate GitHub Action summary
7281
create-summary: true
7382

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+
74125
# Create a new branch for the changelog update
75126
- name: Create changelog branch
76127
if: ${{ steps.changelog.outputs.skipped == 'false' }}
@@ -79,18 +130,38 @@ jobs:
79130
git config --local user.name "zopio-bot"
80131
BRANCH_NAME="changelog-update-${{ steps.changelog.outputs.version }}"
81132
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
82141
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+
84150
git push origin $BRANCH_NAME
85151
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
86152
87153
# Create PR for changelog update
88154
- name: Create Pull Request
155+
id: create-pr
89156
if: ${{ steps.changelog.outputs.skipped == 'false' }}
90157
uses: actions/github-script@v7
91158
with:
92159
github-token: ${{ secrets.GITHUB_TOKEN }}
93160
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+
94165
const { data: pr } = await github.rest.pulls.create({
95166
owner: context.repo.owner,
96167
repo: context.repo.repo,
@@ -102,18 +173,71 @@ jobs:
102173
This PR updates the CHANGELOG.md for version v${{ steps.changelog.outputs.version }}.
103174
104175
### 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')}
107181
108182
### Release notes:
109183
${{ steps.changelog.outputs.clean_changelog }}
110184
185+
### Validation:
186+
- Repository: \`${{ github.repository }}\`
187+
- Version: \`${{ steps.changelog.outputs.version }}\`
188+
- Tag: \`${{ steps.changelog.outputs.tag }}\`
189+
111190
---
112191
*This PR was automatically generated by the changelog workflow.*`
113192
});
114193
115194
core.setOutput('pull-request-number', pr.number);
116195
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+
});
117241
118242
# Create GitHub release after PR is created
119243
- name: Create Release
@@ -123,7 +247,15 @@ jobs:
123247
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124248
with:
125249
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.
128260
draft: true # Create as draft until PR is merged
129261
prerelease: false # Mark as stable release

0 commit comments

Comments
 (0)