7
7
createIssue , createPullRequest , getMilestone , githubToken , listMilestoneIssues , listPullRequests ,
8
8
} from "./github-api" ;
9
9
10
+ const MAIN_BRANCH = "master" ;
11
+
10
12
const root = path . resolve ( path . join ( __dirname , "../.." ) ) ;
11
13
const allMessages : string [ ] = [ ] ;
12
14
const repoName = "Azure/BatchExplorer" ;
@@ -54,57 +56,71 @@ function checkGithubToken() {
54
56
/**
55
57
* This goes back to master and pull
56
58
*/
57
- async function gotoMaster ( ) {
58
- await run ( " git checkout master" ) ;
59
+ async function gotoMainBranch ( ) {
60
+ await run ( ` git checkout ${ MAIN_BRANCH } ` ) ;
59
61
await run ( "git pull" ) ;
60
- success ( " Checkout to master branch and pulled latest" ) ;
62
+ success ( ` Checkout to ${ MAIN_BRANCH } branch and pulled latest` ) ;
61
63
}
62
64
63
- async function loadMillestone ( millestoneId : number ) {
64
- return getMilestone ( repoName , millestoneId ) ;
65
+ async function loadMilestone ( milestoneId : number ) {
66
+ return getMilestone ( repoName , milestoneId ) ;
65
67
}
66
68
67
69
async function getCurrentBranch ( ) : Promise < string > {
68
70
const { stdout } = await run ( `git symbolic-ref --short -q HEAD` ) ;
69
71
return stdout . trim ( ) ;
70
72
}
71
73
72
- function getMillestoneId ( ) {
74
+ function getMilestoneId ( ) {
73
75
if ( process . argv . length < 3 ) {
74
- throw new Error ( "No millestone id was provided." ) ;
76
+ throw new Error ( "No milestone id was provided." ) ;
75
77
}
76
78
return parseInt ( process . argv [ 2 ] , 10 ) ;
77
79
}
78
80
79
81
async function confirmVersion ( version : string ) {
80
82
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 ) => {
82
84
if ( ok ) {
83
85
success ( `A new release for version ${ version } will be prepared` ) ;
84
86
resolve ( null ) ;
85
87
} 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" ) ) ;
87
89
}
88
90
} ) ;
89
91
} ) ;
90
92
}
91
93
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
+
92
99
function getPreparationBranchName ( version : string ) {
93
100
return `release/prepare-${ version } ` ;
94
101
}
95
102
96
103
async function switchToNewBranch ( branchName : string ) {
97
- await run ( `git checkout -b ${ branchName } ` ) ;
104
+ await run ( `git checkout -B ${ branchName } ` ) ;
98
105
success ( `Created a new branch ${ branchName } ` ) ;
99
106
}
100
107
101
108
async 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 } )` ) ;
104
120
}
105
121
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` ) ;
108
124
const changelogFile = path . join ( root , "CHANGELOG.md" ) ;
109
125
const changelogContent = fs . readFileSync ( changelogFile ) ;
110
126
@@ -129,14 +145,14 @@ async function push(branchName: string) {
129
145
await run ( `git push --set-upstream origin ${ branchName } ` ) ;
130
146
}
131
147
132
- async function createIssueIfNot ( millestoneId , version ) {
148
+ async function createIssueIfNot ( milestoneId , version ) {
133
149
const title = `Prepare for release of version ${ version } ` ;
134
- const issues = await listMilestoneIssues ( repoName , millestoneId ) ;
150
+ const issues = await listMilestoneIssues ( repoName , milestoneId ) ;
135
151
let issue = issues . filter ( x => x . title === title ) [ 0 ] ;
136
152
if ( issue ) {
137
153
success ( `Issue was already created earlier ${ issue . html_url } ` ) ;
138
154
} else {
139
- issue = await createIssue ( repoName , title , newIssueBody , millestoneId ) ;
155
+ issue = await createIssue ( repoName , title , newIssueBody , milestoneId ) ;
140
156
success ( `Created a new issue ${ issue . html_url } ` ) ;
141
157
}
142
158
return issue ;
@@ -166,27 +182,27 @@ async function buildApp() {
166
182
167
183
async function startPublish ( ) {
168
184
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" ] } ` ) ;
173
189
}
174
- const version = millestone . title ;
190
+ const version = milestone . title ;
175
191
await confirmVersion ( version ) ;
176
192
const releaseBranch = getPreparationBranchName ( version ) ;
177
193
const branch = await getCurrentBranch ( ) ;
178
194
if ( branch !== releaseBranch ) {
179
- await gotoMaster ( ) ;
195
+ await gotoMainBranch ( ) ;
180
196
await switchToNewBranch ( releaseBranch ) ;
181
197
}
182
- await bumpVersion ( version ) ;
183
- await updateChangeLog ( version , millestoneId ) ;
198
+ await updateChangeLog ( version , milestoneId ) ;
184
199
await updateThirdParty ( ) ;
185
200
await commitChanges ( ) ;
186
201
await push ( releaseBranch ) ;
187
- const issue = await createIssueIfNot ( millestoneId , version ) ;
202
+ const issue = await createIssueIfNot ( milestoneId , version ) ;
188
203
await createPullrequestIfNot ( version , releaseBranch , issue ) ;
189
204
await buildApp ( ) ;
205
+ await bumpVersion ( version ) ;
190
206
}
191
207
192
208
startPublish ( ) . then ( ( ) => {
0 commit comments