@@ -20,7 +20,7 @@ const exitErrors: Error[] = []
20
20
21
21
core . info ( `Running in ${ baseDir } ` )
22
22
; ( async ( ) => {
23
- await checkInputs ( ) . catch ( core . setFailed )
23
+ await checkInputs ( )
24
24
25
25
core . startGroup ( 'Internal logs' )
26
26
core . info ( '> Staging files...' )
@@ -57,13 +57,30 @@ core.info(`Running in ${baseDir}`)
57
57
await git . fetch ( [ '--tags' , '--force' ] , log )
58
58
59
59
core . info ( '> Switching/creating branch...' )
60
+ /** This should store whether the branch already existed, of if a new one was created */
61
+ let branchType ! : 'existing' | 'new'
60
62
await git
61
- . checkout ( getInput ( 'branch' ) , undefined , log )
62
- . catch ( ( ) => git . checkoutLocalBranch ( getInput ( 'branch' ) , log ) )
63
-
64
- // The current default value is set here.
65
- // When the depreacted pull_strategy input is removed, the default should be set via the action manifest.
66
- const pull = getInput ( 'pull' ) || getInput ( 'pull_strategy' ) || '--no-rebase'
63
+ . checkout ( getInput ( 'branch' ) )
64
+ . then ( ( ) => ( branchType = 'existing' ) )
65
+ . catch ( ( ) => {
66
+ if ( getInput ( 'branch_mode' ) == 'create' ) {
67
+ log (
68
+ undefined ,
69
+ `'${ getInput ( 'branch' ) } ' branch not found, trying to create one.`
70
+ )
71
+ branchType = 'new'
72
+ return git . checkoutLocalBranch ( getInput ( 'branch' ) , log )
73
+ } else throw `'${ getInput ( 'branch' ) } ' branch not found.`
74
+ } )
75
+
76
+ /*
77
+ The current default value is set here: it will not pull when it has
78
+ created a new branch, it will use --rebase when the branch already existed
79
+ */
80
+ const pull =
81
+ getInput ( 'pull' ) ||
82
+ getInput ( 'pull_strategy' ) ||
83
+ ( branchType == 'new' ? 'NO-PULL' : '--no-rebase' )
67
84
if ( pull == 'NO-PULL' ) core . info ( '> Not pulling from repo.' )
68
85
else {
69
86
core . info ( '> Pulling from remote...' )
@@ -338,6 +355,18 @@ async function checkInputs() {
338
355
core . info ( `> Running for a PR, the action will use '${ branch } ' as ref.` )
339
356
// #endregion
340
357
358
+ // #region branch_mode
359
+ const branch_mode_valid = [ 'throw' , 'create' ]
360
+ if ( ! branch_mode_valid . includes ( getInput ( 'branch_mode' ) ) )
361
+ throw new Error (
362
+ `"${ getInput (
363
+ 'branch_mode'
364
+ ) } " is not a valid value for the 'branch_mode' input. Valid values are: ${ branch_mode_valid . join (
365
+ ', '
366
+ ) } `
367
+ )
368
+ // #endregion
369
+
341
370
// #region pathspec_error_handling
342
371
const peh_valid = [ 'ignore' , 'exitImmediately' , 'exitAtEnd' ]
343
372
if ( ! peh_valid . includes ( getInput ( 'pathspec_error_handling' ) ) )
0 commit comments