Skip to content

Commit

Permalink
Install CodeQL as part of the action
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael B. Gale committed Jun 13, 2023
1 parent 59a9e3a commit 8216c3a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
20 changes: 14 additions & 6 deletions lib/resolve-environment-action.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/resolve-environment-action.js.map

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

4 changes: 4 additions & 0 deletions resolve-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: 'CodeQL: Resolve Build Environment'
description: 'Attempt to infer a suitable environment configuration for the autobuilder'
author: 'GitHub'
inputs:
tools:
description: URL of CodeQL tools
required: false
# If not specified the Action will check in several places until it finds the CodeQL tools.
token:
default: ${{ github.token }}
matrix:
Expand Down
49 changes: 40 additions & 9 deletions src/resolve-environment-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import {
sendStatusReport,
} from "./actions-util";
import { getGitHubVersion } from "./api-client";
import * as configUtils from "./config-utils";
import { Features } from "./feature-flags";
import { initCodeQL } from "./init";
import { Language, resolveAlias } from "./languages";
import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { runResolveBuildEnvironment } from "./resolve-environment";
import { checkForTimeout, checkGitHubVersionInRange, wrapError } from "./util";
import {
checkForTimeout,
checkGitHubVersionInRange,
getRequiredEnvParam,
wrapError,
} from "./util";
import { validateWorkflow } from "./workflow";

const actionName = "resolve-environment";
Expand All @@ -22,6 +29,17 @@ async function run() {
const logger = getActionsLogger();
const language: Language = resolveAlias(getRequiredInput("language"));

const apiDetails = {
auth: getRequiredInput("token"),
externalRepoAuth: getOptionalInput("external-repository-token"),
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
};

const repositoryNwo = parseRepositoryNwo(
getRequiredEnvParam("GITHUB_REPOSITORY")
);

try {
const workflowErrors = await validateWorkflow(logger);

Expand All @@ -41,12 +59,25 @@ async function run() {
const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);

const config = await configUtils.getConfig(getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?"
);
}
const features = new Features(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
logger
);

const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
gitHubVersion.type
);

const initCodeQLResult = await initCodeQL(
getOptionalInput("tools"),
apiDetails,
getTemporaryDirectory(),
gitHubVersion.type,
codeQLDefaultVersionInfo,
logger
);

const workingDirectory = getOptionalInput("working-directory");
if (workingDirectory) {
Expand All @@ -57,7 +88,7 @@ async function run() {
}

const result = await runResolveBuildEnvironment(
config.codeQLCmd,
initCodeQLResult.codeql.getPath(),
logger,
language
);
Expand Down

0 comments on commit 8216c3a

Please sign in to comment.