Skip to content

Commit 5c82f36

Browse files
authored
Add commit_sha output (#275)
* feat: add commit_sha output * docs(README): add docs for commit_sha
1 parent c5fa676 commit 5c82f36

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ If you're getting this error and you're using `actions/checkout@v1`, try upgradi
130130
The action provides these outputs:
131131

132132
- `committed`: whether the action has created a commit (`'true'` or `'false'`)
133+
- `commit_sha`: the short 7-digit sha of the commit that has just been created
133134
- `pushed`: whether the action has pushed to the remote (`'true'` or `'false'`)
134135
- `tagged`: whether the action has created a tag (`'true'` or `'false'`)
135136

@@ -164,7 +165,6 @@ You can also use the `committer_name` and `committer_email` inputs to make it ap
164165
committer_email: [email protected]
165166
```
166167

167-
168168
<img src="https://user-images.githubusercontent.com/26386270/130594443-b881fae7-3064-4020-a4cc-6db37ef0df65.png" height=70/>
169169

170170
```yaml
@@ -175,7 +175,6 @@ You can also use the `committer_name` and `committer_email` inputs to make it ap
175175
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
176176
```
177177

178-
179178
Do you want to lint your JavaScript files, located in the `src` folder, with ESLint, so that fixable changes are done without your intervention? You can use a workflow like this:
180179

181180
```yaml
@@ -238,8 +237,6 @@ jobs:
238237
cwd: './pathToRepo/'
239238
```
240239

241-
242-
243240
## Contributors ✨
244241

245242
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ inputs:
5959
outputs:
6060
committed:
6161
description: Whether the action has created a commit.
62+
commit_sha:
63+
description: The SHA of the commit that has been created.
6264
pushed:
6365
description: Whether the action has pushed to the remote.
6466
tagged:

lib/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 6 additions & 3 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, { Response } from 'simple-git'
3+
import simpleGit, { CommitSummary, Response } from 'simple-git'
44
import YAML from 'js-yaml'
55
import {
66
getInput,
@@ -85,8 +85,11 @@ core.info(`Running in ${baseDir}`)
8585
}
8686
: {})
8787
},
88-
(err, data?) => {
89-
if (data) setOutput('committed', 'true')
88+
(err, data?: CommitSummary) => {
89+
if (data) {
90+
setOutput('committed', 'true')
91+
setOutput('commit_sha', data.commit)
92+
}
9093
return log(err, data)
9194
}
9295
)

src/util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type Input =
2020
| 'tag'
2121
| 'github_token'
2222

23-
export type Output = 'committed' | 'pushed' | 'tagged'
23+
export type Output = 'committed' | 'commit_sha' | 'pushed' | 'tagged'
2424

2525
type RecordOf<T extends string> = Record<T, string | undefined>
2626
export const tools = new Toolkit<RecordOf<Input>, RecordOf<Output>>({
@@ -31,8 +31,9 @@ export const tools = new Toolkit<RecordOf<Input>, RecordOf<Output>>({
3131
'GITHUB_ACTOR'
3232
]
3333
})
34-
export const outputs: Record<Output, 'true' | 'false'> = {
34+
export const outputs: Record<Output, any> = {
3535
committed: 'false',
36+
commit_sha: undefined,
3637
pushed: 'false',
3738
tagged: 'false'
3839
}

0 commit comments

Comments
 (0)