Add environment variables to signal feature and version to the CLI

This PR ensures environment variables are set before any invocation of
the CLI.  Here is a list of vars that are set:

https://github.com/github/codeql-coreql-team/issues/1124#issuecomment-852463521

This ensures the CLI knows the features and versions of the containing
actions/runner.

Additionally:

- Fix the user agent so that it more closely aligns with user agent
  spec
- Refactor environment variable initialization so that it all happens in
  one place and call.
- Move Mode, getRequiredEnvParam, setMode, getMode out of actions-util
  and into util. actions-util is meant for utils only called by the
  action, not the runner.

The `prepareLocalRunEnvironment()` method is most likely deprecated and
should be removed. I originally added it because I had a way of working
where I would run the action from my local machine to test out changes,
but this was always a little flaky. So, I no longer use this way of
working. I will probably remove it soon.
This commit is contained in:
Andrew Eisenberg 2021-06-01 14:49:07 -07:00
parent 539d968ad7
commit 3708898bf2
48 changed files with 387 additions and 250 deletions

View file

@ -99,7 +99,7 @@ async function uploadPayload(
const client = api.getApiClient(apiDetails);
const reqURL = actionsUtil.isActions()
const reqURL = util.isActions()
? "PUT /repos/:owner/:repo/code-scanning/analysis"
: "POST /repos/:owner/:repo/code-scanning/sarifs";
const response = await client.request(reqURL, {
@ -150,12 +150,12 @@ export async function uploadFromActions(
): Promise<UploadStatusReport> {
return await uploadFiles(
getSarifFilePaths(sarifPath),
parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")),
parseRepositoryNwo(util.getRequiredEnvParam("GITHUB_REPOSITORY")),
await actionsUtil.getCommitOid(),
await actionsUtil.getRef(),
await actionsUtil.getAnalysisKey(),
actionsUtil.getOptionalInput("category"),
actionsUtil.getRequiredEnvParam("GITHUB_WORKFLOW"),
util.getRequiredEnvParam("GITHUB_WORKFLOW"),
actionsUtil.getWorkflowRunID(),
actionsUtil.getRequiredInput("checkout_path"),
actionsUtil.getRequiredInput("matrix"),
@ -275,7 +275,7 @@ export function buildPayload(
toolNames: string[],
gitHubVersion: util.GitHubVersion
) {
if (actionsUtil.isActions()) {
if (util.isActions()) {
const payloadObj = {
commit_oid: commitOid,
ref,
@ -339,7 +339,7 @@ async function uploadFiles(
logger.startGroup("Uploading results");
logger.info(`Processing sarif files: ${JSON.stringify(sarifFiles)}`);
if (actionsUtil.isActions()) {
if (util.isActions()) {
// This check only works on actions as env vars don't persist between calls to the runner
const sentinelEnvVar = "CODEQL_UPLOAD_SARIF";
if (process.env[sentinelEnvVar]) {