Skip to content

Commit

Permalink
feat: add tag_push input and tag_pushed output (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndBug authored Mar 11, 2022
1 parent d67ae5f commit 0e4f5f6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ inputs:
tag:
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
required: false
tag_push:
description: Arguments for the git push --tags command (any additional argument will be added after --tags)
required: false

# Input not required from the user
github_token:
Expand All @@ -70,6 +73,8 @@ outputs:
description: Whether the action has pushed to the remote.
tagged:
description: Whether the action has created a tag.
tag_pushed:
description: Whether the action has pushed a tag.

runs:
using: node12
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface InputTypes {
push: string
remove: string | undefined
tag: string | undefined
tag_push: string | undefined

github_token: string | undefined
}
Expand All @@ -28,6 +29,7 @@ interface OutputTypes {
commit_sha: string | undefined
pushed: 'true' | 'false'
tagged: 'true' | 'false'
tag_pushed: 'true' | 'false'
}
export type output = keyof OutputTypes

Expand All @@ -36,7 +38,8 @@ export const outputs: OutputTypes = {
commit_long_sha: undefined,
commit_sha: undefined,
pushed: 'false',
tagged: 'false'
tagged: 'false',
tag_pushed: 'false'
}
// Setup default output values
Object.entries(outputs).forEach(([name, value]) => core.setOutput(name, value))
Expand Down
24 changes: 5 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,12 @@ core.info(`Running in ${baseDir}`)
if (getInput('tag')) {
core.info('> Pushing tags to repo...')
await git
.pushTags('origin', undefined, (e, d?) => log(undefined, e || d))
.catch(() => {
core.info(
'> Tag push failed: deleting remote tag and re-pushing...'
)
return git
.push(
undefined,
undefined,
{
'--delete': null,
origin: null,
[matchGitArgs(getInput('tag') || '').filter(
(w) => !w.startsWith('-')
)[0]]: null
},
log
)
.pushTags('origin', undefined, log)
.pushTags('origin', matchGitArgs(getInput('tag_push') || ''))
.then((data) => {
setOutput('tag_pushed', 'true')
return log(null, data)
})
.catch((err) => core.setFailed(err))
} else core.info('> No tags to push.')
} else core.info('> Not pushing anything.')

Expand Down

0 comments on commit 0e4f5f6

Please sign in to comment.