mirror of
https://github.com/github/codeql-action.git
synced 2026-11-08 22:19:50 +00:00
Refactor all doc URLs into their own enum
This commit is contained in:
@@ -4,6 +4,7 @@ import { getTemporaryDirectory, getWorkflowEventName } from "./actions-util";
|
||||
import { getGitHubVersion } from "./api-client";
|
||||
import { CodeQL, getCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Feature, featureConfig, Features } from "./feature-flags";
|
||||
import { isTracedLanguage, Language } from "./languages";
|
||||
@@ -102,8 +103,7 @@ export async function determineAutobuildLanguages(
|
||||
.join(
|
||||
" and ",
|
||||
)}, you must replace the autobuild step of your workflow with custom build steps. ` +
|
||||
"For more information, see " +
|
||||
"https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages#adding-build-steps-for-a-compiled-language",
|
||||
`For more information, see ${DocUrl.SPECIFY_BUILD_STEPS_MANUALLY}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,8 +113,6 @@ export async function determineAutobuildLanguages(
|
||||
export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
|
||||
const envVar = featureConfig[Feature.CppDependencyInstallation].envVar;
|
||||
const featureName = "C++ automatic installation of dependencies";
|
||||
const envDoc =
|
||||
"https://docs.github.com/en/actions/learn-github-actions/variables#defining-environment-variables-for-a-single-workflow";
|
||||
const gitHubVersion = await getGitHubVersion();
|
||||
const repositoryNwo = parseRepositoryNwo(
|
||||
getRequiredEnvParam("GITHUB_REPOSITORY"),
|
||||
@@ -134,14 +132,14 @@ export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
|
||||
logger.info(
|
||||
`Disabling ${featureName} as we are on a self-hosted runner.${
|
||||
getWorkflowEventName() !== "dynamic"
|
||||
? ` To override this, set the ${envVar} environment variable to 'true' in your workflow (see ${envDoc} for more information).`
|
||||
? ` To override this, set the ${envVar} environment variable to 'true' in your workflow (see ${DocUrl.DEFINE_ENV_VARIABLES} for more information).`
|
||||
: ""
|
||||
}`,
|
||||
);
|
||||
core.exportVariable(envVar, "false");
|
||||
} else {
|
||||
logger.info(
|
||||
`Enabling ${featureName}. This can be disabled by setting the ${envVar} environment variable to 'false' (see ${envDoc} for more information).`,
|
||||
`Enabling ${featureName}. This can be disabled by setting the ${envVar} environment variable to 'false' (see ${DocUrl.DEFINE_ENV_VARIABLES} for more information).`,
|
||||
);
|
||||
core.exportVariable(envVar, "true");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { ConfigurationError } from "./util";
|
||||
|
||||
/**
|
||||
@@ -27,11 +28,9 @@ export class CommandInvocationError extends Error {
|
||||
fatalErrors.trim(),
|
||||
)} See the logs for more details.`;
|
||||
} else if (autobuildErrors) {
|
||||
const autobuildHelpLink =
|
||||
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed";
|
||||
message =
|
||||
"We were unable to automatically build your code. Please provide manual build steps. " +
|
||||
`See ${autobuildHelpLink} for more information. ` +
|
||||
`See ${DocUrl.AUTOMATIC_BUILD_FAILED} for more information. ` +
|
||||
`Encountered the following error: ${autobuildErrors}`;
|
||||
} else {
|
||||
const lastLine = ensureEndsInPeriod(
|
||||
|
||||
@@ -16,6 +16,7 @@ import { CommandInvocationError } from "./cli-errors";
|
||||
import * as codeql from "./codeql";
|
||||
import { AugmentationProperties, Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
@@ -909,8 +910,7 @@ test("runTool summarizes autobuilder errors", async (t) => {
|
||||
instanceOf: util.ConfigurationError,
|
||||
message:
|
||||
"We were unable to automatically build your code. Please provide manual build steps. " +
|
||||
"See https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed " +
|
||||
"for more information. " +
|
||||
`See ${DocUrl.AUTOMATIC_BUILD_FAILED} for more information. ` +
|
||||
"Encountered the following error: Start of the error message\n" +
|
||||
" Some more context about the error message\n" +
|
||||
" continued\n" +
|
||||
@@ -937,8 +937,7 @@ test("runTool truncates long autobuilder errors", async (t) => {
|
||||
instanceOf: util.ConfigurationError,
|
||||
message:
|
||||
"We were unable to automatically build your code. Please provide manual build steps. " +
|
||||
"See https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed " +
|
||||
"for more information. " +
|
||||
`See ${DocUrl.AUTOMATIC_BUILD_FAILED} for more information. ` +
|
||||
"Encountered the following error: " +
|
||||
`${Array.from({ length: 10 }, (_, i) => `line${i + 1}`).join(
|
||||
"\n",
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
wrapCliConfigurationError,
|
||||
} from "./cli-errors";
|
||||
import { type Config } from "./config-utils";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { EnvVar } from "./environment";
|
||||
import {
|
||||
CODEQL_VERSION_FINE_GRAINED_PARALLELISM,
|
||||
@@ -698,9 +699,7 @@ export async function getCodeQLForCmd(
|
||||
const prefix =
|
||||
"We were unable to automatically build your code. " +
|
||||
"Please change the build mode for this language to manual and specify build steps " +
|
||||
"for your project. See " +
|
||||
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed" +
|
||||
"for more information.";
|
||||
`for your project. See ${DocUrl.AUTOMATIC_BUILD_FAILED} for more information.`;
|
||||
const ErrorConstructor =
|
||||
e instanceof util.ConfigurationError
|
||||
? util.ConfigurationError
|
||||
|
||||
18
src/doc-url.ts
Normal file
18
src/doc-url.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* URLs to code scanning docs linked to from CodeQL Action logs.
|
||||
*/
|
||||
|
||||
export enum DocUrl {
|
||||
ASSIGNING_PERMISSIONS_TO_JOBS =
|
||||
"https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs",
|
||||
AUTOMATIC_BUILD_FAILED =
|
||||
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed",
|
||||
DEFINE_ENV_VARIABLES =
|
||||
"https://docs.github.com/en/actions/learn-github-actions/variables#defining-environment-variables-for-a-single-workflow",
|
||||
SCANNING_ON_PUSH =
|
||||
"https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#scanning-on-push",
|
||||
SPECIFY_BUILD_STEPS_MANUALLY =
|
||||
"https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#about-specifying-build-steps-manually",
|
||||
TRACK_CODE_SCANNING_ALERTS_ACROSS_RUNS =
|
||||
"https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#providing-data-to-track-code-scanning-alerts-across-runs"
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import path from "path";
|
||||
|
||||
import Long from "long";
|
||||
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { Logger } from "./logging";
|
||||
import { SarifFile, SarifResult } from "./util";
|
||||
|
||||
@@ -260,7 +261,7 @@ export async function addFingerprints(
|
||||
logger: Logger,
|
||||
): Promise<SarifFile> {
|
||||
logger.info(
|
||||
"Adding fingerprints to SARIF file. For more information, see https://docs.github.com/en/enterprise-cloud@latest/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#providing-data-to-track-code-scanning-alerts-across-runs",
|
||||
`Adding fingerprints to SARIF file. For more information, see ${DocUrl.TRACK_CODE_SCANNING_ALERTS_ACROSS_RUNS}`,
|
||||
);
|
||||
// Gather together results for the same file and construct
|
||||
// callbacks to accept hashes for that file and update the location
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from "./actions-util";
|
||||
import { getAnalysisKey, getApiClient } from "./api-client";
|
||||
import { type Config } from "./config-utils";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Logger } from "./logging";
|
||||
import {
|
||||
@@ -414,7 +415,7 @@ export async function sendStatusReport<S extends StatusReportBase>(
|
||||
'Workflows triggered by Dependabot on the "push" event run with read-only access. ' +
|
||||
"Uploading Code Scanning results requires write access. " +
|
||||
'To use Code Scanning with Dependabot, please ensure you are using the "pull_request" event for this workflow and avoid triggering on the "push" event for Dependabot branches. ' +
|
||||
"See https://docs.github.com/en/code-security/secure-coding/configuring-code-scanning#scanning-on-push for more information on how to configure these events.",
|
||||
`See ${DocUrl.SCANNING_ON_PUSH} for more information on how to configure these events."`,
|
||||
);
|
||||
} else {
|
||||
core.warning(e.message);
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as actionsUtil from "./actions-util";
|
||||
import * as apiClient from "./api-client";
|
||||
import { CodeQL } from "./codeql";
|
||||
import type { Config } from "./config-utils";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
@@ -233,7 +234,7 @@ export async function cleanupTrapCaches(
|
||||
logger.warning(
|
||||
"Could not cleanup TRAP caches as the token did not have the required permissions. " +
|
||||
'To clean up TRAP caches, ensure the token has the "actions:write" permission. ' +
|
||||
"For more information, see https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs",
|
||||
`For more information, see " + ${DocUrl.ASSIGNING_PERMISSIONS_TO_JOBS}`,
|
||||
);
|
||||
} else {
|
||||
logger.info(`Failed to cleanup TRAP caches, continuing. Details: ${e}`);
|
||||
|
||||
Reference in New Issue
Block a user