Merge pull request #84 from github/remove_git_dependency
Fall back to GITHUB_SHA env var if git is not available
This commit is contained in:
commit
96d02d50f7
3 changed files with 44 additions and 19 deletions
31
lib/util.js
generated
31
lib/util.js
generated
|
|
@ -140,15 +140,28 @@ exports.getLanguages = getLanguages;
|
||||||
* Gets the SHA of the commit that is currently checked out.
|
* Gets the SHA of the commit that is currently checked out.
|
||||||
*/
|
*/
|
||||||
async function getCommitOid() {
|
async function getCommitOid() {
|
||||||
let commitOid = '';
|
// Try to use git to get the current commit SHA. If that fails then
|
||||||
await exec.exec('git', ['rev-parse', 'HEAD'], {
|
// log but otherwise silently fall back to using the SHA from the environment.
|
||||||
silent: true,
|
// The only time these two values will differ is during analysis of a PR when
|
||||||
listeners: {
|
// the workflow has changed the current commit to the head commit instead of
|
||||||
stdout: (data) => { commitOid += data.toString(); },
|
// the merge commit, which must mean that git is available.
|
||||||
stderr: (data) => { process.stderr.write(data); }
|
// Even if this does go wrong, it's not a huge problem for the alerts to
|
||||||
}
|
// reported on the merge commit.
|
||||||
});
|
try {
|
||||||
return commitOid.trim();
|
let commitOid = '';
|
||||||
|
await exec.exec('git', ['rev-parse', 'HEAD'], {
|
||||||
|
silent: true,
|
||||||
|
listeners: {
|
||||||
|
stdout: (data) => { commitOid += data.toString(); },
|
||||||
|
stderr: (data) => { process.stderr.write(data); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return commitOid.trim();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
core.info("Failed to call git to get current commit. Continuing with data from environment: " + e);
|
||||||
|
return getRequiredEnvParam('GITHUB_SHA');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.getCommitOid = getCommitOid;
|
exports.getCommitOid = getCommitOid;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
30
src/util.ts
30
src/util.ts
|
|
@ -139,15 +139,27 @@ export async function getLanguages(): Promise<string[]> {
|
||||||
* Gets the SHA of the commit that is currently checked out.
|
* Gets the SHA of the commit that is currently checked out.
|
||||||
*/
|
*/
|
||||||
export async function getCommitOid(): Promise<string> {
|
export async function getCommitOid(): Promise<string> {
|
||||||
let commitOid = '';
|
// Try to use git to get the current commit SHA. If that fails then
|
||||||
await exec.exec('git', ['rev-parse', 'HEAD'], {
|
// log but otherwise silently fall back to using the SHA from the environment.
|
||||||
silent: true,
|
// The only time these two values will differ is during analysis of a PR when
|
||||||
listeners: {
|
// the workflow has changed the current commit to the head commit instead of
|
||||||
stdout: (data) => { commitOid += data.toString(); },
|
// the merge commit, which must mean that git is available.
|
||||||
stderr: (data) => { process.stderr.write(data); }
|
// Even if this does go wrong, it's not a huge problem for the alerts to
|
||||||
}
|
// reported on the merge commit.
|
||||||
});
|
try {
|
||||||
return commitOid.trim();
|
let commitOid = '';
|
||||||
|
await exec.exec('git', ['rev-parse', 'HEAD'], {
|
||||||
|
silent: true,
|
||||||
|
listeners: {
|
||||||
|
stdout: (data) => { commitOid += data.toString(); },
|
||||||
|
stderr: (data) => { process.stderr.write(data); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return commitOid.trim();
|
||||||
|
} catch (e) {
|
||||||
|
core.info("Failed to call git to get current commit. Continuing with data from environment: " + e);
|
||||||
|
return getRequiredEnvParam('GITHUB_SHA');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue