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: The action provides these outputs:
- `committed`: whether the action has created a commit (`'true'` or `'false'`) - `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'`) - `pushed`: whether the action has pushed to the remote (`'true'` or `'false'`)
- `tagged`: whether the action has created a tag (`'true'` or `'false'`) - `tagged`: whether the action has created a tag (`'true'` or `'false'`)

View File

@@ -62,8 +62,10 @@ inputs:
outputs: outputs:
committed: committed:
description: Whether the action has created a commit. description: Whether the action has created a commit.
commit_long_sha:
description: The complete SHA of the commit that has been created.
commit_sha: commit_sha:
description: The SHA of the commit that has been created. description: The short SHA of the commit that has been created.
pushed: pushed:
description: Whether the action has pushed to the remote. description: Whether the action has pushed to the remote.
tagged: 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 { interface OutputTypes {
committed: 'true' | 'false' committed: 'true' | 'false'
commit_long_sha: string | undefined
commit_sha: string | undefined commit_sha: string | undefined
pushed: 'true' | 'false' pushed: 'true' | 'false'
tagged: 'true' | 'false' tagged: 'true' | 'false'
@@ -32,6 +33,7 @@ export type output = keyof OutputTypes
export const outputs: OutputTypes = { export const outputs: OutputTypes = {
committed: 'false', committed: 'false',
commit_long_sha: undefined,
commit_sha: undefined, commit_sha: undefined,
pushed: 'false', pushed: 'false',
tagged: 'false' tagged: 'false'

View File

@@ -1,6 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import path from 'path' 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 { checkInputs, getInput, logOutputs, setOutput } from './io'
import { log, matchGitArgs, parseInputArray } from './util' import { log, matchGitArgs, parseInputArray } from './util'
@@ -70,17 +70,20 @@ core.info(`Running in ${baseDir}`)
} else core.info('> Not pulling from repo.') } else core.info('> Not pulling from repo.')
core.info('> Creating commit...') core.info('> Creating commit...')
await git.commit( const commitData = await git
getInput('message'), .commit(getInput('message'), matchGitArgs(getInput('commit') || ''))
matchGitArgs(getInput('commit') || ''), .catch((err) => {
(err, data?: CommitSummary) => { log(err)
if (data) { })
setOutput('committed', 'true') if (commitData) {
setOutput('commit_sha', data.commit) log(undefined, commitData)
} setOutput('committed', 'true')
return log(err, data) 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')) { if (getInput('tag')) {
core.info('> Tagging commit...') core.info('> Tagging commit...')