77 createIssue , createPullRequest , getMilestone , githubToken , listMilestoneIssues , listPullRequests ,
88} from "./github-api" ;
99
10+ const MAIN_BRANCH = "master" ;
11+
1012const root = path . resolve ( path . join ( __dirname , "../.." ) ) ;
1113const allMessages : string [ ] = [ ] ;
1214const repoName = "Azure/BatchExplorer" ;
@@ -54,57 +56,71 @@ function checkGithubToken() {
5456/**
5557 * This goes back to master and pull
5658 */
57- async function gotoMaster ( ) {
58- await run ( " git checkout master" ) ;
59+ async function gotoMainBranch ( ) {
60+ await run ( ` git checkout ${ MAIN_BRANCH } ` ) ;
5961 await run ( "git pull" ) ;
60- success ( " Checkout to master branch and pulled latest" ) ;
62+ success ( ` Checkout to ${ MAIN_BRANCH } branch and pulled latest` ) ;
6163}
6264
63- async function loadMillestone ( millestoneId : number ) {
64- return getMilestone ( repoName , millestoneId ) ;
65+ async function loadMilestone ( milestoneId : number ) {
66+ return getMilestone ( repoName , milestoneId ) ;
6567}
6668
6769async function getCurrentBranch ( ) : Promise < string > {
6870 const { stdout } = await run ( `git symbolic-ref --short -q HEAD` ) ;
6971 return stdout . trim ( ) ;
7072}
7173
72- function getMillestoneId ( ) {
74+ function getMilestoneId ( ) {
7375 if ( process . argv . length < 3 ) {
74- throw new Error ( "No millestone id was provided." ) ;
76+ throw new Error ( "No milestone id was provided." ) ;
7577 }
7678 return parseInt ( process . argv [ 2 ] , 10 ) ;
7779}
7880
7981async function confirmVersion ( version : string ) {
8082 return new Promise ( ( resolve , reject ) => {
81- ask ( `Up program to be version ${ version } (From millestone title) [Y/n]` , true , ( ok ) => {
83+ ask ( `Up program to be version ${ version } (From milestone title) [Y/n]` , true , ( ok ) => {
8284 if ( ok ) {
8385 success ( `A new release for version ${ version } will be prepared` ) ;
8486 resolve ( null ) ;
8587 } else {
86- reject ( new Error ( "Millestone version wasn't confirmed. Please change millestone title" ) ) ;
88+ reject ( new Error ( "milestone version wasn't confirmed. Please change milestone title" ) ) ;
8789 }
8890 } ) ;
8991 } ) ;
9092}
9193
94+ function calcNextVersion ( version : string ) {
95+ const match = / ^ ( \d + \. ) ( \d + ) ( \. \d + ) $ / . exec ( version ) ;
96+ return `${ match [ 1 ] } ${ parseInt ( match [ 2 ] , 10 ) + 1 } ${ match [ 3 ] } ` ;
97+ }
98+
9299function getPreparationBranchName ( version : string ) {
93100 return `release/prepare-${ version } ` ;
94101}
95102
96103async function switchToNewBranch ( branchName : string ) {
97- await run ( `git checkout -b ${ branchName } ` ) ;
104+ await run ( `git checkout -B ${ branchName } ` ) ;
98105 success ( `Created a new branch ${ branchName } ` ) ;
99106}
100107
101108async function bumpVersion ( version ) {
102- await run ( `npm version --no-git-tag-version --allow-same-version ${ version } ` ) ;
103- success ( `Updated version in package.json to ${ version } ` ) ;
109+ const currentBranch = await getCurrentBranch ( ) ;
110+ const nextVersion = calcNextVersion ( version ) ;
111+ const bumpBranch = `release/bump-${ nextVersion } ` ;
112+ await gotoMainBranch ( ) ;
113+ await switchToNewBranch ( bumpBranch ) ;
114+ await run ( `npm version --no-git-tag-version --allow-same-version ${ nextVersion } ` ) ;
115+
116+ await run ( `git commit -am "Bump version to ${ nextVersion } "` ) ;
117+ await run ( `git push origin ${ bumpBranch } ` ) ;
118+ await run ( `git checkout "${ currentBranch } "` ) ;
119+ success ( `Updated version in package.json to ${ nextVersion } (branch: ${ bumpBranch } )` ) ;
104120}
105121
106- async function updateChangeLog ( version , millestoneId ) {
107- const { stdout } = await run ( `gh-changelog-gen --repo ${ repoName } ${ millestoneId } --formatter markdown` ) ;
122+ async function updateChangeLog ( version , milestoneId ) {
123+ const { stdout } = await run ( `gh-changelog-gen --repo ${ repoName } ${ milestoneId } --formatter markdown` ) ;
108124 const changelogFile = path . join ( root , "CHANGELOG.md" ) ;
109125 const changelogContent = fs . readFileSync ( changelogFile ) ;
110126
@@ -129,14 +145,14 @@ async function push(branchName: string) {
129145 await run ( `git push --set-upstream origin ${ branchName } ` ) ;
130146}
131147
132- async function createIssueIfNot ( millestoneId , version ) {
148+ async function createIssueIfNot ( milestoneId , version ) {
133149 const title = `Prepare for release of version ${ version } ` ;
134- const issues = await listMilestoneIssues ( repoName , millestoneId ) ;
150+ const issues = await listMilestoneIssues ( repoName , milestoneId ) ;
135151 let issue = issues . filter ( x => x . title === title ) [ 0 ] ;
136152 if ( issue ) {
137153 success ( `Issue was already created earlier ${ issue . html_url } ` ) ;
138154 } else {
139- issue = await createIssue ( repoName , title , newIssueBody , millestoneId ) ;
155+ issue = await createIssue ( repoName , title , newIssueBody , milestoneId ) ;
140156 success ( `Created a new issue ${ issue . html_url } ` ) ;
141157 }
142158 return issue ;
@@ -166,27 +182,27 @@ async function buildApp() {
166182
167183async function startPublish ( ) {
168184 checkGithubToken ( ) ;
169- const millestoneId = getMillestoneId ( ) ;
170- const millestone = await loadMillestone ( millestoneId ) ;
171- if ( ! millestone . title && millestone [ "message" ] ) {
172- throw new Error ( `Error fetching milestone: ${ millestone [ "message" ] } ` ) ;
185+ const milestoneId = getMilestoneId ( ) ;
186+ const milestone = await loadMilestone ( milestoneId ) ;
187+ if ( ! milestone . title && milestone [ "message" ] ) {
188+ throw new Error ( `Error fetching milestone: ${ milestone [ "message" ] } ` ) ;
173189 }
174- const version = millestone . title ;
190+ const version = milestone . title ;
175191 await confirmVersion ( version ) ;
176192 const releaseBranch = getPreparationBranchName ( version ) ;
177193 const branch = await getCurrentBranch ( ) ;
178194 if ( branch !== releaseBranch ) {
179- await gotoMaster ( ) ;
195+ await gotoMainBranch ( ) ;
180196 await switchToNewBranch ( releaseBranch ) ;
181197 }
182- await bumpVersion ( version ) ;
183- await updateChangeLog ( version , millestoneId ) ;
198+ await updateChangeLog ( version , milestoneId ) ;
184199 await updateThirdParty ( ) ;
185200 await commitChanges ( ) ;
186201 await push ( releaseBranch ) ;
187- const issue = await createIssueIfNot ( millestoneId , version ) ;
202+ const issue = await createIssueIfNot ( milestoneId , version ) ;
188203 await createPullrequestIfNot ( version , releaseBranch , issue ) ;
189204 await buildApp ( ) ;
205+ await bumpVersion ( version ) ;
190206}
191207
192208startPublish ( ) . then ( ( ) => {
0 commit comments