FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Set the CODEQL_WRAPPER env var by aeisenberg · Pull Request #496 · github/codeql-action · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (4) .map  (4) .ts  (4) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion lib/api-client.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/api-client.js.map

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

2 changes: 2 additions & 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.

8 changes: 8 additions & 0 deletions lib/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/util.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions lib/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/util.test.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/api-client.ts
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as githubUtils from "@actions/github/lib/utils";
import consoleLogLevel from "console-log-level";

import { getRequiredEnvParam, getRequiredInput } from "./actions-util";
import { isLocalRun } from "./util";
import { isLocalRun, isAction } from "./util";

export enum DisallowedAPIVersionReason {
ACTION_TOO_OLD,
Expand Down Expand Up @@ -37,7 +37,7 @@ export const getApiClient = function (
return new githubUtils.GitHub(
githubUtils.getOctokitOptions(auth, {
baseUrl: getApiUrl(apiDetails.url),
userAgent: "CodeQL Action",
userAgent: isAction() ? "CodeQL Action" : "CodeQL Runner",
log: consoleLogLevel({ level: "debug" }),
})
);
Expand Down
3 changes: 3 additions & 0 deletions src/codeql.ts
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
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ export async function setupCodeQL(
throw new Error(`Unsupported platform: ${process.platform}`);
}

// set a environment variable to let CodeQL know where we are running
process.env.CODEQL_WRAPPER = util.isAction() ? "action" : "runner";

cachedCodeQL = getCodeQLForCmd(codeqlCmd);
return { codeql: cachedCodeQL, toolsVersion: codeqlURLVersion };
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions src/util.test.ts
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,10 @@ async function mockStdInForAuthExpectError(
util.getGitHubAuth(mockLogger, undefined, true, stdin)
);
}

test("isAction", async (t) => {
process.env.GITHUB_ACTIONS = "true";
t.assert(util.isAction(), "Should be running in actions");
delete process.env.GITHUB_ACTIONS;
t.assert(!util.isAction(), "Should be running in runner");
});
8 changes: 8 additions & 0 deletions src/util.ts
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
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,11 @@ export async function getGitHubAuth(
"No GitHub authentication token was specified. Please provide a token via the GITHUB_TOKEN environment variable, or by adding the `--github-auth-stdin` flag and passing the token via standard input."
);
}

/**
* Returns true if this process is running as part of github actions.
* False otherwise.
*/
export function isAction() {
return "GITHUB_ACTIONS" in process.env;
}
Comment on lines +398 to +400

hmakholm May 10, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What if someone writes an Actions workflow that explicitly downloads and invokes codeql-runner-linux64? In that case I think we should announce ourselves as the runner even though $GITHUB_ACTIONS also happens to be set.

I feel it would be more robust simply to have a global flag that runner.ts sets early on.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there a use case for why someone would do this?

adityasharad May 10, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Henning is right. We do it in this repo for integration testing the runner!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The way we handle behaviour differences between the action and runner currently is by passing a mode parameter around. While I admit that's not a perfect solution, it would probably be cleaner to use that instead of introducing a new mechanism for telling if we should behave like the action or the runner. This would also solve the problem Henning mentions. If you want to then simplify to using a flag set in the environment instead of an explicit function parameter you could then do everything at once (there's also a CodeQL query that checks this info that would need changing).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Implemented this idea here #516.


Back | FazBrowse Home | New Git URL