11const 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...' ) ;
327const 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
1742const 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
2549req . 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 ) ;
3155req . end ( ) ;
0 commit comments