Skip to content

Commit 43de3a9

Browse files
start uploading analysis_key parameter
1 parent 1cdde3e commit 43de3a9

6 files changed

Lines changed: 95 additions & 0 deletions

File tree

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: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
@@ -76,6 +76,7 @@ async function uploadFiles(sarifFiles: string[]) {
7676
const commitOid = util.getRequiredEnvParam('GITHUB_SHA');
7777
const workflowRunIDStr = util.getRequiredEnvParam('GITHUB_RUN_ID');
7878
const ref = util.getRequiredEnvParam('GITHUB_REF'); // it's in the form "refs/heads/master"
79+
const analysisKey = await util.getAnalysisKey();
7980
const analysisName = util.getRequiredEnvParam('GITHUB_WORKFLOW');
8081
const startedAt = process.env[sharedEnv.CODEQL_ACTION_STARTED_AT];
8182

@@ -103,6 +104,7 @@ async function uploadFiles(sarifFiles: string[]) {
103104
const payload = JSON.stringify({
104105
"commit_oid": commitOid,
105106
"ref": ref,
107+
"analysis_key": analysisKey,
106108
"analysis_name": analysisName,
107109
"sarif": zipped_sarif,
108110
"workflow_run_id": workflowRunID,

src/util.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,54 @@ export async function getLanguages(): Promise<string[]> {
150150
return languages;
151151
}
152152

153+
/**
154+
* Get the path of the currently executing workflow.
155+
*/
156+
async function getWorkflowPath(): Promise<string> {
157+
const repo_nwo = getRequiredEnvParam('GITHUB_REPOSITORY').split("/");
158+
const owner = repo_nwo[0];
159+
const repo = repo_nwo[1];
160+
const run_id = getRequiredEnvParam('GITHUB_RUN_ID');
161+
162+
const ok = new octokit.Octokit({
163+
auth: core.getInput('token'),
164+
userAgent: "CodeQL Action",
165+
log: consoleLogLevel({ level: 'debug' })
166+
});
167+
168+
const runsResponse = await ok.request('GET /repos/:owner/:repo/actions/runs/:run_id', {
169+
owner,
170+
repo,
171+
run_id
172+
});
173+
const workflowUrl = runsResponse.data.workflow_url;
174+
175+
const workflowResponse = await ok.request('GET ' + workflowUrl);
176+
177+
return workflowResponse.data.path;
178+
}
179+
180+
/**
181+
* Get the analysis key paramter for the current job.
182+
*
183+
* This will combine the workflow path and current job name.
184+
* Computing this the first time requires making requests to
185+
* the github API, but after that the result will be cached.
186+
*/
187+
export async function getAnalysisKey(): Promise<string> {
188+
let analysisKey = process.env[sharedEnv.CODEQL_ACTION_ANALYSIS_KEY];
189+
if (analysisKey !== undefined) {
190+
return analysisKey;
191+
}
192+
193+
const workflowPath = await getWorkflowPath();
194+
const jobName = getRequiredEnvParam('GITHUB_JOB');
195+
196+
analysisKey = workflowPath + ' - ' + jobName;
197+
core.exportVariable(sharedEnv.CODEQL_ACTION_ANALYSIS_KEY, analysisKey);
198+
return analysisKey;
199+
}
200+
153201
interface StatusReport {
154202
"workflow_run_id": number;
155203
"workflow_name": string;

0 commit comments

Comments
 (0)