Skip to content

Commit

Permalink
feat: add commit_long_sha output (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndBug committed Jan 20, 2022
1 parent f016b26 commit 0e1feea
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -154,7 +154,8 @@ If you're getting this error and you're using `actions/checkout@v1`, try upgradi
The action provides these outputs:

- `committed`: whether the action has created a commit (`'true'` or `'false'`)
- `commit_sha`: the short 7-digit sha of the commit that has just been created
- `commit_long_sha`: the full SHA of the commit that has just been created
- `commit_sha`: the short 7-character SHA of the commit that has just been created
- `pushed`: whether the action has pushed to the remote (`'true'` or `'false'`)
- `tagged`: whether the action has created a tag (`'true'` or `'false'`)

Expand Down
4 changes: 3 additions & 1 deletion action.yml
Expand Up @@ -62,8 +62,10 @@ inputs:
outputs:
committed:
description: Whether the action has created a commit.
commit_long_sha:
description: The complete SHA of the commit that has been created.
commit_sha:
description: The SHA of the commit that has been created.
description: The short SHA of the commit that has been created.
pushed:
description: Whether the action has pushed to the remote.
tagged:
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/io.ts
Expand Up @@ -24,6 +24,7 @@ export type input = keyof InputTypes

interface OutputTypes {
committed: 'true' | 'false'
commit_long_sha: string | undefined
commit_sha: string | undefined
pushed: 'true' | 'false'
tagged: 'true' | 'false'
Expand All @@ -32,6 +33,7 @@ export type output = keyof OutputTypes

export const outputs: OutputTypes = {
committed: 'false',
commit_long_sha: undefined,
commit_sha: undefined,
pushed: 'false',
tagged: 'false'
Expand Down
27 changes: 15 additions & 12 deletions src/main.ts
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import path from 'path'
import simpleGit, { CommitSummary, Response } from 'simple-git'
import simpleGit, { Response } from 'simple-git'
import { checkInputs, getInput, logOutputs, setOutput } from './io'
import { log, matchGitArgs, parseInputArray } from './util'

Expand Down Expand Up @@ -70,17 +70,20 @@ core.info(`Running in ${baseDir}`)
} else core.info('> Not pulling from repo.')

core.info('> Creating commit...')
await git.commit(
getInput('message'),
matchGitArgs(getInput('commit') || ''),
(err, data?: CommitSummary) => {
if (data) {
setOutput('committed', 'true')
setOutput('commit_sha', data.commit)
}
return log(err, data)
}
)
const commitData = await git
.commit(getInput('message'), matchGitArgs(getInput('commit') || ''))
.catch((err) => {
log(err)
})
if (commitData) {
log(undefined, commitData)
setOutput('committed', 'true')
setOutput('commit_sha', commitData.commit)
await git
.revparse(commitData.commit)
.then((long_sha) => setOutput('commit_long_sha', long_sha))
.catch((err) => core.warning(`Couldn't parse long SHA:\n${err}`))
}

if (getInput('tag')) {
core.info('> Tagging commit...')
Expand Down

0 comments on commit 0e1feea

Please sign in to comment.