Skip to content

Instantly share code, notes, and snippets.

@AlaeddineMessadi
Created February 9, 2021 10:08
Show Gist options
  • Save AlaeddineMessadi/3491759f0a60df402599f9c79fabb126 to your computer and use it in GitHub Desktop.
Save AlaeddineMessadi/3491759f0a60df402599f9c79fabb126 to your computer and use it in GitHub Desktop.
Get the latest git SHA
/** Vercel they provide some environment variables you could use to get the latest Git SHA: */
const COMMIT_SHA =
VERCEL_GITHUB_COMMIT_SHA ||
VERCEL_GITLAB_COMMIT_SHA ||
VERCEL_BITBUCKET_COMMIT_SHA
/** Otherwise you'd need to get it yourself */
const cp = require('child_process');
const gitSha = cp.execSync('git rev-parse HEAD', {
cwd: __dirname,
encoding: 'utf8'
});
/** or the short version of the SHA */
const cp = require('child_process');
const gitSha = cp.execSync('git rev-parse --short HEAD', {
cwd: __dirname,
encoding: 'utf8'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment