Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into pr_template_typos
Robert authored and GitHub committed Apr 30, 2020

Unverified

No user is associated with the committer email.
2 parents 20a0628 + f16b356 commit 1bb13e0
Showing 11 changed files with 103 additions and 12 deletions.
2 changes: 0 additions & 2 deletions README.md
@@ -2,8 +2,6 @@

This action runs GitHub's industry-leading static analysis engine, CodeQL, against a repository's source code to find security vulnerabilities. It then automatically uploads the results to GitHub so they can be displayed in the repository's security tab. CodeQL runs an extensible set of [queries](https://github.com/semmle/ql), which have been developed by the community and the [GitHub Security Lab](https://securitylab.github.com/) to find common vulnerabilities in your code.

[Sign up for the Advanced Security beta](https://github.com/features/security/advanced-security/signup)

## Usage

To get code scanning results from CodeQL analysis on your repo you can use the following workflow as a template:
4 changes: 2 additions & 2 deletions lib/finalize-db.js

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

4 changes: 3 additions & 1 deletion lib/upload-lib.js

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

18 changes: 18 additions & 0 deletions lib/util.js

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

6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
@@ -12,7 +12,7 @@
"dependencies": {
"@actions/core": "^1.0.0",
"@actions/exec": "^1.0.1",
"@actions/http-client": "^1.0.4",
"@actions/http-client": "^1.0.8",
"@actions/io": "^1.0.1",
"@actions/tool-cache": "^1.1.2",
"@octokit/rest": "^17.1.0",
4 changes: 2 additions & 2 deletions src/finalize-db.ts
@@ -82,13 +82,13 @@ async function resolveQueryLanguages(codeqlCmd: string, config: configUtils.Conf
const noDeclaredLanguage = resolveQueriesOutputObject.noDeclaredLanguage;
const noDeclaredLanguageQueries = Object.keys(noDeclaredLanguage);
if (noDeclaredLanguageQueries.length !== 0) {
core.warning('Some queries do not declare a language:\n' + noDeclaredLanguageQueries.join('\n'));
throw new Error('Some queries do not declare a language, their qlpack.yml file is missing or is invalid');
}

const multipleDeclaredLanguages = resolveQueriesOutputObject.multipleDeclaredLanguages;
const multipleDeclaredLanguagesQueries = Object.keys(multipleDeclaredLanguages);
if (multipleDeclaredLanguagesQueries.length !== 0) {
core.warning('Some queries declare multiple languages:\n' + multipleDeclaredLanguagesQueries.join('\n'));
throw new Error('Some queries declare multiple languages, their qlpack.yml file is missing or is invalid');
}
}

41 changes: 41 additions & 0 deletions src/testdata/tool-names.sarif
@@ -0,0 +1,41 @@
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [
{
"tool": {
"driver": {
"name": "CodeQL command-line toolchain"
}
}
},
{
"tool": {
"driver": {
"name": "CodeQL command-line toolchain"
}
}
},
{
"tool": {
"driver": {
"name": "ESLint"
}
}
},
{
"tool": {
"driver": {
"name": ""
}
}
},
{
"tool": {
"driver": {
"name": null
}
}
}
]
}
5 changes: 4 additions & 1 deletion src/upload-lib.ts
@@ -98,6 +98,8 @@ async function uploadFiles(sarifFiles: string[]) {
matrix = undefined;
}

const toolNames = util.getToolNames(sarifPayload);

const payload = JSON.stringify({
"commit_oid": commitOid,
"ref": ref,
@@ -106,7 +108,8 @@ async function uploadFiles(sarifFiles: string[]) {
"workflow_run_id": workflowRunID,
"checkout_uri": checkoutURI,
"environment": matrix,
"started_at": startedAt
"started_at": startedAt,
"tool_names": toolNames,
});

core.info('Uploading results');
9 changes: 9 additions & 0 deletions src/util.test.ts
@@ -0,0 +1,9 @@
import * as fs from 'fs';

import * as util from './util';

test('getToolNames', () => {
const input = fs.readFileSync(__dirname + '/testdata/tool-names.sarif', 'utf8')
const toolNames = util.getToolNames(input);
expect(toolNames).toStrictEqual(["CodeQL command-line toolchain", "ESLint"])
})
20 changes: 20 additions & 0 deletions src/util.ts
@@ -293,3 +293,23 @@ export async function reportActionFailed(action: string, cause?: string, excepti
export async function reportActionSucceeded(action: string) {
await sendStatusReport(await createStatusReport(action, 'success'));
}

/**
* Get the array of all the tool names contained in the given sarif contents.
*
* Returns an array of unique string tool names.
*/
export function getToolNames(sarifContents: string): string[] {
const sarif = JSON.parse(sarifContents);
const toolNames = {};

for (const run of sarif.runs || []) {
const tool = run.tool || {};
const driver = tool.driver || {};
if (typeof driver.name === "string" && driver.name.length > 0) {
toolNames[driver.name] = true;
}
}

return Object.keys(toolNames);
}

0 comments on commit 1bb13e0

Please sign in to comment.