Skip to content

Commit 5aa789a

Browse files
committed
Return the current commit SHA if no new commit was created.
1 parent a498ab9 commit 5aa789a

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

commit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ steps:
3535

3636
### Outputs
3737

38-
- `commit-sha` — The SHA of the created commit. Empty when `committed` is `false`.
38+
- `commit-sha` — The SHA of the created commit, or the current commit SHA if no new commit was created.
3939
- `committed` — `'true'` when a commit was created, `'false'` when there were no changes to commit.
4040

4141
### Example: commit to a new branch

commit/index.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ export async function main({ github, env, core }: { github: Octokit, env: Record
9292

9393
if (fileChanges.additions.length === 0 && fileChanges.deletions.length === 0) {
9494
core.info('no staged changes — skipping commit');
95+
const currentHeadSha = (await exec('git rev-parse HEAD', { encoding: 'utf8' })).stdout.trim();
9596
core.setOutput('committed', 'false');
96-
core.setOutput('commit-sha', '');
97+
core.setOutput('commit-sha', currentHeadSha);
9798
return;
9899
}
99100

commit/index.test.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ describe('signed commit action', () => {
128128
const graphql = vi.fn();
129129
const fakeGithub = { graphql };
130130

131+
const headSha = (await doExec('git rev-parse HEAD')).stdout.trim();
132+
131133
const originalCwd = process.cwd();
132134
try {
133135
process.chdir(repoDir);
@@ -147,7 +149,7 @@ describe('signed commit action', () => {
147149

148150
expect(graphql).not.toHaveBeenCalled();
149151
expect(outputs.committed).toEqual('false');
150-
expect(outputs['commit-sha']).toEqual('');
152+
expect(outputs['commit-sha']).toEqual(headSha);
151153
});
152154

153155
it('checks file modes and does not throw when correct', async () => {

0 commit comments

Comments
 (0)