Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6fc72c1
Add basic Rust support for internal testing
Sep 18, 2024
a66a5fe
Bump the npm group with 3 updates
dependabot[bot] Oct 2, 2024
f0c7f1d
Update checked-in dependencies
github-actions[bot] Oct 2, 2024
08bec82
Update default bundle to codeql-bundle-v2.19.1
github-actions[bot] Oct 2, 2024
4beccf7
Add changelog note
github-actions[bot] Oct 2, 2024
868284b
Merge branch 'main' into update-bundle/codeql-bundle-v2.19.1
angelapwen Oct 3, 2024
35de01e
Update supported GitHub Enterprise Server versions
github-actions[bot] Oct 3, 2024
15f615c
Add a deprecation warning for CodeQL <=2.14.5
henrymercer Oct 3, 2024
01007b8
Fix new lines in update supported GHES versions PR
henrymercer Oct 3, 2024
955d001
Extract runGitCommand()
cklin Oct 3, 2024
d64cca4
Rename determineMergeBaseCommitOid()
cklin Oct 3, 2024
495ca58
Update changelog and version after v3.26.11
github-actions[bot] Oct 3, 2024
a83506b
Update checked-in dependencies
github-actions[bot] Oct 3, 2024
15649f6
Mergeback v3.26.11 refs/heads/releases/v3 into main (#2523)
angelapwen Oct 3, 2024
8b33300
Merge pull request #2521 from github/cklin/run-git-command
cklin Oct 3, 2024
873c91c
Update README with detailed information
aeisenberg Aug 7, 2024
c768f67
Clean up README
aeisenberg Aug 9, 2024
3b143d4
Update readme
aeisenberg Oct 3, 2024
bed2a47
Update autobuild/action.yml
aeisenberg Oct 4, 2024
76aafb9
Merge pull request #2520 from github/update-supported-enterprise-serv…
henrymercer Oct 4, 2024
6c8758f
Fix changelog note section
henrymercer Oct 4, 2024
215ff9c
Merge pull request #2525 from github/henrymercer/fix-changelog-section
henrymercer Oct 4, 2024
46d955c
Merge pull request #2415 from aeisenberg/aeisenberg/update-readme-1
aeisenberg Oct 4, 2024
057e1ec
Check zstd is on the path in addition to tar version
henrymercer Oct 4, 2024
64871a8
Merge branch 'main' into update-bundle/codeql-bundle-v2.19.1
angelapwen Oct 4, 2024
1532671
Update default bundle to 2.19.1 (#2519)
angelapwen Oct 4, 2024
8a56dd2
Update to @actions/core 1.11.1
aeisenberg Oct 4, 2024
7cf65a5
Merge pull request #2518 from github/dependabot/npm_and_yarn/npm-8815…
aeisenberg Oct 4, 2024
56d1975
Merge pull request #2489 from github/redsun82/rust
redsun82 Oct 7, 2024
bf2e624
Update src/tar.ts
henrymercer Oct 7, 2024
d65a176
Rebuild
github-actions[bot] Oct 7, 2024
c9a70ff
Merge pull request #2526 from github/henrymercer/check-zstd-on-path
henrymercer Oct 7, 2024
570aecb
Update changelog for v3.26.12
github-actions[bot] Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract runGitCommand()
  • Loading branch information
cklin committed Oct 3, 2024
commit 955d00143d6ac6fbf4e837e0cb1d38978b28ce60
95 changes: 43 additions & 52 deletions lib/actions-util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions lib/actions-util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/actions-util.test.js.map

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions src/actions-util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ test("determineMergeBaseCommitOid non-pullrequest", async (t) => {
infoStub.restore();
});

test("determineMergeBaseCommitOid no error", async (t) => {
test("determineMergeBaseCommitOid not git repository", async (t) => {
const infoStub = sinon.stub(core, "info");

process.env["GITHUB_EVENT_NAME"] = "pull_request";
Expand All @@ -292,11 +292,12 @@ test("determineMergeBaseCommitOid no error", async (t) => {
});

t.deepEqual(1, infoStub.callCount);
t.assert(
infoStub.firstCall.args[0].startsWith(
t.deepEqual(
infoStub.firstCall.args[0],
"git call failed. Will calculate the base branch SHA on the server. Error: " +
"The checkout path provided to the action does not appear to be a git repository.",
),
);

infoStub.restore();
});

Expand All @@ -312,7 +313,12 @@ test("determineMergeBaseCommitOid other error", async (t) => {
t.deepEqual(1, infoStub.callCount);
t.assert(
infoStub.firstCall.args[0].startsWith(
"Failed to call git to determine merge base.",
"git call failed. Will calculate the base branch SHA on the server. Error: ",
),
);
t.assert(
!infoStub.firstCall.args[0].endsWith(
"The checkout path provided to the action does not appear to be a git repository.",
),
);

Expand Down
117 changes: 53 additions & 64 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@ export function getTemporaryDirectory(): string {
: getRequiredEnvParam("RUNNER_TEMP");
}

async function runGitCommand(
checkoutPath: string | undefined,
args: string[],
customErrorMessage: string,
): Promise<string> {
let stdout = "";
let stderr = "";
try {
await new toolrunner.ToolRunner(await safeWhich.safeWhich("git"), args, {
silent: true,
listeners: {
stdout: (data) => {
stdout += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
cwd: checkoutPath,
}).exec();
return stdout;
} catch (error) {
let reason = stderr;
if (stderr.includes("not a git repository")) {
reason =
"The checkout path provided to the action does not appear to be a git repository.";
}
core.info(`git call failed. ${customErrorMessage} Error: ${reason}`);
throw error;
}
}

/**
* Gets the SHA of the commit that is currently checked out.
*/
Expand All @@ -63,38 +95,14 @@ export const getCommitOid = async function (
// the merge commit, which must mean that git is available.
// Even if this does go wrong, it's not a huge problem for the alerts to
// reported on the merge commit.
let stderr = "";
try {
let commitOid = "";
await new toolrunner.ToolRunner(
await safeWhich.safeWhich("git"),
const stdout = await runGitCommand(
checkoutPath,
["rev-parse", ref],
{
silent: true,
listeners: {
stdout: (data) => {
commitOid += data.toString();
},
stderr: (data) => {
stderr += data.toString();
},
},
cwd: checkoutPath,
},
).exec();
return commitOid.trim();
"Continuing with commit SHA from user input or environment.",
);
return stdout.trim();
} catch {
if (stderr.includes("not a git repository")) {
core.info(
"Could not determine current commit SHA using git. Continuing with data from user input or environment. " +
"The checkout path provided to the action does not appear to be a git repository.",
);
} else {
core.info(
`Could not determine current commit SHA using git. Continuing with data from user input or environment. ${stderr}`,
);
}

return getOptionalInput("sha") || getRequiredEnvParam("GITHUB_SHA");
}
};
Expand All @@ -113,37 +121,29 @@ export const determineMergeBaseCommitOid = async function (
const mergeSha = getRequiredEnvParam("GITHUB_SHA");
const checkoutPath =
checkoutPathOverride ?? getOptionalInput("checkout_path");
let stderr = "";

try {
let commitOid = "";
let baseOid = "";
let headOid = "";

await new toolrunner.ToolRunner(
await safeWhich.safeWhich("git"),
const stdout = await runGitCommand(
checkoutPath,
["show", "-s", "--format=raw", mergeSha],
{
silent: true,
listeners: {
stdline: (data) => {
if (data.startsWith("commit ") && commitOid === "") {
commitOid = data.substring(7);
} else if (data.startsWith("parent ")) {
if (baseOid === "") {
baseOid = data.substring(7);
} else if (headOid === "") {
headOid = data.substring(7);
}
}
},
stderr: (data) => {
stderr += data.toString();
},
},
cwd: checkoutPath,
},
).exec();
"Will calculate the base branch SHA on the server.",
);

for (const data of stdout.split("\n")) {
if (data.startsWith("commit ") && commitOid === "") {
commitOid = data.substring(7);
} else if (data.startsWith("parent ")) {
if (baseOid === "") {
baseOid = data.substring(7);
} else if (headOid === "") {
headOid = data.substring(7);
}
}
}

// Let's confirm our assumptions: We had a merge commit and the parsed parent data looks correct
if (
Expand All @@ -155,17 +155,6 @@ export const determineMergeBaseCommitOid = async function (
}
return undefined;
} catch {
if (stderr.includes("not a git repository")) {
core.info(
"The checkout path provided to the action does not appear to be a git repository. " +
"Will calculate the merge base on the server.",
);
} else {
core.info(
`Failed to call git to determine merge base. Will calculate the merge base on ` +
`the server. Reason: ${stderr}`,
);
}
return undefined;
}
};
Expand Down