feat: dst_sha

This commit is contained in:
peaceiris 2020-10-11 15:57:30 +09:00
parent 25e5ffa147
commit a0d94c7b00
No known key found for this signature in database
GPG Key ID: 5868468A8EBA64EC
3 changed files with 22 additions and 2 deletions

View File

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

View File

@ -190,16 +190,32 @@ export function getCommitMessage(
return subject;
}
export async function commit(allowEmptyCommit: boolean, msg: string): Promise<void> {
export async function commit(allowEmptyCommit: boolean, msg: string): Promise<string> {
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 '';
}
}

View File

@ -75,7 +75,8 @@ export async function run(): Promise<void> {
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');