Skip to content

Commit 1477a43

Browse files
committed
Merge branch 'master' into integration-tests
2 parents f17ebc8 + c0d9de1 commit 1477a43

File tree

11 files changed

+197
-7
lines changed

11 files changed

+197
-7
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ env:
143143

144144
to `github/codeql-action/analyze`.
145145

146-
### If you do not use a vendor directory
146+
#### If you do not use a vendor directory
147147

148148
Dependencies on public repositories should just work. If you have dependencies on private repositories, one option is to use `git config` and a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) to authenticate when downloading dependencies. Add a section like
149149

@@ -168,3 +168,7 @@ dotnet build /p:UseSharedCompilation=false
168168
```
169169

170170
Version 3 does not require the additional flag.
171+
172+
### Analysing Go together with other languages on `macos-latest`
173+
174+
When running on macos it is currently not possible to analyze Go in conjunction with any of Java, C/C++, or C#. Each language can still be analyzed separately.

lib/external-queries.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/shared-environment.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

queries/undeclared-action-input.ql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @name Undeclared action input
3+
* @description Code tries to use an input parameter that is not defined for this action.
4+
Perhaps this code is shared by multiple actions.
5+
* @kind problem
6+
* @problem.severity error
7+
* @id javascript/codeql-action/undeclared-action-input
8+
*/
9+
10+
import javascript
11+
12+
class ActionDeclaration extends File {
13+
ActionDeclaration() {
14+
getRelativePath().matches("%/action.yml")
15+
}
16+
17+
string getName() {
18+
result = getRelativePath().regexpCapture("(.*)/action.yml", 1)
19+
}
20+
21+
YAMLDocument getRootNode() {
22+
result.getFile() = this
23+
}
24+
25+
string getAnInput() {
26+
result = getRootNode().(YAMLMapping).lookup("inputs").(YAMLMapping).getKey(_).(YAMLString).getValue()
27+
}
28+
29+
FunctionDeclStmt getEntrypoint() {
30+
result.getFile().getRelativePath() = getRootNode().
31+
(YAMLMapping).lookup("runs").
32+
(YAMLMapping).lookup("main").
33+
(YAMLString).getValue().regexpReplaceAll("\\.\\./lib/(.*)\\.js", "src/$1.ts") and
34+
result.getName() = "run"
35+
}
36+
}
37+
38+
Expr getAFunctionChildExpr(Function f) {
39+
result.getContainer() = f
40+
}
41+
42+
/*
43+
* Result is a function that is called from the body of the given function `f`
44+
*/
45+
Function calledBy(Function f) {
46+
result = getAFunctionChildExpr(f).(InvokeExpr).getResolvedCallee()
47+
or
48+
result.getEnclosingContainer() = f // assume outer function causes inner function to be called
49+
}
50+
51+
class GetInputMethodCallExpr extends MethodCallExpr {
52+
GetInputMethodCallExpr() {
53+
getMethodName() = "getInput"
54+
}
55+
56+
string getInputName() {
57+
result = getArgument(0).(StringLiteral).getValue()
58+
}
59+
}
60+
61+
from ActionDeclaration action, GetInputMethodCallExpr getInputCall, string inputName
62+
where getAFunctionChildExpr(calledBy*(action.getEntrypoint())) = getInputCall and
63+
inputName = getInputCall.getInputName() and
64+
not inputName = action.getAnInput()
65+
select getInputCall, "The $@ input is not defined for the $@ action", inputName, inputName, action, action.getName()

src/external-queries.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import * as path from "path";
33

44
import * as configUtils from "./config-utils";
55
import * as externalQueries from "./external-queries";
6+
import * as util from "./util";
67

78
test("checkoutExternalQueries", async () => {
89
let config = new configUtils.Config();
910
config.externalQueries = [
1011
new configUtils.ExternalQuery("github/codeql-go", "df4c6869212341b601005567381944ed90906b6b"),
1112
];
12-
await externalQueries.checkoutExternalQueries(config);
1313

14-
let destination = process.env["RUNNER_WORKSPACE"] || "/tmp/codeql-action/";
15-
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master
16-
expect(fs.existsSync(path.join(destination, "github", "codeql-go", "COPYRIGHT"))).toBeTruthy();
14+
await util.withTmpDir(async tmpDir => {
15+
process.env["RUNNER_WORKSPACE"] = tmpDir;
16+
await externalQueries.checkoutExternalQueries(config);
17+
18+
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master
19+
expect(fs.existsSync(path.join(tmpDir, "github", "codeql-go", "COPYRIGHT"))).toBeTruthy();
20+
});
1721
});

src/external-queries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import * as fs from 'fs';
44
import * as path from 'path';
55

66
import * as configUtils from './config-utils';
7+
import * as util from './util';
78

89
export async function checkoutExternalQueries(config: configUtils.Config) {
9-
const folder = process.env['RUNNER_WORKSPACE'] || '/tmp/codeql-action';
10+
const folder = util.getRequiredEnvParam('RUNNER_WORKSPACE');
1011

1112
for (const externalQuery of config.externalQueries) {
1213
core.info('Checking out ' + externalQuery.repository);

src/shared-environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const CODEQL_ACTION_CMD = 'CODEQL_ACTION_CMD';
22
export const CODEQL_ACTION_DATABASE_DIR = 'CODEQL_ACTION_DATABASE_DIR';
33
export const CODEQL_ACTION_LANGUAGES = 'CODEQL_ACTION_LANGUAGES';
4+
export const CODEQL_ACTION_ANALYSIS_KEY = 'CODEQL_ACTION_ANALYSIS_KEY';
45
export const ODASA_TRACER_CONFIGURATION = 'ODASA_TRACER_CONFIGURATION';
56
export const CODEQL_ACTION_SCANNED_LANGUAGES = 'CODEQL_ACTION_SCANNED_LANGUAGES';
67
export const CODEQL_ACTION_TRACED_LANGUAGES = 'CODEQL_ACTION_TRACED_LANGUAGES';

src/upload-lib.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
146146
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
147147
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
148148
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
149+
const analysisKey = await util.getAnalysisKey();
149150
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
150151
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
151152

@@ -173,6 +174,7 @@ async function uploadFiles(sarifFiles: string[]): Promise<boolean> {
173174
const payload = JSON.stringify({
174175
"commit_oid": commitOid,
175176
"ref": ref,
177+
"analysis_key": analysisKey,
176178
"analysis_name": analysisName,
177179
"sarif": zipped_sarif,
178180
"workflow_run_id": workflowRunID,

0 commit comments

Comments
 (0)