Rewrite the ref to correctly point to refs/remotes

Fixes the rev-parse issues caused by https://github.com/github/codeql-action/pull/428
This commit is contained in:
Simon Engledew
2021-03-25 12:47:36 +00:00
parent 972dc3e3f9
commit ba14abbca7
6 changed files with 11 additions and 6 deletions

View File

@@ -40,7 +40,7 @@ test("getRef() returns merge PR ref if GITHUB_REF still checked out but sha has
const sha = "a".repeat(40);
const callback = sinon.stub(actionsutil, "getCommitOid");
callback.withArgs("refs/pull/1/merge").resolves(sha);
callback.withArgs("refs/remotes/pull/1/merge").resolves(sha);
callback.withArgs("HEAD").resolves(sha);
const actualRef = await actionsutil.getRef();

View File

@@ -443,7 +443,10 @@ export async function getRef(): Promise<string> {
// using GITHUB_REF. There is a subtle race condition where
// git rev-parse GITHUB_REF != GITHUB_SHA, so we must check
// git git-parse GITHUB_REF == git rev-parse HEAD instead.
const hasChangedRef = sha !== head && (await getCommitOid(ref)) !== head;
const hasChangedRef =
sha !== head &&
(await getCommitOid(ref.replace(/^refs\/pull\//, "refs/remotes/pull/"))) !==
head;
if (hasChangedRef) {
const newRef = ref.replace(pull_ref_regex, "refs/pull/$1/head");