@@ -101,6 +101,7 @@ type PublishOptions = {
101101 script : string ;
102102 githubToken : string ;
103103 createGithubReleases : boolean ;
104+ commitUsingApi : boolean ;
104105 cwd ?: string ;
105106} ;
106107
@@ -119,6 +120,7 @@ export async function runPublish({
119120 script,
120121 githubToken,
121122 createGithubReleases,
123+ commitUsingApi,
122124 cwd = process . cwd ( ) ,
123125} : PublishOptions ) : Promise < PublishResult > {
124126 const octokit = setupOctokit ( githubToken ) ;
@@ -131,6 +133,10 @@ export async function runPublish({
131133 { cwd }
132134 ) ;
133135
136+ if ( ! commitUsingApi ) {
137+ await gitUtils . pushTags ( ) ;
138+ }
139+
134140 let { packages, tool } = await getPackages ( cwd ) ;
135141 let releasedPackages : Package [ ] = [ ] ;
136142
@@ -158,21 +164,21 @@ export async function runPublish({
158164 await Promise . all (
159165 releasedPackages . map ( async ( pkg ) => {
160166 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+ } ) ;
175180 }
181+ await createRelease ( octokit , { pkg, tagName } ) ;
176182 } )
177183 ) ;
178184 }
@@ -191,20 +197,22 @@ export async function runPublish({
191197
192198 if ( match ) {
193199 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- } ) ;
207200 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+ }
208216 await createRelease ( octokit , { pkg, tagName } ) ;
209217 }
210218 break ;
@@ -320,6 +328,7 @@ type VersionOptions = {
320328 commitMessage ?: string ;
321329 hasPublishScript ?: boolean ;
322330 prBodyMaxCharacters ?: number ;
331+ commitUsingApi : boolean ;
323332 branch ?: string ;
324333} ;
325334
@@ -335,6 +344,7 @@ export async function runVersion({
335344 commitMessage = "Version Packages" ,
336345 hasPublishScript = false ,
337346 prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE ,
347+ commitUsingApi,
338348 branch,
339349} : VersionOptions ) : Promise < RunVersionResult > {
340350 const octokit = setupOctokit ( githubToken ) ;
@@ -345,6 +355,11 @@ export async function runVersion({
345355
346356 let { preState } = await readChangesetState ( cwd ) ;
347357
358+ if ( ! commitUsingApi ) {
359+ await gitUtils . switchToMaybeExistingBranch ( versionBranch ) ;
360+ await gitUtils . reset ( github . context . sha ) ;
361+ }
362+
348363 let versionsByDirectory = await getVersionsByDirectory ( cwd ) ;
349364
350365 if ( script ) {
@@ -389,16 +404,27 @@ export async function runVersion({
389404 ! ! preState ? ` (${ preState . tag } )` : ""
390405 } `;
391406
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+ }
402428
403429 let existingPullRequests = await existingPullRequestsPromise ;
404430 core . info ( JSON . stringify ( existingPullRequests . data , null , 2 ) ) ;
0 commit comments