@@ -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 ) ;
@@ -158,21 +160,21 @@ export async function runPublish({
158
160
await Promise . all (
159
161
releasedPackages . map ( async ( pkg ) => {
160
162
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 } ) ;
163
+ if ( commitUsingApi ) {
164
+ // Tag will usually only be created locally,
165
+ // Create it using the GitHub API so it's signed.
166
+ await octokit . rest . git
167
+ . createRef ( {
168
+ ...github . context . repo ,
169
+ ref : `refs/tags/${ tagName } ` ,
170
+ sha : github . context . sha ,
171
+ } )
172
+ . catch ( ( err ) => {
173
+ // Assuming tag was manually pushed in custom publish script
174
+ core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
175
+ } ) ;
175
176
}
177
+ await createRelease ( octokit , { pkg, tagName } ) ;
176
178
} )
177
179
) ;
178
180
}
@@ -191,20 +193,22 @@ export async function runPublish({
191
193
192
194
if ( match ) {
193
195
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
196
if ( createGithubReleases ) {
197
+ const tagName = `v${ pkg . packageJson . version } ` ;
198
+ if ( commitUsingApi ) {
199
+ // Tag will only be created locally,
200
+ // Create it using the GitHub API so it's signed.
201
+ await octokit . rest . git
202
+ . createRef ( {
203
+ ...github . context . repo ,
204
+ ref : `refs/tags/${ tagName } ` ,
205
+ sha : github . context . sha ,
206
+ } )
207
+ . catch ( ( err ) => {
208
+ // Assuming tag was manually pushed in custom publish script
209
+ core . warning ( `Failed to create tag ${ tagName } : ${ err . message } ` ) ;
210
+ } ) ;
211
+ }
208
212
await createRelease ( octokit , { pkg, tagName } ) ;
209
213
}
210
214
break ;
@@ -320,6 +324,7 @@ type VersionOptions = {
320
324
commitMessage ?: string ;
321
325
hasPublishScript ?: boolean ;
322
326
prBodyMaxCharacters ?: number ;
327
+ commitUsingApi : boolean ;
323
328
branch ?: string ;
324
329
} ;
325
330
@@ -335,6 +340,7 @@ export async function runVersion({
335
340
commitMessage = "Version Packages" ,
336
341
hasPublishScript = false ,
337
342
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE ,
343
+ commitUsingApi,
338
344
branch,
339
345
} : VersionOptions ) : Promise < RunVersionResult > {
340
346
const octokit = setupOctokit ( githubToken ) ;
@@ -345,6 +351,11 @@ export async function runVersion({
345
351
346
352
let { preState } = await readChangesetState ( cwd ) ;
347
353
354
+ if ( ! commitUsingApi ) {
355
+ await gitUtils . switchToMaybeExistingBranch ( versionBranch ) ;
356
+ await gitUtils . reset ( github . context . sha ) ;
357
+ }
358
+
348
359
let versionsByDirectory = await getVersionsByDirectory ( cwd ) ;
349
360
350
361
if ( script ) {
@@ -389,16 +400,23 @@ export async function runVersion({
389
400
! ! preState ? ` (${ preState . tag } )` : ""
390
401
} `;
391
402
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
- } ) ;
403
+ if ( commitUsingApi ) {
404
+ await commitChangesFromRepo ( {
405
+ octokit,
406
+ ...github . context . repo ,
407
+ branch : versionBranch ,
408
+ message : finalCommitMessage ,
409
+ base : {
410
+ commit : github . context . sha ,
411
+ } ,
412
+ force : true ,
413
+ } ) ;
414
+ } else {
415
+ // project with `commit: true` setting could have already committed files
416
+ if ( ! ( await gitUtils . checkIfClean ( ) ) ) {
417
+ await gitUtils . commitAll ( finalCommitMessage ) ;
418
+ }
419
+ }
402
420
403
421
let existingPullRequests = await existingPullRequestsPromise ;
404
422
core . info ( JSON . stringify ( existingPullRequests . data , null , 2 ) ) ;
0 commit comments