feat: add commit_long_sha output (#349)

This commit is contained in:
Federico Grandi
2022-01-20 13:18:16 +01:00
committed by GitHub
parent f016b267be
commit 0e1feea77e
5 changed files with 23 additions and 15 deletions

View File

@@ -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'`)

View File

@@ -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:

2
lib/index.js generated

File diff suppressed because one or more lines are too long

View File

@@ -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'
@@ -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'

View File

@@ -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'
@@ -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...')