Prompt customers to upgrade from v1 to v2
This commit is contained in:
parent
ff8b365e79
commit
0256599547
18 changed files with 189 additions and 13 deletions
|
|
@ -69,6 +69,7 @@ async function run() {
|
|||
let runStats: QueriesStatusReport | undefined = undefined;
|
||||
let config: Config | undefined = undefined;
|
||||
util.initializeEnvironment(util.Mode.actions, pkg.version);
|
||||
await util.checkActionVersion(pkg.version);
|
||||
|
||||
try {
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { determineAutobuildLanguage, runAutobuild } from "./autobuild";
|
|||
import * as config_utils from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { initializeEnvironment, Mode } from "./util";
|
||||
import { checkActionVersion, initializeEnvironment, Mode } from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
const pkg = require("../package.json");
|
||||
|
|
@ -49,8 +49,9 @@ async function sendCompletedStatusReport(
|
|||
}
|
||||
|
||||
async function run() {
|
||||
const logger = getActionsLogger();
|
||||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
await checkActionVersion(pkg.version);
|
||||
let language: Language | undefined = undefined;
|
||||
try {
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import {
|
|||
DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
DEFAULT_DEBUG_DATABASE_NAME,
|
||||
getMlPoweredJsQueriesStatus,
|
||||
checkActionVersion,
|
||||
} from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
|
|
@ -124,6 +125,7 @@ async function run() {
|
|||
const startedAt = new Date();
|
||||
const logger = getActionsLogger();
|
||||
initializeEnvironment(Mode.actions, pkg.version);
|
||||
await checkActionVersion(pkg.version);
|
||||
|
||||
let config: configUtils.Config;
|
||||
let codeql: CodeQL;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ import { getGitHubVersionActionsOnly } from "./api-client";
|
|||
import { getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import { getRequiredEnvParam, initializeEnvironment, Mode } from "./util";
|
||||
import {
|
||||
checkActionVersion,
|
||||
getRequiredEnvParam,
|
||||
initializeEnvironment,
|
||||
Mode,
|
||||
} from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
const pkg = require("../package.json");
|
||||
|
|
@ -31,8 +36,9 @@ async function sendSuccessStatusReport(
|
|||
}
|
||||
|
||||
async function run() {
|
||||
initializeEnvironment(Mode.actions, pkg.version);
|
||||
const startedAt = new Date();
|
||||
initializeEnvironment(Mode.actions, pkg.version);
|
||||
await checkActionVersion(pkg.version);
|
||||
if (
|
||||
!(await actionsUtil.sendStatusReport(
|
||||
await actionsUtil.createStatusReportBase(
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import * as fs from "fs";
|
|||
import * as os from "os";
|
||||
import * as stream from "stream";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import * as sinon from "sinon";
|
||||
|
|
@ -392,3 +393,49 @@ test("isGitHubGhesVersionBelow", async (t) => {
|
|||
)
|
||||
);
|
||||
});
|
||||
|
||||
const CHECK_ACTION_VERSION_TESTS: Array<[string, util.GitHubVersion, boolean]> =
|
||||
[
|
||||
["1.2.1", { type: util.GitHubVariant.DOTCOM }, true],
|
||||
["1.2.1", { type: util.GitHubVariant.GHAE }, true],
|
||||
["1.2.1", { type: util.GitHubVariant.GHES, version: "3.3" }, false],
|
||||
["1.2.1", { type: util.GitHubVariant.GHES, version: "3.4" }, true],
|
||||
["1.2.1", { type: util.GitHubVariant.GHES, version: "3.5" }, true],
|
||||
["2.2.1", { type: util.GitHubVariant.DOTCOM }, false],
|
||||
["2.2.1", { type: util.GitHubVariant.GHAE }, false],
|
||||
["2.2.1", { type: util.GitHubVariant.GHES, version: "3.3" }, false],
|
||||
["2.2.1", { type: util.GitHubVariant.GHES, version: "3.4" }, false],
|
||||
["2.2.1", { type: util.GitHubVariant.GHES, version: "3.5" }, false],
|
||||
];
|
||||
|
||||
for (const [
|
||||
version,
|
||||
githubVersion,
|
||||
shouldReportWarning,
|
||||
] of CHECK_ACTION_VERSION_TESTS) {
|
||||
const reportWarningDescription = shouldReportWarning
|
||||
? "reports warning"
|
||||
: "doesn't report warning";
|
||||
const versionsDescription = `CodeQL Action version ${version} and GitHub version ${util.formatGitHubVersion(
|
||||
githubVersion
|
||||
)}`;
|
||||
test(`checkActionVersion ${reportWarningDescription} for ${versionsDescription}`, async (t) => {
|
||||
const warningSpy = sinon.spy(core, "warning");
|
||||
const versionStub = sinon
|
||||
.stub(api, "getGitHubVersionActionsOnly")
|
||||
.resolves(githubVersion);
|
||||
const isActionsStub = sinon.stub(util, "isActions").returns(true);
|
||||
await util.checkActionVersion(version);
|
||||
if (shouldReportWarning) {
|
||||
t.true(
|
||||
warningSpy.calledOnceWithExactly(
|
||||
sinon.match("CodeQL Action version 1 will be deprecated")
|
||||
)
|
||||
);
|
||||
} else {
|
||||
t.false(warningSpy.called);
|
||||
}
|
||||
versionStub.restore();
|
||||
isActionsStub.restore();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
43
src/util.ts
43
src/util.ts
|
|
@ -7,6 +7,7 @@ import * as core from "@actions/core";
|
|||
import del from "del";
|
||||
import * as semver from "semver";
|
||||
|
||||
import * as api from "./api-client";
|
||||
import { getApiClient, GitHubApiDetails } from "./api-client";
|
||||
import * as apiCompatibility from "./api-compatibility.json";
|
||||
import { CodeQL, CODEQL_VERSION_NEW_TRACING } from "./codeql";
|
||||
|
|
@ -708,3 +709,45 @@ export function getMlPoweredJsQueriesStatus(config: Config): string {
|
|||
return "other";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the customer to upgrade to CodeQL Action v2, if appropriate.
|
||||
*
|
||||
* Check whether a customer is running v1. If they are, and we can determine that the GitHub
|
||||
* instance supports v2, then log a warning about v1's upcoming deprecation prompting the customer
|
||||
* to upgrade to v2.
|
||||
*/
|
||||
export async function checkActionVersion(version: string) {
|
||||
if (!semver.satisfies(version, ">=2")) {
|
||||
const githubVersion = await api.getGitHubVersionActionsOnly();
|
||||
// Only log a warning for versions of GHES that are compatible with CodeQL Action version 2.
|
||||
if (
|
||||
githubVersion.type === GitHubVariant.DOTCOM ||
|
||||
githubVersion.type === GitHubVariant.GHAE ||
|
||||
(githubVersion.type === GitHubVariant.GHES &&
|
||||
semver.satisfies(
|
||||
semver.coerce(githubVersion.version) ?? "0.0.0",
|
||||
">=3.4"
|
||||
))
|
||||
) {
|
||||
core.warning(
|
||||
"CodeQL Action version 1 will be deprecated on December 7th, 2022. Please upgrade to " +
|
||||
"version 2. For more information, see " +
|
||||
"https://github.blog/changelog/2022-04-27-code-scanning-deprecation-of-codeql-action-v1/."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function formatGitHubVersion(version: GitHubVersion): string {
|
||||
switch (version.type) {
|
||||
case GitHubVariant.DOTCOM:
|
||||
return "dotcom";
|
||||
case GitHubVariant.GHAE:
|
||||
return "GHAE";
|
||||
case GitHubVariant.GHES:
|
||||
return `GHES ${version.version}`;
|
||||
default:
|
||||
assertNever(version);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue