Skip to content

Commit b369695

Browse files
committed
feat(push): add push option
re #86
1 parent 0c6f4a1 commit b369695

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ inputs:
2626
description: The flag used on the pull strategy
2727
required: false
2828
default: '--no-rebase'
29+
push:
30+
description: Whether to push the commit to the repo
31+
required: false
2932
remove:
3033
description: Arguments for the git rm command
3134
required: false

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// WARNING: this file is auto-generated by scripts/inputs.ts (npm run inputs), any manual edit will be overwritten.
22

3-
export type Input = 'add' | 'author_name' | 'author_email' | 'branch' | 'cwd' | 'message' | 'pull_strategy' | 'remove' | 'signoff' | 'tag'
3+
export type Input = 'add' | 'author_name' | 'author_email' | 'branch' | 'cwd' | 'message' | 'pull_strategy' | 'push' | 'remove' | 'signoff' | 'tag'

src/main.ts

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,23 @@ console.log(`Running in ${baseDir}`);
6666
await git.tag(getInput('tag').split(' '), log)
6767
} else info('> No tag info provided.')
6868

69-
info('> Pushing commit to repo...')
70-
await git.push('origin', getInput('branch'), { '--set-upstream': null }, log)
71-
72-
if (getInput('tag')) {
73-
info('> Pushing tags to repo...')
74-
await git.pushTags('origin', (e, d?) => log(undefined, e || d)).catch(() => {
75-
info('> Tag push failed: deleting remote tag and re-pushing...')
76-
return git.push(undefined, undefined, {
77-
'--delete': null,
78-
'origin': null,
79-
[getInput('tag').split(' ').filter(w => !w.startsWith('-'))[0]]: null
80-
}, log)
81-
.pushTags('origin', log)
82-
})
83-
} else info('> No tags to push.')
69+
if (getInput('push')) {
70+
info('> Pushing commit to repo...')
71+
await git.push('origin', getInput('branch'), { '--set-upstream': null }, log)
72+
73+
if (getInput('tag')) {
74+
info('> Pushing tags to repo...')
75+
await git.pushTags('origin', (e, d?) => log(undefined, e || d)).catch(() => {
76+
info('> Tag push failed: deleting remote tag and re-pushing...')
77+
return git.push(undefined, undefined, {
78+
'--delete': null,
79+
'origin': null,
80+
[getInput('tag').split(' ').filter(w => !w.startsWith('-'))[0]]: null
81+
}, log)
82+
.pushTags('origin', log)
83+
})
84+
} else info('> No tags to push.')
85+
} else info('> Not pushing anything.')
8486

8587
endGroup()
8688
info('> Task completed.')
@@ -175,13 +177,32 @@ async function checkInputs() {
175177
// #endregion
176178

177179
// #region signoff
178-
if (getInput('signoff')) try {
179-
const parsed = JSON.parse(getInput('signoff'))
180-
if (typeof parsed == 'boolean' && !parsed)
180+
if (getInput('signoff')) {
181+
const parsed = parseBool(getInput('signoff'))
182+
183+
if (parsed === undefined)
184+
throw new Error(`"${getInput('signoff')}" is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`)
185+
186+
if (!parsed)
181187
setInput('signoff', undefined)
188+
182189
debug(`Current signoff option: ${getInput('signoff')} (${typeof getInput('signoff')})`)
183-
} catch {
184-
throw new Error(`"${getInput('signoff')}" is not a valid value for the 'signoff' input: only "true" and "false" are allowed.`)
190+
}
191+
192+
// #endregion
193+
194+
// #region push
195+
setDefault('push', 'true')
196+
if (getInput('push')) { // It's just to scope the parsed constant
197+
const parsed = parseBool(getInput('push'))
198+
199+
if (parsed === undefined)
200+
throw new Error(`"${getInput('push')}" is not a valid value for the 'push' input: only "true" and "false" are allowed.`)
201+
202+
if (!parsed)
203+
setInput('push', undefined)
204+
205+
debug(`Current push option: ${getInput('push')} (${typeof getInput('push')})`)
185206
}
186207
// #endregion
187208
}
@@ -190,6 +211,14 @@ function getInput(name: Input) {
190211
return getInputCore(name)
191212
}
192213

214+
function parseBool(value: any) {
215+
try {
216+
const parsed = JSON.parse(value)
217+
if (typeof parsed == 'boolean')
218+
return parsed
219+
} catch { }
220+
}
221+
193222
function log(err: any | Error, data?: any) {
194223
if (data) console.log(data)
195224
if (err) error(err)

0 commit comments

Comments
 (0)