feat: add worktree input
This commit is contained in:
@@ -59,7 +59,10 @@ inputs:
|
||||
tag_push:
|
||||
description: Arguments for the git push --tags command (any additional argument will be added after --tags)
|
||||
required: false
|
||||
|
||||
worktree:
|
||||
description: Arguments for the git worktree commands, see the README for usage
|
||||
required: false
|
||||
|
||||
# Input not required from the user
|
||||
github_token:
|
||||
description: The token used to make requests to the GitHub API. It's NOT used to make commits and should not be changed.
|
||||
|
||||
2
lib/index.js
generated
2
lib/index.js
generated
File diff suppressed because one or more lines are too long
24
src/io.ts
24
src/io.ts
@@ -19,6 +19,7 @@ interface InputTypes {
|
||||
remove: string | undefined
|
||||
tag: string | undefined
|
||||
tag_push: string | undefined
|
||||
worktree: string | undefined
|
||||
|
||||
github_token: string | undefined
|
||||
}
|
||||
@@ -243,6 +244,29 @@ export async function checkInputs() {
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region worktree
|
||||
if (getInput('worktree')) {
|
||||
const parsed = parseInputArray(getInput('worktree') || '')
|
||||
|
||||
if (parsed.length == 1)
|
||||
core.info(
|
||||
"Worktree input parsed as single string, it will be used as if it's the path to the worktree."
|
||||
)
|
||||
else if (parsed.length == 2 || parsed.length == 3)
|
||||
core.info(
|
||||
'Worktree input parsed as [string, string, string], it will be used as follows:\n' +
|
||||
'0: path to the worktree directory\n' +
|
||||
'1: arguments for the git worktree add command (including the directory), defaults to the directory\n' +
|
||||
'2: arguments for the git worktree remove command (including the directory), defaults to the directory'
|
||||
)
|
||||
else
|
||||
core.setFailed(
|
||||
`Worktree input parsed as an array of length ${parsed.length}, correct lenghts are 1, 2, and 3.`
|
||||
)
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region github_token
|
||||
if (!getInput('github_token'))
|
||||
core.warning(
|
||||
|
||||
32
src/main.ts
32
src/main.ts
@@ -14,6 +14,27 @@ core.info(`Running in ${baseDir}`)
|
||||
await checkInputs()
|
||||
|
||||
core.startGroup('Internal logs')
|
||||
|
||||
let worktreeDir: string,
|
||||
worktreeAdd: string,
|
||||
worktreeRemove: string | undefined
|
||||
if (getInput('worktree')) {
|
||||
core.info('> Creating worktree...')
|
||||
;[worktreeDir, worktreeAdd, worktreeRemove] = parseInputArray(
|
||||
getInput('worktree') || ''
|
||||
)
|
||||
worktreeAdd = worktreeAdd || worktreeDir
|
||||
worktreeRemove = worktreeRemove || worktreeDir
|
||||
|
||||
core.debug(`Running: git worktree add ${worktreeAdd}`)
|
||||
await git
|
||||
.raw('worktree', 'add', ...worktreeAdd.split(' '))
|
||||
.then((data) => log(undefined, data))
|
||||
|
||||
core.info('> Changing working directory...')
|
||||
await git.cwd(worktreeDir)
|
||||
} else core.info('> Not creating a worktree.')
|
||||
|
||||
core.info('> Staging files...')
|
||||
|
||||
const ignoreErrors =
|
||||
@@ -198,6 +219,17 @@ core.info(`Running in ${baseDir}`)
|
||||
} else core.info('> No tags to push.')
|
||||
} else core.info('> Not pushing anything.')
|
||||
|
||||
if (worktreeRemove) {
|
||||
core.info('> Switching back to previous working directory...')
|
||||
await git.cwd(baseDir)
|
||||
|
||||
core.info('> Removing worktree...')
|
||||
core.debug(`Running: git worktree remove ${worktreeRemove}`)
|
||||
await git
|
||||
.raw('worktree', 'remove', worktreeRemove.split(' '))
|
||||
.then((data) => log(undefined, data))
|
||||
} else core.info('> No worktree to remove.')
|
||||
|
||||
core.endGroup()
|
||||
core.info('> Task completed.')
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user