From a0d94c7b00bbb7bbad6545de2268aada9293933e Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Sun, 11 Oct 2020 15:57:30 +0900 Subject: [PATCH] feat: dst_sha --- action.yml | 3 +++ src/git-utils.ts | 18 +++++++++++++++++- src/main.ts | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 175640d..eee9cbf 100644 --- a/action.yml +++ b/action.yml @@ -77,3 +77,6 @@ inputs: description: 'Set files or directories to exclude from a publish directory.' required: false default: '.github' +outputs: + dst_sha: + description: 'Deployed commit hash.' diff --git a/src/git-utils.ts b/src/git-utils.ts index 6d417e9..156280e 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -190,16 +190,32 @@ export function getCommitMessage( return subject; } -export async function commit(allowEmptyCommit: boolean, msg: string): Promise { +export async function commit(allowEmptyCommit: boolean, msg: string): Promise { try { if (allowEmptyCommit) { await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]); } else { await exec.exec('git', ['commit', '-m', `${msg}`]); } + + const result: CmdResult = { + exitcode: 0, + output: '' + }; + const options = { + listeners: { + stdout: (data: Buffer): void => { + result.output += data.toString(); + } + } + }; + result.exitcode = await exec.exec('git', ['rev-parse', 'HEAD'], options); + + return result.output; } catch (e) { core.info('[INFO] skip commit'); core.debug(`[INFO] skip commit ${e.message}`); + return ''; } } diff --git a/src/main.ts b/src/main.ts index 6ddf944..e49ad2e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -75,7 +75,8 @@ export async function run(): Promise { baseRepo, hash ); - await commit(inps.AllowEmptyCommit, commitMessage); + const dstSHA = await commit(inps.AllowEmptyCommit, commitMessage); + core.setOutput('dst_sha', dstSHA); core.endGroup(); core.startGroup('Push the commit or tag');