1- const fs = require ( "fs" ) ;
2- const path = require ( "path" ) ;
3- const { Octokit } = require ( "@octokit/rest" ) ;
4- const simpleGit = require ( "simple-git" ) ;
1+ import fs from "fs" ;
2+ import path from "path" ;
3+ import { Octokit } from "@octokit/rest" ;
4+ import { fileURLToPath } from "url" ;
5+ import simpleGit from "simple-git" ;
56
67const VERSION = process . env . VERSION ;
78const GITHUB_TOKEN = process . env . GITHUB_TOKEN ;
89const PAT = process . env . PAT || GITHUB_TOKEN ;
9- const REPO_OWNER = "MendixMobile" ;
10- const REPO_NAME = "docs" ;
11- const UPSTREAM_OWNER = "MendixMobile" ;
12- // const UPSTREAM_OWNER = "mendix";
13- const BRANCH_NAME = `update-mobile-release-notes-v${ VERSION } ` ;
10+
11+ const CHANGELOG_BRANCH_NAME = `update-changelog-v${ VERSION } ` ;
12+
13+ const DOCS_REPO_OWNER = "MendixMobile" ;
14+ const DOCS_REPO_NAME = "docs" ;
15+ const DOCS_UPSTREAM_OWNER = "MendixMobile" ;
16+ // const DOCS_UPSTREAM_OWNER = "mendix";
17+ const DOCS_BRANCH_NAME = `update-mobile-release-notes-v${ VERSION } ` ;
1418const TARGET_FILE =
1519 "content/en/docs/releasenotes/mobile/make-it-native-parent/make-it-native-10.md" ;
1620
17- if ( ! VERSION ) {
18- console . error ( "VERSION env variable is required!" ) ;
21+ const __filename = fileURLToPath ( import . meta. url ) ;
22+ const __dirname = path . dirname ( __filename ) ;
23+
24+ const required = [ "VERSION" , "GITHUB_TOKEN" , "GITHUB_SHA" , "GITHUB_REPOSITORY" ] ;
25+ const missing = required . filter ( ( k ) => ! process . env [ k ] ) ;
26+ if ( missing . length ) {
27+ console . error ( "Missing env vars:" , missing . join ( ", " ) ) ;
1928 process . exit ( 1 ) ;
2029}
2130
@@ -43,7 +52,7 @@ function extractUnreleased() {
4352
4453function updateChangelog ( { changelog, unreleasedContent, changelogPath } ) {
4554 const today = getToday ( ) ;
46- const newSection = `## [${ VERSION } ] Make it Native - ${ today } \n${ unreleasedContent } \n\n` ;
55+ const newSection = `## [${ VERSION } ] Make it Native - ${ today } \n\n ${ unreleasedContent } \n\n` ;
4756 const unreleasedRegex =
4857 / ^ # # \[ U n r e l e a s e d \] ( .* ?) (? = ^ # # \[ \d + \. \d + \. \d + \] [ ^ \n ] * | \Z ) / ms;
4958 const updatedChangelog = changelog . replace (
@@ -72,57 +81,65 @@ async function createRelease(unreleasedContent) {
7281 } ) ;
7382}
7483
75- async function prChangelogUpdate ( ) {
84+ async function createChangelogUpdatePR ( ) {
7685 const git = simpleGit ( ) ;
7786
78- await git . checkoutLocalBranch ( CHANGELOG_BRANCH ) ;
87+ await git . checkoutLocalBranch ( CHANGELOG_BRANCH_NAME ) ;
7988
8089 await git . add ( "CHANGELOG.md" ) ;
8190 await git . commit ( `chore: update CHANGELOG for v${ VERSION } ` ) ;
82- await git . push ( "origin" , CHANGELOG_BRANCH , [ "--force" ] ) ;
91+ await git . push ( "origin" , CHANGELOG_BRANCH_NAME , [ "--force-with-lease " ] ) ;
8392
8493 await octokit . pulls . create ( {
85- owner : MAKE_IT_NATIVE_OWNER ,
86- repo : MAKE_IT_NATIVE_REPO ,
94+ owner : process . env . GITHUB_REPOSITORY_OWNER ,
95+ repo : process . env . GITHUB_REPOSITORY . split ( "/" ) [ 1 ] ,
8796 title : `Update CHANGELOG for v${ VERSION } ` ,
88- head : CHANGELOG_BRANCH ,
89- base : "development " ,
97+ head : CHANGELOG_BRANCH_NAME ,
98+ base : "main " ,
9099 body : "**Note:** Please do not take any action on this pull request unless it has been reviewed and approved by a member of the Mobile team." ,
91100 draft : true ,
92101 } ) ;
93102
94103 process . chdir ( ".." ) ;
95104}
96105
106+ function injectUnreleasedToDoc ( docPath , unreleasedContent ) {
107+ const doc = fs . readFileSync ( docPath , "utf-8" ) ;
108+ const frontmatterMatch = doc . match ( / ^ - - - [ \s \S ] * ?- - - / ) ;
109+ if ( ! frontmatterMatch ) throw new Error ( "Frontmatter not found!" ) ;
110+ const frontmatter = frontmatterMatch [ 0 ] ;
111+ const rest = doc . slice ( frontmatter . length ) . trimStart ( ) ;
112+
113+ const firstParagraphMatch = rest . match ( / ^ ( .* ?\n ) ( \s * \n ) / s) ;
114+ if ( ! firstParagraphMatch ) throw new Error ( "First paragraph not found!" ) ;
115+ const firstParagraph = firstParagraphMatch [ 1 ] ;
116+ const afterFirstParagraph = rest . slice ( firstParagraph . length ) . trimStart ( ) ;
117+
118+ const date = new Date ( ) ;
119+ const formattedDate = date . toLocaleDateString ( "en-US" , {
120+ year : "numeric" ,
121+ month : "short" ,
122+ day : "numeric" ,
123+ } ) ;
124+ const title = `## ${ VERSION } \n\n**Release date: ${ formattedDate } **` ;
125+
126+ return `${ frontmatter } \n\n${ firstParagraph } \n${ title } \n\n${ unreleasedContent } \n\n${ afterFirstParagraph } ` ;
127+ }
128+
97129async function updateDocs ( unreleasedContent ) {
98130 const git = simpleGit ( ) ;
99131 await git . clone (
100- `https://x-access-token:${ PAT } @github.com/${ REPO_OWNER } /${ REPO_NAME } .git`
132+ `https://x-access-token:${ PAT } @github.com/${ DOCS_REPO_OWNER } /${ DOCS_REPO_NAME } .git`
101133 ) ;
102- process . chdir ( REPO_NAME ) ;
103- await git . checkoutLocalBranch ( BRANCH_NAME ) ;
104-
105- function injectUnreleasedToDoc ( docPath , unreleasedContent ) {
106- const doc = fs . readFileSync ( docPath , "utf-8" ) ;
107- const frontmatterMatch = doc . match ( / ^ - - - [ \s \S ] * ?- - - / ) ;
108- if ( ! frontmatterMatch ) throw new Error ( "Frontmatter not found!" ) ;
109- const frontmatter = frontmatterMatch [ 0 ] ;
110- const rest = doc . slice ( frontmatter . length ) . trimStart ( ) ;
111-
112- const firstParagraphMatch = rest . match ( / ^ ( .* ?\n ) ( \s * \n ) / s) ;
113- if ( ! firstParagraphMatch ) throw new Error ( "First paragraph not found!" ) ;
114- const firstParagraph = firstParagraphMatch [ 1 ] ;
115- const afterFirstParagraph = rest . slice ( firstParagraph . length ) . trimStart ( ) ;
116-
117- return `${ frontmatter } \n\n${ firstParagraph } \n${ unreleasedContent } \n\n${ afterFirstParagraph } ` ;
118- }
134+ process . chdir ( DOCS_REPO_NAME ) ;
135+ await git . checkoutLocalBranch ( DOCS_BRANCH_NAME ) ;
119136
120137 const newDocContent = injectUnreleasedToDoc ( TARGET_FILE , unreleasedContent ) ;
121138 fs . writeFileSync ( TARGET_FILE , newDocContent , "utf-8" ) ;
122139
123140 await git . add ( TARGET_FILE ) ;
124141 await git . commit ( `docs: update mobile release notes for v${ VERSION } ` ) ;
125- await git . push ( "origin" , BRANCH_NAME , [ "--force" ] ) ;
142+ await git . push ( "origin" , DOCS_BRANCH_NAME , [ "--force" ] ) ;
126143
127144 const prBody = `
128145Automated sync of the latest release notes for v${ VERSION } from [make-it-native](https://github.com/mendix/make-it-native).
@@ -135,10 +152,10 @@ This pull request was automatically generated by an automation process managed b
135152` ;
136153
137154 await octokit . pulls . create ( {
138- owner : UPSTREAM_OWNER ,
139- repo : REPO_NAME ,
155+ owner : DOCS_UPSTREAM_OWNER ,
156+ repo : DOCS_REPO_NAME ,
140157 title : `Update mobile app release notes for v${ VERSION } ` ,
141- head : `${ REPO_OWNER } :${ BRANCH_NAME } ` ,
158+ head : `${ DOCS_REPO_OWNER } :${ DOCS_BRANCH_NAME } ` ,
142159 base : "development" ,
143160 body : prBody ,
144161 draft : true ,
@@ -148,12 +165,18 @@ This pull request was automatically generated by an automation process managed b
148165}
149166
150167( async ( ) => {
151- const { changelog, unreleasedContent, changelogPath } = extractUnreleased ( ) ;
152-
153- await createRelease ( unreleasedContent ) ;
154- updateChangelog ( { changelog, unreleasedContent, changelogPath } ) ;
155- await prChangelogUpdate ( ) ;
156- await updateDocs ( unreleasedContent ) ;
157-
158- console . log ( "Release, changelog update, and docs PR completed!" ) ;
168+ try {
169+ const { changelog, unreleasedContent, changelogPath } = extractUnreleased ( ) ;
170+
171+ await createRelease ( unreleasedContent ) ;
172+ updateChangelog ( { changelog, unreleasedContent, changelogPath } ) ;
173+ await createChangelogUpdatePR ( ) ;
174+ await updateDocs ( unreleasedContent ) ;
175+
176+ console . log ( "Release, changelog update, and docs PR completed!" ) ;
177+ process . exit ( 0 ) ;
178+ } catch ( err ) {
179+ console . error ( "❌ Release script failed:" , err ) ;
180+ process . exit ( 1 ) ;
181+ }
159182} ) ( ) ;
0 commit comments