feat(push): add push option

re #86
This commit is contained in:
Federico Grandi
2020-11-11 18:11:50 +01:00
parent 0c6f4a1284
commit b36969554e
4 changed files with 53 additions and 21 deletions

View File

@@ -26,6 +26,9 @@ inputs:
description: The flag used on the pull strategy
required: false
default: '--no-rebase'
push:
description: Whether to push the commit to the repo
required: false
remove:
description: Arguments for the git rm command
required: false

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,3 @@
// WARNING: this file is auto-generated by scripts/inputs.ts (npm run inputs), any manual edit will be overwritten.
export type Input = 'add' | 'author_name' | 'author_email' | 'branch' | 'cwd' | 'message' | 'pull_strategy' | 'remove' | 'signoff' | 'tag'
export type Input = 'add' | 'author_name' | 'author_email' | 'branch' | 'cwd' | 'message' | 'pull_strategy' | 'push' | 'remove' | 'signoff' | 'tag'

View File

@@ -66,21 +66,23 @@ console.log(`Running in ${baseDir}`);
await git.tag(getInput('tag').split(' '), log)
} else info('> No tag info provided.')
info('> Pushing commit to repo...')
await git.push('origin', getInput('branch'), { '--set-upstream': null }, log)
if (getInput('push')) {
info('> Pushing commit to repo...')
await git.push('origin', getInput('branch'), { '--set-upstream': null }, log)
if (getInput('tag')) {
info('> Pushing tags to repo...')
await git.pushTags('origin', (e, d?) => log(undefined, e || d)).catch(() => {
info('> Tag push failed: deleting remote tag and re-pushing...')
return git.push(undefined, undefined, {
'--delete': null,
'origin': null,
[getInput('tag').split(' ').filter(w => !w.startsWith('-'))[0]]: null
}, log)
.pushTags('origin', log)
})
} else info('> No tags to push.')
if (getInput('tag')) {
info('> Pushing tags to repo...')
await git.pushTags('origin', (e, d?) => log(undefined, e || d)).catch(() => {
info('> Tag push failed: deleting remote tag and re-pushing...')
return git.push(undefined, undefined, {
'--delete': null,
'origin': null,
[getInput('tag').split(' ').filter(w => !w.startsWith('-'))[0]]: null
}, log)
.pushTags('origin', log)
})
} else info('> No tags to push.')
} else info('> Not pushing anything.')
endGroup()
info('> Task completed.')
@@ -175,13 +177,32 @@ async function checkInputs() {
// #endregion
// #region signoff
if (getInput('signoff')) try {
const parsed = JSON.parse(getInput('signoff'))
if (typeof parsed == 'boolean' && !parsed)
if (getInput('signoff')) {
const parsed = parseBool(getInput('signoff'))
if (parsed === undefined)
throw new Error(`"${getInput('signoff')}" is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`)
if (!parsed)
setInput('signoff', undefined)
debug(`Current signoff option: ${getInput('signoff')} (${typeof getInput('signoff')})`)
} catch {
throw new Error(`"${getInput('signoff')}" is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`)
}
// #endregion
// #region push
setDefault('push', 'true')
if (getInput('push')) { // It's just to scope the parsed constant
const parsed = parseBool(getInput('push'))
if (parsed === undefined)
throw new Error(`"${getInput('push')}" is not a valid value for the 'push' input: only "true" and "false" are allowed.`)
if (!parsed)
setInput('push', undefined)
debug(`Current push option: ${getInput('push')} (${typeof getInput('push')})`)
}
// #endregion
}
@@ -190,6 +211,14 @@ function getInput(name: Input) {
return getInputCore(name)
}
function parseBool(value: any) {
try {
const parsed = JSON.parse(value)
if (typeof parsed == 'boolean')
return parsed
} catch { }
}
function log(err: any | Error, data?: any) {
if (data) console.log(data)
if (err) error(err)