mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 22:50:17 +08:00
use tmp dir for external queries test
This commit is contained in:
@@ -3,15 +3,19 @@ import * as path from "path";
|
||||
|
||||
import * as configUtils from "./config-utils";
|
||||
import * as externalQueries from "./external-queries";
|
||||
import * as util from "./util";
|
||||
|
||||
test("checkoutExternalQueries", async () => {
|
||||
let config = new configUtils.Config();
|
||||
config.externalQueries = [
|
||||
new configUtils.ExternalQuery("github/codeql-go", "df4c6869212341b601005567381944ed90906b6b"),
|
||||
];
|
||||
await externalQueries.checkoutExternalQueries(config);
|
||||
|
||||
let destination = process.env["RUNNER_WORKSPACE"] || "/tmp/codeql-action/";
|
||||
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master
|
||||
expect(fs.existsSync(path.join(destination, "github", "codeql-go", "COPYRIGHT"))).toBeTruthy();
|
||||
await util.withTmpDir(async tmpDir => {
|
||||
process.env["RUNNER_WORKSPACE"] = tmpDir;
|
||||
await externalQueries.checkoutExternalQueries(config);
|
||||
|
||||
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in master
|
||||
expect(fs.existsSync(path.join(tmpDir, "github", "codeql-go", "COPYRIGHT"))).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,9 +4,10 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as configUtils from './config-utils';
|
||||
import * as util from './util';
|
||||
|
||||
export async function checkoutExternalQueries(config: configUtils.Config) {
|
||||
const folder = process.env['RUNNER_WORKSPACE'] || '/tmp/codeql-action';
|
||||
const folder = util.getRequiredEnvParam('RUNNER_WORKSPACE');
|
||||
|
||||
for (const externalQuery of config.externalQueries) {
|
||||
core.info('Checking out ' + externalQuery.repository);
|
||||
|
||||
10
src/util.ts
10
src/util.ts
@@ -3,6 +3,8 @@ import * as http from '@actions/http-client';
|
||||
import * as auth from '@actions/http-client/auth';
|
||||
import * as octokit from '@octokit/rest';
|
||||
import consoleLogLevel from 'console-log-level';
|
||||
import * as fs from "fs";
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as sharedEnv from './shared-environment';
|
||||
@@ -313,3 +315,11 @@ export function getToolNames(sarifContents: string): string[] {
|
||||
|
||||
return Object.keys(toolNames);
|
||||
}
|
||||
|
||||
// Creates a random temporary directory, runs the given body, and then deletes the directory.
|
||||
// Mostly intended for use within tests.
|
||||
export async function withTmpDir(body: (tmpDir: string) => Promise<void>) {
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codeql-action-'));
|
||||
await body(tmpDir);
|
||||
fs.rmdirSync(tmpDir, { recursive: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user