Skip to content

Commit a9697fe

Browse files
committed
Use sha of HEAD (in case users check out different branch)
Use this instead of GITHUB_SHA, which is often the same as master instead of the target branch (e.g. is a user runs checkout with a different ref)
1 parent 41aaa78 commit a9697fe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: action/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
4545

4646
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
4747
const GITHUB_EVENT_PATH = process.env.GITHUB_EVENT_PATH;
48-
const GITHUB_SHA = process.env.GITHUB_SHA;
4948
const GITHUB_ACTOR = process.env.GITHUB_ACTOR;
5049

5150
// Error messages
@@ -201,6 +200,9 @@ const writeToProcess = (command: string, args: string[], opts: {env: { [id: stri
201200
await exec(`git config --global user.name "${name}"`);
202201
await exec(`git config --global user.email "${email}"`);
203202

203+
// Get current sha of repo to use in commit message
204+
const sha = (await exec(`git rev-parse HEAD`)).stdout.trim().substr(0, 7);
205+
204206
// Environment to pass to children
205207
const env = Object.assign({}, process.env, {
206208
SSH_AUTH_SOCK
@@ -287,7 +289,6 @@ const writeToProcess = (command: string, args: string[], opts: {env: { [id: stri
287289
// TODO: replace this copy with a node implementation
288290
await exec(`cp -r ${folder}/* ./`, { env, cwd: REPO_TEMP });
289291
await exec(`git add -A .`, { env, cwd: REPO_TEMP });
290-
const sha = GITHUB_SHA ? GITHUB_SHA.substr(0, 7) : 'unknown';
291292
await exec(`git commit --allow-empty -m "Update ${config.branch} to output generated at ${sha}"`, { env, cwd: REPO_TEMP });
292293
console.log(`##[info] Pushing`);
293294
const push = await exec(`git push origin "${config.branch}"`, { env, cwd: REPO_TEMP });

0 commit comments

Comments
 (0)