Skip to content

Commit 0e1feea

Browse files
authored
feat: add commit_long_sha output (#349)
1 parent f016b26 commit 0e1feea

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ If you're getting this error and you're using `actions/checkout@v1`, try upgradi
154154
The action provides these outputs:
155155

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

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ inputs:
6262
outputs:
6363
committed:
6464
description: Whether the action has created a commit.
65+
commit_long_sha:
66+
description: The complete SHA of the commit that has been created.
6567
commit_sha:
66-
description: The SHA of the commit that has been created.
68+
description: The short SHA of the commit that has been created.
6769
pushed:
6870
description: Whether the action has pushed to the remote.
6971
tagged:

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/io.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export type input = keyof InputTypes
2424

2525
interface OutputTypes {
2626
committed: 'true' | 'false'
27+
commit_long_sha: string | undefined
2728
commit_sha: string | undefined
2829
pushed: 'true' | 'false'
2930
tagged: 'true' | 'false'
@@ -32,6 +33,7 @@ export type output = keyof OutputTypes
3233

3334
export const outputs: OutputTypes = {
3435
committed: 'false',
36+
commit_long_sha: undefined,
3537
commit_sha: undefined,
3638
pushed: 'false',
3739
tagged: 'false'

src/main.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core'
22
import path from 'path'
3-
import simpleGit, { CommitSummary, Response } from 'simple-git'
3+
import simpleGit, { Response } from 'simple-git'
44
import { checkInputs, getInput, logOutputs, setOutput } from './io'
55
import { log, matchGitArgs, parseInputArray } from './util'
66

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

7272
core.info('> Creating commit...')
73-
await git.commit(
74-
getInput('message'),
75-
matchGitArgs(getInput('commit') || ''),
76-
(err, data?: CommitSummary) => {
77-
if (data) {
78-
setOutput('committed', 'true')
79-
setOutput('commit_sha', data.commit)
80-
}
81-
return log(err, data)
82-
}
83-
)
73+
const commitData = await git
74+
.commit(getInput('message'), matchGitArgs(getInput('commit') || ''))
75+
.catch((err) => {
76+
log(err)
77+
})
78+
if (commitData) {
79+
log(undefined, commitData)
80+
setOutput('committed', 'true')
81+
setOutput('commit_sha', commitData.commit)
82+
await git
83+
.revparse(commitData.commit)
84+
.then((long_sha) => setOutput('commit_long_sha', long_sha))
85+
.catch((err) => core.warning(`Couldn't parse long SHA:\n${err}`))
86+
}
8487

8588
if (getInput('tag')) {
8689
core.info('> Tagging commit...')

0 commit comments

Comments
 (0)