Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #159 from github/rename_cli
Rename CLI to CodeQL runner
Robert authored and GitHub committed Aug 26, 2020

Unverified

No user is associated with the committer email.
2 parents fe75660 + 09677da commit aac5eb2
Showing 23 changed files with 56 additions and 56 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cli.yml → .github/workflows/runner.yml
@@ -1,4 +1,4 @@
name: "CodeScanning CLI"
name: "CodeQL runner"

on: [push, pull_request]

@@ -9,15 +9,15 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Build CLI
- name: Build runner
run: |
cd packaging
cd runner
npm install
npm run build-cli
npm run build-runner
- name: Upload with CLI
- name: Upload with runner
run: |
packaging/dist/code-scanning-cli-linux upload \
runner/dist/codeql-runner-linux upload \
--sarif-file src/testdata/empty-sarif.sarif \
--repository $GITHUB_REPOSITORY \
--commit $GITHUB_SHA \
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,2 +1,2 @@
/packaging/dist/
/packaging/node_modules/
/runner/dist/
/runner/node_modules/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
@@ -49,9 +49,9 @@ Running locally will generate the CodeQL database and run all the queries, but i

As well as the unit tests (see _Common tasks_ above), there are integration tests, defined in `.github/workflows/integration-testing.yml`. These are run by a CI check. Depending on the change you’re making, you may want to add a test to this file or extend an existing one.

### Building the CLI
### Building the CodeQL runner

Navigate to the `packaging` directory and run `npm install` to install dependencies needed only for compiling the CLI. Run `npm run build-cli` to output files to the `packaging/dist` directory.
Navigate to the `runner` directory and run `npm install` to install dependencies needed only for compiling the CodeQL runner. Run `npm run build-runner` to output files to the `runner/dist` directory.

## Submitting a pull request

1 change: 0 additions & 1 deletion lib/cli.js.map

This file was deleted.

6 changes: 3 additions & 3 deletions lib/fingerprints.test.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/fingerprints.test.js.map

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

4 changes: 2 additions & 2 deletions lib/logging.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/logging.js.map

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

6 changes: 3 additions & 3 deletions lib/cli.js → lib/runner.js

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

1 change: 1 addition & 0 deletions lib/runner.js.map

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

2 changes: 1 addition & 1 deletion lib/upload-lib.js
2 changes: 1 addition & 1 deletion lib/upload-lib.js.map
4 changes: 2 additions & 2 deletions lib/upload-lib.test.js
2 changes: 1 addition & 1 deletion lib/upload-lib.test.js.map
22 changes: 11 additions & 11 deletions queries/unguarded-action-lib.ql
@@ -27,21 +27,21 @@ class ActionsLibImport extends ImportDeclaration {
}

/**
* An entrypoint to the CLI.
* An entrypoint to the CodeQL runner.
*/
class ClIEntrypoint extends Function {
ClIEntrypoint() {
getFile().getAbsolutePath().matches("%/cli.ts")
class RunnerEntrypoint extends Function {
RunnerEntrypoint() {
getFile().getAbsolutePath().matches("%/runner.ts")
}
}

/**
* A check of whether we are in actions mode or CLI mode.
* A check of whether we are in actions mode or runner mode.
*/
class ModeGuard extends IfStmt {
ModeGuard() {
getCondition().(EqualityTest).getAnOperand().(StringLiteral).getValue() = "actions" or
getCondition().(EqualityTest).getAnOperand().(StringLiteral).getValue() = "cli"
getCondition().(EqualityTest).getAnOperand().(StringLiteral).getValue() = "runner"
}

string getOperand() {
@@ -58,11 +58,11 @@ class ModeGuard extends IfStmt {
Stmt getActionsBlock() {
(getOperand() = "actions" and isPositive() and result = getThen())
or
(getOperand() = "cli" and not isPositive() and result = getThen())
(getOperand() = "runner" and not isPositive() and result = getThen())
or
(getOperand() = "actions" and not isPositive() and result = getElse())
or
(getOperand() = "cli" and isPositive() and result = getElse())
(getOperand() = "runner" and isPositive() and result = getElse())
}

/**
@@ -99,10 +99,10 @@ Function calledBy(Function f) {
not exists(ModeGuard guard | guard.getAnActionsExpr() = result))
}

from VarAccess v, ActionsLibImport actionsLib, ClIEntrypoint cliEntry
from VarAccess v, ActionsLibImport actionsLib, RunnerEntrypoint runnerEntry
where actionsLib.getAProvidedVariable() = v.getVariable()
and getAFunctionChildExpr(calledBy*(cliEntry)) = v
and getAFunctionChildExpr(calledBy*(runnerEntry)) = v
select v, "$@ is imported from $@ and this code can be called from $@",
v, v.getName(),
actionsLib, actionsLib.getName(),
cliEntry, "the CLI"
runnerEntry, "the runner"
2 changes: 1 addition & 1 deletion packaging/package-lock.json → runner/package-lock.json
6 changes: 3 additions & 3 deletions packaging/package.json → runner/package.json
@@ -1,10 +1,10 @@
{
"name": "codeql-packaging",
"name": "codeql-runner",
"version": "0.0.0",
"private": true,
"description": "CodeQL action - CLI packaging",
"description": "CodeQL runner",
"scripts": {
"build-cli": "webpack --mode production && pkg dist/code-scanning-cli.js --out-path dist"
"build-runner": "webpack --mode production && pkg dist/codeql-runner.js --out-path dist"
},
"license": "MIT",
"dependencies": {},
4 changes: 2 additions & 2 deletions packaging/webpack.config.js → runner/webpack.config.js
@@ -1,7 +1,7 @@
const path = require('path');

module.exports = {
entry: '../src/cli.ts',
entry: '../src/runner.ts',
module: {
rules: [
{
@@ -16,7 +16,7 @@ module.exports = {
extensions: [ '.ts', '.js' ],
},
output: {
filename: 'code-scanning-cli.js',
filename: 'codeql-runner.js',
path: path.resolve(__dirname, 'dist'),
},
optimization: {
8 changes: 4 additions & 4 deletions src/fingerprints.test.ts
@@ -4,7 +4,7 @@ import * as fs from 'fs';
import * as path from 'path';

import * as fingerprints from './fingerprints';
import { getCLILogger } from './logging';
import { getRunnerLogger } from './logging';
import {setupTests} from './testing-utils';

setupTests(test);
@@ -116,7 +116,7 @@ test('hash', (t: ava.Assertions) => {
function testResolveUriToFile(uri: any, index: any, artifactsURIs: any[]) {
const location = { "uri": uri, "index": index };
const artifacts = artifactsURIs.map(uri => ({ "location": { "uri": uri } }));
return fingerprints.resolveUriToFile(location, artifacts, getCLILogger());
return fingerprints.resolveUriToFile(location, artifacts, getRunnerLogger());
}

test('resolveUriToFile', t => {
@@ -175,7 +175,7 @@ test('addFingerprints', t => {
// The URIs in the SARIF files resolve to files in the testdata directory
process.env['GITHUB_WORKSPACE'] = path.normalize(__dirname + '/../src/testdata');

t.deepEqual(fingerprints.addFingerprints(input, getCLILogger()), expected);
t.deepEqual(fingerprints.addFingerprints(input, getRunnerLogger()), expected);
});

test('missingRegions', t => {
@@ -190,5 +190,5 @@ test('missingRegions', t => {
// The URIs in the SARIF files resolve to files in the testdata directory
process.env['GITHUB_WORKSPACE'] = path.normalize(__dirname + '/../src/testdata');

t.deepEqual(fingerprints.addFingerprints(input, getCLILogger()), expected);
t.deepEqual(fingerprints.addFingerprints(input, getRunnerLogger()), expected);
});
2 changes: 1 addition & 1 deletion src/logging.ts
@@ -14,7 +14,7 @@ export function getActionsLogger(): Logger {
return core;
}

export function getCLILogger(): Logger {
export function getRunnerLogger(): Logger {
return {
debug: console.debug,
info: console.info,
6 changes: 3 additions & 3 deletions src/cli.ts → src/runner.ts
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import * as path from 'path';

import { getCLILogger } from './logging';
import { getRunnerLogger } from './logging';
import { parseRepositoryNwo } from './repository';
import * as upload_lib from './upload-lib';

@@ -40,7 +40,7 @@ function parseGithubApiUrl(inputUrl: string): string {
}
}

const logger = getCLILogger();
const logger = getRunnerLogger();

program
.command('upload')
@@ -66,7 +66,7 @@ program
undefined,
cmd.githubAuth,
parseGithubApiUrl(cmd.githubUrl),
'cli',
'runner',
logger);
} catch (e) {
logger.error('Upload failed');
6 changes: 3 additions & 3 deletions src/upload-lib.test.ts
@@ -1,17 +1,17 @@
import test from 'ava';

import { getCLILogger } from './logging';
import { getRunnerLogger } from './logging';
import {setupTests} from './testing-utils';
import * as uploadLib from './upload-lib';

setupTests(test);

test('validateSarifFileSchema - valid', t => {
const inputFile = __dirname + '/../src/testdata/valid-sarif.sarif';
t.notThrows(() => uploadLib.validateSarifFileSchema(inputFile, getCLILogger()));
t.notThrows(() => uploadLib.validateSarifFileSchema(inputFile, getRunnerLogger()));
});

test('validateSarifFileSchema - invalid', t => {
const inputFile = __dirname + '/../src/testdata/invalid-sarif.sarif';
t.throws(() => uploadLib.validateSarifFileSchema(inputFile, getCLILogger()));
t.throws(() => uploadLib.validateSarifFileSchema(inputFile, getRunnerLogger()));
});
4 changes: 2 additions & 2 deletions src/upload-lib.ts
@@ -12,7 +12,7 @@ import { RepositoryNwo } from './repository';
import * as sharedEnv from './shared-environment';
import * as util from './util';

type UploadMode = 'actions' | 'cli';
type UploadMode = 'actions' | 'runner';

// Takes a list of paths to sarif files and combines them together,
// returning the contents of the combined sarif file.
@@ -221,7 +221,7 @@ async function uploadFiles(
logger.info("Uploading sarif files: " + JSON.stringify(sarifFiles));

if (mode === 'actions') {
// This check only works on actions as env vars don't persist between calls to the CLI
// 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]) {
throw new Error("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job");

0 comments on commit aac5eb2

Please sign in to comment.