Skip to content

Commit 52b8304

Browse files
[TEST]: testing changelog-api (#11)
1 parent 82a6865 commit 52b8304

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

.github/scripts/notify-backend.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
11
const https = require('https');
2+
const fs = require('fs');
3+
const path = require('path');
4+
const matter = require('gray-matter');
25

6+
const workspace = process.env.GITHUB_WORKSPACE;
7+
const newChangelogPath = path.join(workspace, 'changelog.mdx');
8+
const newFileContent = fs.readFileSync(newChangelogPath, 'utf8');
9+
const { data: newFrontmatter } = matter(newFileContent);
10+
const newSummary = newFrontmatter.summary;
11+
12+
13+
const oldChangelogPath = path.join(__dirname, 'old_changelog.mdx');
14+
const oldFileContent = fs.readFileSync(oldChangelogPath, 'utf8');
15+
const { data: oldFrontmatter } = matter(oldFileContent);
16+
const oldSummary = oldFrontmatter.summary;
17+
if (!newSummary) {
18+
console.error("Error: 'summary' not found in changelog.mdx frontmatter.");
19+
process.exit(1);
20+
}
21+
22+
if (newSummary === oldSummary) {
23+
console.log('Summary is unchanged. Skipping notification.');
24+
process.exit(0);
25+
}
26+
console.log('Summary has changed. Sending notification...');
327
const options = {
4-
hostname: 'your-backend-api.com',
5-
path: '/api/changelog-updated',
28+
hostname: 'changelog-api.strettchcloud.com',
29+
path: '/api/changelog',
630
method: 'POST',
731
headers: {
832
'Content-Type': 'application/json'
933
}
1034
};
1135

12-
const data = JSON.stringify({
36+
const requestBody = JSON.stringify({
1337
message: 'Changelog has been updated!',
38+
summary: newSummary,
1439
timestamp: new Date().toISOString()
1540
});
1641

1742
const req = https.request(options, res => {
1843
console.log(`statusCode: ${res.statusCode}`);
19-
2044
res.on('data', d => {
2145
process.stdout.write(d);
2246
});
2347
});
2448

2549
req.on('error', error => {
2650
console.error(error);
27-
process.exit(1); // Exit with a non-zero code to fail the workflow step
51+
process.exit(1);
2852
});
2953

30-
req.write(data);
54+
req.write(requestBody);
3155
req.end();

.github/scripts/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"gray-matter": "^4.0.3"
4+
}
5+
}

.github/workflows/changelog-notify.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ jobs:
2121
files: |
2222
changelog.mdx
2323
24-
- name: Notify backend if changelog changed
24+
- name: Notify backend if summary changed
2525
if: steps.changed-files.outputs.any_changed == 'true'
2626
run: |
27+
# 1. Install dependencies
28+
npm install --prefix .github/scripts
29+
30+
# 2. Get the *previous* version of the file
31+
# This is the key new line.
32+
git show HEAD~1:changelog.mdx > .github/scripts/old_changelog.mdx || echo "---" > .github/scripts/old_changelog.mdx
33+
34+
# 3. Run the "smart" script
2735
node .github/scripts/notify-backend.js

changelog.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: 'Changelog'
33
description: 'Track the latest updates, features, and improvements to Strettch Cloud'
44
icon: 'clock-rotate-left'
5+
summary: '🚀 Fixed billing accuracy, improved DNS handling, and enhanced mobile responsiveness.'
56
---
67

78
### Week of October 21-27, 2025

0 commit comments

Comments
 (0)