-
Notifications
You must be signed in to change notification settings - Fork 439
Log information about the runner which may affect the private registry proxy #3486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bff89dc
Add enum for Java-related env var names
mbg 33e2dff
Log information about proxy-related environment variables
mbg a3d7d36
Find likely JDK locations and check configurations
mbg 4250b46
Wrap `checkProxyEnvironment` call in `try`/`catch` for good measure
mbg ef9cfd9
Clear GHA `JAVA_HOME_*` env vars for `discoverActionsJdks` test
mbg c1d6ee5
Fix typos
mbg 99fcc7b
Check whether `value` is a URL in `checkEnvVar` and clear credentials
mbg 11c6c18
Only run when debugging or test mode is enabled
mbg 44a4bea
Fixup: add missing `.env`
mbg 9715925
Consistently use "\n" to split lines, then trim extra characters if n…
mbg 32ab108
Move interesting JRE properties out of `checkJdkSettings`
mbg 46473e0
Add more interesting Java properties
mbg 906dd89
Run `java` to show computed settings
mbg 64300e4
Merge branch 'main' into mbg/start-proxy/java-env-checks
mbg 61f7dd3
Fix `checkExpectedLogMessages` not asserting anything on success
mbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| import * as fs from "fs"; | ||
| import * as os from "os"; | ||
| import path from "path"; | ||
|
|
||
| import * as toolrunner from "@actions/exec/lib/toolrunner"; | ||
| import * as io from "@actions/io"; | ||
| import test, { ExecutionContext } from "ava"; | ||
| import sinon from "sinon"; | ||
|
|
||
| import { JavaEnvVars, KnownLanguage } from "../languages"; | ||
| import { | ||
| checkExpectedLogMessages, | ||
| getRecordingLogger, | ||
| LoggedMessage, | ||
| setupTests, | ||
| } from "../testing-utils"; | ||
| import { withTmpDir } from "../util"; | ||
|
|
||
| import { | ||
| checkJavaEnvVars, | ||
| checkJdkSettings, | ||
| checkProxyEnvironment, | ||
| checkProxyEnvVars, | ||
| discoverActionsJdks, | ||
| JAVA_PROXY_ENV_VARS, | ||
| ProxyEnvVars, | ||
| } from "./environment"; | ||
|
|
||
| setupTests(test); | ||
|
|
||
| function stubToolrunner() { | ||
| sinon.stub(io, "which").throws(new Error("Java not installed")); | ||
| sinon.stub(toolrunner, "ToolRunner").returns({ | ||
| exec: async () => { | ||
| return 0; | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| function assertEnvVarLogMessages( | ||
| t: ExecutionContext<any>, | ||
| envVars: string[], | ||
| messages: LoggedMessage[], | ||
| expectSet: boolean | string, | ||
| ) { | ||
| const template = (envVar: string) => { | ||
| if (typeof expectSet === "string") { | ||
| return `Environment variable '${envVar}' is set to '${expectSet}'`; | ||
| } | ||
| return expectSet | ||
| ? `Environment variable '${envVar}' is set to '${envVar}'` | ||
| : `Environment variable '${envVar}' is not set`; | ||
| }; | ||
|
|
||
| const expected: string[] = []; | ||
|
|
||
| for (const envVar of envVars) { | ||
| expected.push(template(envVar)); | ||
| } | ||
|
|
||
| checkExpectedLogMessages(t, messages, expected); | ||
| } | ||
|
|
||
| test("checkJavaEnvironment - none set", (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| checkJavaEnvVars(logger); | ||
| assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, false); | ||
| }); | ||
|
|
||
| test("checkJavaEnvironment - logs values when variables are set", (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| for (const envVar of Object.values(JavaEnvVars)) { | ||
| process.env[envVar] = envVar; | ||
| } | ||
|
|
||
| checkJavaEnvVars(logger); | ||
| assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, true); | ||
| }); | ||
|
|
||
| test("discoverActionsJdks - discovers JDK paths", (t) => { | ||
| // Clear GHA variables that may interfere with this test in CI. | ||
| for (const envVar of Object.keys(process.env)) { | ||
| if (envVar.startsWith("JAVA_HOME_")) { | ||
| delete process.env[envVar]; | ||
| } | ||
| } | ||
|
|
||
| const jdk8 = "/usr/lib/jvm/temurin-8-jdk-amd64"; | ||
| const jdk17 = "/usr/lib/jvm/temurin-17-jdk-amd64"; | ||
| const jdk21 = "/usr/lib/jvm/temurin-21-jdk-amd64"; | ||
|
|
||
| process.env[JavaEnvVars.JAVA_HOME] = jdk17; | ||
| process.env["JAVA_HOME_8_X64"] = jdk8; | ||
| process.env["JAVA_HOME_17_X64"] = jdk17; | ||
| process.env["JAVA_HOME_21_X64"] = jdk21; | ||
|
|
||
| const results = discoverActionsJdks(); | ||
| t.is(results.size, 3); | ||
| t.true(results.has(jdk8)); | ||
| t.true(results.has(jdk17)); | ||
| t.true(results.has(jdk21)); | ||
| }); | ||
|
|
||
| test("checkJdkSettings - does not throw for an empty directory", async (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| await withTmpDir(async (tmpDir) => { | ||
| t.notThrows(() => checkJdkSettings(logger, tmpDir)); | ||
| }); | ||
| }); | ||
|
|
||
| test("checkJdkSettings - finds files and logs relevant properties", async (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| await withTmpDir(async (tmpDir) => { | ||
| const dir = path.join(tmpDir, "conf"); | ||
| fs.mkdirSync(dir); | ||
|
|
||
| const file = path.join(dir, "net.properties"); | ||
| fs.writeFileSync( | ||
| file, | ||
| [ | ||
| "irrelevant.property=foo", | ||
| "http.proxyHost=proxy.example.com", | ||
| "http.unrelated=bar", | ||
| ].join(os.EOL), | ||
| {}, | ||
| ); | ||
| checkJdkSettings(logger, tmpDir); | ||
|
|
||
| checkExpectedLogMessages(t, messages, [ | ||
| `Found '${file}'.`, | ||
| `Found 'http.proxyHost=proxy.example.com' in '${file}'`, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| test("checkProxyEnvVars - none set", (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| checkProxyEnvVars(logger); | ||
| assertEnvVarLogMessages(t, Object.values(ProxyEnvVars), messages, false); | ||
| }); | ||
|
|
||
| test("checkProxyEnvVars - logs values when variables are set", (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| for (const envVar of Object.values(ProxyEnvVars)) { | ||
| process.env[envVar] = envVar; | ||
| } | ||
|
|
||
| checkProxyEnvVars(logger); | ||
| assertEnvVarLogMessages(t, Object.values(ProxyEnvVars), messages, true); | ||
| }); | ||
|
|
||
| test("checkProxyEnvVars - credentials are removed from URLs", (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| for (const envVar of Object.values(ProxyEnvVars)) { | ||
| process.env[envVar] = "https://secret:password@proxy.local"; | ||
| } | ||
|
|
||
| checkProxyEnvVars(logger); | ||
| assertEnvVarLogMessages( | ||
| t, | ||
| Object.values(ProxyEnvVars), | ||
| messages, | ||
| "https://proxy.local/", | ||
| ); | ||
| }); | ||
|
|
||
| test("checkProxyEnvironment - includes base checks for all known languages", async (t) => { | ||
| stubToolrunner(); | ||
|
|
||
| for (const language of Object.values(KnownLanguage)) { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| await checkProxyEnvironment(logger, language); | ||
| assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); | ||
| } | ||
| }); | ||
|
|
||
| test("checkProxyEnvironment - includes Java checks for Java", async (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| stubToolrunner(); | ||
|
|
||
| await checkProxyEnvironment(logger, KnownLanguage.java); | ||
| assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); | ||
| assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, false); | ||
| }); | ||
|
|
||
| test("checkProxyEnvironment - includes language-specific checks if the language is undefined", async (t) => { | ||
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); | ||
|
|
||
| stubToolrunner(); | ||
|
|
||
| await checkProxyEnvironment(logger, undefined); | ||
| assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); | ||
| assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, false); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.