@@ -101,6 +101,7 @@ type PublishOptions = {
101
101
script : string ;
102
102
githubToken : string ;
103
103
createGithubReleases : boolean ;
104
+ commitUsingApi : boolean ;
104
105
cwd ?: string ;
105
106
} ;
106
107
@@ -119,6 +120,7 @@ export async function runPublish({
119
120
script,
120
121
githubToken,
121
122
createGithubReleases,
123
+ commitUsingApi,
122
124
cwd = process . cwd ( ) ,
123
125
} : PublishOptions ) : Promise < PublishResult > {
124
126
const octokit = setupOctokit ( githubToken ) ;
@@ -131,6 +133,10 @@ export async function runPublish({
131
133
{ cwd }
132
134
) ;
133
135
136
+ if ( ! commitUsingApi ) {
137
+ await gitUtils . pushTags ( ) ;
138
+ }
139
+
134
140
let { packages, tool } = await getPackages ( cwd ) ;
135
141
let releasedPackages : Package [ ] = [ ] ;
136
142
@@ -158,21 +164,21 @@ export async function runPublish({
158
164
await Promise . all (
159
165
releasedPackages . map ( async ( pkg ) => {
160
166
const tagName = `${ pkg . packageJson . name } @${ pkg . packageJson . version } ` ;
161
- // Tag will only be created locally,
162
- // Create it using the GitHub API so it's signed.
163
- await octokit . rest . git
164
- . createRef ( {
165
- ...github . context . repo ,
166
- ref : `refs/tags/${ tagName } ` ,
167
- sha : github . context . sha ,
168
- } )
169
- . catch ( ( err ) => {
170
- // Assuming tag was manually pushed in custom publish script
171
- core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
172
- } ) ;
173
- if ( createGithubReleases ) {
174
- await createRelease ( octokit , { pkg, tagName } ) ;
167
+ if ( commitUsingApi ) {
168
+ // Tag will usually only be created locally,
169
+ // Create it using the GitHub API so it's signed.
170
+ await octokit . rest . git
171
+ . createRef ( {
172
+ ...github . context . repo ,
173
+ ref : `refs/tags/${ tagName } ` ,
174
+ sha : github . context . sha ,
175
+ } )
176
+ . catch ( ( err ) => {
177
+ // Assuming tag was manually pushed in custom publish script
178
+ core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
179
+ } ) ;
175
180
}
181
+ await createRelease ( octokit , { pkg, tagName } ) ;
176
182
} )
177
183
) ;
178
184
}
@@ -191,20 +197,22 @@ export async function runPublish({
191
197
192
198
if ( match ) {
193
199
releasedPackages . push ( pkg ) ;
194
- const tagName = `v${ pkg . packageJson . version } ` ;
195
- // Tag will only be created locally,
196
- // Create it using the GitHub API so it's signed.
197
- await octokit . rest . git
198
- . createRef ( {
199
- ...github . context . repo ,
200
- ref : `refs/tags/${ tagName } ` ,
201
- sha : github . context . sha ,
202
- } )
203
- . catch ( ( err ) => {
204
- // Assuming tag was manually pushed in custom publish script
205
- core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
206
- } ) ;
207
200
if ( createGithubReleases ) {
201
+ const tagName = `v${ pkg . packageJson . version } ` ;
202
+ if ( commitUsingApi ) {
203
+ // Tag will only be created locally,
204
+ // Create it using the GitHub API so it's signed.
205
+ await octokit . rest . git
206
+ . createRef ( {
207
+ ...github . context . repo ,
208
+ ref : `refs/tags/${ tagName } ` ,
209
+ sha : github . context . sha ,
210
+ } )
211
+ . catch ( ( err ) => {
212
+ // Assuming tag was manually pushed in custom publish script
213
+ core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
214
+ } ) ;
215
+ }
208
216
await createRelease ( octokit , { pkg, tagName } ) ;
209
217
}
210
218
break ;
@@ -320,6 +328,7 @@ type VersionOptions = {
320
328
commitMessage ?: string ;
321
329
hasPublishScript ?: boolean ;
322
330
prBodyMaxCharacters ?: number ;
331
+ commitUsingApi : boolean ;
323
332
branch ?: string ;
324
333
} ;
325
334
@@ -335,6 +344,7 @@ export async function runVersion({
335
344
commitMessage = "Version Packages" ,
336
345
hasPublishScript = false ,
337
346
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE ,
347
+ commitUsingApi,
338
348
branch,
339
349
} : VersionOptions ) : Promise < RunVersionResult > {
340
350
const octokit = setupOctokit ( githubToken ) ;
@@ -345,6 +355,11 @@ export async function runVersion({
345
355
346
356
let { preState } = await readChangesetState ( cwd ) ;
347
357
358
+ if ( ! commitUsingApi ) {
359
+ await gitUtils . switchToMaybeExistingBranch ( versionBranch ) ;
360
+ await gitUtils . reset ( github . context . sha ) ;
361
+ }
362
+
348
363
let versionsByDirectory = await getVersionsByDirectory ( cwd ) ;
349
364
350
365
if ( script ) {
@@ -389,16 +404,27 @@ export async function runVersion({
389
404
! ! preState ? ` (${ preState . tag } )` : ""
390
405
} `;
391
406
392
- await commitChangesFromRepo ( {
393
- octokit,
394
- ...github . context . repo ,
395
- branch : versionBranch ,
396
- message : finalCommitMessage ,
397
- base : {
398
- commit : github . context . sha ,
399
- } ,
400
- force : true ,
401
- } ) ;
407
+ if ( commitUsingApi ) {
408
+ await commitChangesFromRepo ( {
409
+ octokit,
410
+ ...github . context . repo ,
411
+ branch : versionBranch ,
412
+ message : finalCommitMessage ,
413
+ base : {
414
+ commit : github . context . sha ,
415
+ } ,
416
+ force : true ,
417
+ } ) ;
418
+ } else {
419
+ // project with `commit: true` setting could have already committed files
420
+ if ( ! ( await gitUtils . checkIfClean ( ) ) ) {
421
+ await gitUtils . commitAll ( finalCommitMessage ) ;
422
+ }
423
+ }
424
+
425
+ if ( ! commitUsingApi ) {
426
+ await gitUtils . push ( versionBranch , { force : true } ) ;
427
+ }
402
428
403
429
let existingPullRequests = await existingPullRequestsPromise ;
404
430
core . info ( JSON . stringify ( existingPullRequests . data , null , 2 ) ) ;
0 commit comments