Clean-up logging

This commit is contained in:
Marco Gario 2024-08-02 08:12:51 +00:00
parent dc92ab6239
commit 3b3012e891
3 changed files with 21 additions and 15 deletions

View file

@ -30,6 +30,7 @@ const toolcache = __importStar(require("@actions/tool-cache"));
const node_forge_1 = require("node-forge"); const node_forge_1 = require("node-forge");
const actionsUtil = __importStar(require("./actions-util")); const actionsUtil = __importStar(require("./actions-util"));
const util = __importStar(require("./util")); const util = __importStar(require("./util"));
const logging_1 = require("./logging");
const UPDATEJOB_PROXY = "update-job-proxy"; const UPDATEJOB_PROXY = "update-job-proxy";
const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912"; const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912";
const UPDATEJOB_PROXY_URL = "https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.18.1/update-job-proxy.tar.gz"; const UPDATEJOB_PROXY_URL = "https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.18.1/update-job-proxy.tar.gz";
@ -79,12 +80,14 @@ function generateCertificateAuthority() {
return { cert: pem, key }; return { cert: pem, key };
} }
async function runWrapper() { async function runWrapper() {
// Setup logging const logger = (0, logging_1.getActionsLogger)();
// Setup logging for the proxy
const tempDir = actionsUtil.getTemporaryDirectory(); const tempDir = actionsUtil.getTemporaryDirectory();
const logFilePath = path.resolve(tempDir, "proxy.log"); const proxyLogFilePath = path.resolve(tempDir, "proxy.log");
core.saveState("proxy-log-file", logFilePath); core.saveState("proxy-log-file", proxyLogFilePath);
// Get the configuration options // Get the configuration options
const credentials = getCredentials(); const credentials = getCredentials();
logger.debug(`Credentials loaded for the following URLs:\n ${credentials.map(c => c.host).join("\n")}`);
const ca = generateCertificateAuthority(); const ca = generateCertificateAuthority();
const proxyAuth = getProxyAuth(); const proxyAuth = getProxyAuth();
const proxyConfig = { const proxyConfig = {
@ -94,9 +97,9 @@ async function runWrapper() {
}; };
// Start the Proxy // Start the Proxy
const proxyBin = await getProxyBinaryPath(); const proxyBin = await getProxyBinaryPath();
await startProxy(proxyBin, proxyConfig, logFilePath); await startProxy(proxyBin, proxyConfig, proxyLogFilePath, logger);
} }
async function startProxy(binPath, config, logFilePath) { async function startProxy(binPath, config, logFilePath, logger) {
const host = "127.0.0.1"; const host = "127.0.0.1";
let port = 49152; let port = 49152;
try { try {
@ -130,7 +133,7 @@ async function startProxy(binPath, config, logFilePath) {
if (subprocessError) { if (subprocessError) {
throw subprocessError; throw subprocessError;
} }
core.info(`Proxy started on ${host}:${port}`); logger.info(`Proxy started on ${host}:${port}`);
core.setOutput("proxy_host", host); core.setOutput("proxy_host", host);
core.setOutput("proxy_port", port.toString()); core.setOutput("proxy_port", port.toString());
core.setOutput("proxy_ca_certificate", config.ca.cert); core.setOutput("proxy_ca_certificate", config.ca.cert);
@ -145,7 +148,6 @@ async function startProxy(binPath, config, logFilePath) {
function getCredentials() { function getCredentials() {
const encodedCredentials = actionsUtil.getOptionalInput("registries_credentials"); const encodedCredentials = actionsUtil.getOptionalInput("registries_credentials");
if (encodedCredentials !== undefined) { if (encodedCredentials !== undefined) {
core.info(`Using encoded credentials.`);
const credentialsStr = Buffer.from(encodedCredentials, "base64").toString(); const credentialsStr = Buffer.from(encodedCredentials, "base64").toString();
return JSON.parse(credentialsStr); return JSON.parse(credentialsStr);
} }

File diff suppressed because one or more lines are too long

View file

@ -7,6 +7,7 @@ import { pki } from "node-forge";
import * as actionsUtil from "./actions-util"; import * as actionsUtil from "./actions-util";
import * as util from "./util"; import * as util from "./util";
import { getActionsLogger, Logger } from "./logging";
const UPDATEJOB_PROXY = "update-job-proxy"; const UPDATEJOB_PROXY = "update-job-proxy";
const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912"; const UPDATEJOB_PROXY_VERSION = "v2.0.20240722180912";
@ -89,13 +90,17 @@ function generateCertificateAuthority(): CertificateAuthority {
} }
async function runWrapper() { async function runWrapper() {
// Setup logging const logger = getActionsLogger();
// Setup logging for the proxy
const tempDir = actionsUtil.getTemporaryDirectory(); const tempDir = actionsUtil.getTemporaryDirectory();
const logFilePath = path.resolve(tempDir, "proxy.log"); const proxyLogFilePath = path.resolve(tempDir, "proxy.log");
core.saveState("proxy-log-file", logFilePath); core.saveState("proxy-log-file", proxyLogFilePath);
// Get the configuration options // Get the configuration options
const credentials = getCredentials(); const credentials = getCredentials();
logger.debug(`Credentials loaded for the following URLs:\n ${credentials.map(c => c.host).join("\n")}`)
const ca = generateCertificateAuthority(); const ca = generateCertificateAuthority();
const proxyAuth = getProxyAuth(); const proxyAuth = getProxyAuth();
@ -107,10 +112,10 @@ async function runWrapper() {
// Start the Proxy // Start the Proxy
const proxyBin = await getProxyBinaryPath(); const proxyBin = await getProxyBinaryPath();
await startProxy(proxyBin, proxyConfig, logFilePath); await startProxy(proxyBin, proxyConfig, proxyLogFilePath, logger);
} }
async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string) { async function startProxy(binPath: string, config: ProxyConfig, logFilePath: string, logger: Logger) {
const host = "127.0.0.1"; const host = "127.0.0.1";
let port = 49152; let port = 49152;
try { try {
@ -148,7 +153,7 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
if (subprocessError) { if (subprocessError) {
throw subprocessError; throw subprocessError;
} }
core.info(`Proxy started on ${host}:${port}`); logger.info(`Proxy started on ${host}:${port}`);
core.setOutput("proxy_host", host); core.setOutput("proxy_host", host);
core.setOutput("proxy_port", port.toString()); core.setOutput("proxy_port", port.toString());
core.setOutput("proxy_ca_certificate", config.ca.cert); core.setOutput("proxy_ca_certificate", config.ca.cert);
@ -165,7 +170,6 @@ async function startProxy(binPath: string, config: ProxyConfig, logFilePath: str
function getCredentials(): Credential[] { function getCredentials(): Credential[] {
const encodedCredentials = actionsUtil.getOptionalInput("registries_credentials"); const encodedCredentials = actionsUtil.getOptionalInput("registries_credentials");
if (encodedCredentials !== undefined) { if (encodedCredentials !== undefined) {
core.info(`Using encoded credentials.`);
const credentialsStr = Buffer.from(encodedCredentials, "base64").toString(); const credentialsStr = Buffer.from(encodedCredentials, "base64").toString();
return JSON.parse(credentialsStr) as Credential[]; return JSON.parse(credentialsStr) as Credential[];
} }