Created
February 9, 2021 10:08
-
-
Save AlaeddineMessadi/3491759f0a60df402599f9c79fabb126 to your computer and use it in GitHub Desktop.
Get the latest git SHA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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