Skip to content

Commit

Permalink
Use the --resolve-query-specs parameter of pack download
Browse files Browse the repository at this point in the history
This will allow the command to resolve packs with paths.

Also, use a more concise version of `tr`.
  • Loading branch information
Andrew Eisenberg committed Apr 29, 2022
1 parent 06b15c2 commit 922dc2b
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/__packaging-config-inputs-js.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/__packaging-config-js.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/__packaging-inputs-js.yml

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

2 changes: 1 addition & 1 deletion .github/workflows/__split-workflow.yml

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

11 changes: 1 addition & 10 deletions lib/analyze.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/analyze.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/codeql.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/codeql.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pr-checks/checks/packaging-config-inputs-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/other-query-block javascript/example/two-block"
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | tr "\r" " " | xargs)"
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort tr "\n\r" " " | | xargs)"
echo "Found matching rules '$RULES'"
if [ "$RULES" != "$EXPECTED_RULES" ]; then
echo "Did not match expected rules '$EXPECTED_RULES'."
Expand Down
2 changes: 1 addition & 1 deletion pr-checks/checks/packaging-config-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ steps:
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/other-query-block javascript/example/two-block"
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | tr "\r" " " | xargs)"
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort tr "\n\r" " " | | xargs)"
echo "Found matching rules '$RULES'"
if [ "$RULES" != "$EXPECTED_RULES" ]; then
echo "Did not match expected rules '$EXPECTED_RULES'."
Expand Down
2 changes: 1 addition & 1 deletion pr-checks/checks/packaging-inputs-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ steps:
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/other-query-block javascript/example/two-block"
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | tr "\r" " " | xargs)"
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort tr "\n\r" " " | | xargs)"
echo "Found matching rules '$RULES'"
if [ "$RULES" != "$EXPECTED_RULES" ]; then
echo "Did not match expected rules '$EXPECTED_RULES'."
Expand Down
2 changes: 1 addition & 1 deletion pr-checks/checks/split-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ steps:
EXPECTED_RULES="javascript/example/empty-or-one-block javascript/example/empty-or-one-block javascript/example/other-query-block javascript/example/two-block"
# use tr to replace newlines with spaces and xargs to trim leading and trailing whitespace
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort | tr "\n" " " | tr "\r" " " | xargs)"
RULES="$(cat javascript.sarif | jq -r '.runs[0].results[].ruleId' | sort tr "\n\r" " " | | xargs)"
echo "Found matching rules '$RULES'"
if [ "$RULES" != "$EXPECTED_RULES" ]; then
echo "Did not match expected rules '$EXPECTED_RULES'."
Expand Down
15 changes: 2 additions & 13 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,8 @@ export async function runQueries(
logger.info("Performing analysis with custom CodeQL Packs.");
logger.startGroup(`Downloading custom packs for ${language}`);

const results = await codeql.packDownload(
removePackPath(packsWithVersion)
);
const results = await codeql.packDownload(packsWithVersion);

logger.info(
`Downloaded packs: ${results.packs
.map((r) => `${r.name}@${r.version || "latest"}`)
Expand Down Expand Up @@ -499,16 +498,6 @@ async function injectLinesOfCode(
}
}

/**
* `codeql pack download` command does not support downloading pack specifiers with paths
* in them. This removes the path from the pack specifier.
* @param packsWithVersion array of pack specifiers, some of which may have paths in them
* @returns array of pack specifiers without paths
*/
function removePackPath(packsWithVersion: string[]) {
return packsWithVersion.map((pack) => pack.split(":")[0]);
}

function printLinesOfCodeSummary(
logger: Logger,
language: Language,
Expand Down
1 change: 1 addition & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ async function getCodeQLForCmd(
"pack",
"download",
"--format=json",
"--resolve-query-specs",
...getExtraOptionsFromEnv(["pack", "download"]),
...packs,
];
Expand Down

0 comments on commit 922dc2b

Please sign in to comment.