Convert deprecation warning to error

This commit is contained in:
Angela P Wen 2025-01-07 13:59:42 -08:00
parent a06dbc607d
commit 04b5afaa72
9 changed files with 44 additions and 39 deletions

2
lib/environment.js generated
View file

@ -43,6 +43,8 @@ var EnvVar;
EnvVar["HAS_WARNED_ABOUT_DISK_SPACE"] = "CODEQL_ACTION_HAS_WARNED_ABOUT_DISK_SPACE"; EnvVar["HAS_WARNED_ABOUT_DISK_SPACE"] = "CODEQL_ACTION_HAS_WARNED_ABOUT_DISK_SPACE";
/** Whether the init action has been run. */ /** Whether the init action has been run. */
EnvVar["INIT_ACTION_HAS_RUN"] = "CODEQL_ACTION_INIT_HAS_RUN"; EnvVar["INIT_ACTION_HAS_RUN"] = "CODEQL_ACTION_INIT_HAS_RUN";
/** Whether the error for a deprecated version of the CodeQL Action was logged. */
EnvVar["LOG_VERSION_DEPRECATION"] = "CODEQL_ACTION_DID_LOG_VERSION_DEPRECATION";
/** /**
* For macOS. Result of `csrutil status` to determine whether System Integrity * For macOS. Result of `csrutil status` to determine whether System Integrity
* Protection is enabled. * Protection is enabled.

View file

@ -1 +1 @@
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,MA2GX;AA3GD,WAAY,MAAM;IAChB,2DAA2D;IAC3D,+FAAqF,CAAA;IAErF,6DAA6D;IAC7D,mGAAyF,CAAA;IAEzF;;;OAGG;IACH,4CAAkC,CAAA;IAElC,gEAAgE;IAChE,qEAA2D,CAAA;IAE3D;;;OAGG;IACH,yFAA+E,CAAA;IAE/E;;;OAGG;IACH,yEAA+D,CAAA;IAE/D,gFAAgF;IAChF,6DAAmD,CAAA;IAEnD;;;OAGG;IACH,uEAA6D,CAAA;IAE7D,gEAAgE;IAChE,mEAAyD,CAAA;IAEzD,kFAAkF;IAClF,mFAAyE,CAAA;IAEzE,4CAA4C;IAC5C,4DAAkD,CAAA;IAElD;;;OAGG;IACH,yDAA+C,CAAA;IAE/C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F,mFAAmF;IACnF,6FAAmF,CAAA;IAEnF,qFAAqF;IACrF,+CAAqC,CAAA;IAErC,mEAAyD,CAAA;IAEzD,kEAAkE;IAClE,2CAAiC,CAAA;IAEjC;;;;;;OAMG;IACH,4DAAkD,CAAA;IAElD;;;OAGG;IACH,wDAA8C,CAAA;IAE9C;;;;OAIG;IACH,iEAAuD,CAAA;IAEvD;;;OAGG;IACH,6EAAmE,CAAA;AACrE,CAAC,EA9GW,MAAM,sBAAN,MAAM,QA8GjB"}

17
lib/util.js generated
View file

@ -848,15 +848,14 @@ async function checkDiskUsage(logger) {
/** /**
* Prompt the customer to upgrade to CodeQL Action v3, if appropriate. * Prompt the customer to upgrade to CodeQL Action v3, if appropriate.
* *
* Check whether a customer is running v2. If they are, and we can determine that the GitHub * Check whether a customer is running v1 or v2. If they are, and we can determine that the GitHub
* instance supports v3, then log a warning about v2's upcoming deprecation prompting the customer * instance supports v3, then log an error prompting the customer to upgrade to v3.
* to upgrade to v3.
*/ */
function checkActionVersion(version, githubVersion) { function checkActionVersion(version, githubVersion) {
if (!semver.satisfies(version, ">=3") && // do not warn if the customer is already running v3 if (!semver.satisfies(version, ">=3") && // do not log error if the customer is already running v3
!process.env.CODEQL_V2_DEPRECATION_WARNING // do not warn if we have already warned !process.env[environment_1.EnvVar.LOG_VERSION_DEPRECATION] // do not log error if we have already
) { ) {
// Only log a warning for versions of GHES that are compatible with CodeQL Action version 3. // Only error for versions of GHES that are compatible with CodeQL Action version 3.
// //
// GHES 3.11 shipped without the v3 tag, but it also shipped without this warning message code. // GHES 3.11 shipped without the v3 tag, but it also shipped without this warning message code.
// Therefore users who are seeing this warning message code have pulled in a new version of the // Therefore users who are seeing this warning message code have pulled in a new version of the
@ -865,12 +864,12 @@ function checkActionVersion(version, githubVersion) {
githubVersion.type === GitHubVariant.GHE_DOTCOM || githubVersion.type === GitHubVariant.GHE_DOTCOM ||
(githubVersion.type === GitHubVariant.GHES && (githubVersion.type === GitHubVariant.GHES &&
semver.satisfies(semver.coerce(githubVersion.version) ?? "0.0.0", ">=3.11"))) { semver.satisfies(semver.coerce(githubVersion.version) ?? "0.0.0", ">=3.11"))) {
core.warning("CodeQL Action v2 will be deprecated on December 5th, 2024. " + core.error("CodeQL Action major versions v1 and v2 have been deprecated. " +
"Please update all occurrences of the CodeQL Action in your workflow files to v3. " + "Please update all occurrences of the CodeQL Action in your workflow files to v3. " +
"For more information, see " + "For more information, see " +
"https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/"); "https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/");
// set CODEQL_V2_DEPRECATION_WARNING env var to prevent the warning from being logged multiple times // set LOG_VERSION_DEPRECATION env var to prevent the warning from being logged multiple times
core.exportVariable("CODEQL_V2_DEPRECATION_WARNING", "true"); core.exportVariable(environment_1.EnvVar.LOG_VERSION_DEPRECATION, "true");
} }
} }
} }

File diff suppressed because one or more lines are too long

16
lib/util.test.js generated
View file

@ -350,21 +350,21 @@ const CHECK_ACTION_VERSION_TESTS = [
["3.2.1", { type: util.GitHubVariant.GHES, version: "3.11" }, false], ["3.2.1", { type: util.GitHubVariant.GHES, version: "3.11" }, false],
["3.2.1", { type: util.GitHubVariant.GHES, version: "3.12" }, false], ["3.2.1", { type: util.GitHubVariant.GHES, version: "3.12" }, false],
]; ];
for (const [version, githubVersion, shouldReportWarning,] of CHECK_ACTION_VERSION_TESTS) { for (const [version, githubVersion, shouldReportError,] of CHECK_ACTION_VERSION_TESTS) {
const reportWarningDescription = shouldReportWarning const reportErrorDescription = shouldReportError
? "reports warning" ? "reports error"
: "doesn't report warning"; : "doesn't report error";
const versionsDescription = `CodeQL Action version ${version} and GitHub version ${formatGitHubVersion(githubVersion)}`; const versionsDescription = `CodeQL Action version ${version} and GitHub version ${formatGitHubVersion(githubVersion)}`;
(0, ava_1.default)(`checkActionVersion ${reportWarningDescription} for ${versionsDescription}`, async (t) => { (0, ava_1.default)(`checkActionVersion ${reportErrorDescription} for ${versionsDescription}`, async (t) => {
const warningSpy = sinon.spy(core, "warning"); const warningSpy = sinon.spy(core, "error");
const versionStub = sinon const versionStub = sinon
.stub(api, "getGitHubVersion") .stub(api, "getGitHubVersion")
.resolves(githubVersion); .resolves(githubVersion);
// call checkActionVersion twice and assert below that warning is reported only once // call checkActionVersion twice and assert below that warning is reported only once
util.checkActionVersion(version, await api.getGitHubVersion()); util.checkActionVersion(version, await api.getGitHubVersion());
util.checkActionVersion(version, await api.getGitHubVersion()); util.checkActionVersion(version, await api.getGitHubVersion());
if (shouldReportWarning) { if (shouldReportError) {
t.true(warningSpy.calledOnceWithExactly(sinon.match("CodeQL Action v2 will be deprecated"))); t.true(warningSpy.calledOnceWithExactly(sinon.match("CodeQL Action major versions v1 and v2 have been deprecated.")));
} }
else { else {
t.false(warningSpy.called); t.false(warningSpy.called);

File diff suppressed because one or more lines are too long

View file

@ -50,6 +50,9 @@ export enum EnvVar {
/** Whether the init action has been run. */ /** Whether the init action has been run. */
INIT_ACTION_HAS_RUN = "CODEQL_ACTION_INIT_HAS_RUN", INIT_ACTION_HAS_RUN = "CODEQL_ACTION_INIT_HAS_RUN",
/** Whether the error for a deprecated version of the CodeQL Action was logged. */
LOG_VERSION_DEPRECATION = "CODEQL_ACTION_DID_LOG_VERSION_DEPRECATION",
/** /**
* For macOS. Result of `csrutil status` to determine whether System Integrity * For macOS. Result of `csrutil status` to determine whether System Integrity
* Protection is enabled. * Protection is enabled.

View file

@ -431,16 +431,16 @@ const CHECK_ACTION_VERSION_TESTS: Array<[string, util.GitHubVersion, boolean]> =
for (const [ for (const [
version, version,
githubVersion, githubVersion,
shouldReportWarning, shouldReportError,
] of CHECK_ACTION_VERSION_TESTS) { ] of CHECK_ACTION_VERSION_TESTS) {
const reportWarningDescription = shouldReportWarning const reportErrorDescription = shouldReportError
? "reports warning" ? "reports error"
: "doesn't report warning"; : "doesn't report error";
const versionsDescription = `CodeQL Action version ${version} and GitHub version ${formatGitHubVersion( const versionsDescription = `CodeQL Action version ${version} and GitHub version ${formatGitHubVersion(
githubVersion, githubVersion,
)}`; )}`;
test(`checkActionVersion ${reportWarningDescription} for ${versionsDescription}`, async (t) => { test(`checkActionVersion ${reportErrorDescription} for ${versionsDescription}`, async (t) => {
const warningSpy = sinon.spy(core, "warning"); const warningSpy = sinon.spy(core, "error");
const versionStub = sinon const versionStub = sinon
.stub(api, "getGitHubVersion") .stub(api, "getGitHubVersion")
.resolves(githubVersion); .resolves(githubVersion);
@ -449,10 +449,12 @@ for (const [
util.checkActionVersion(version, await api.getGitHubVersion()); util.checkActionVersion(version, await api.getGitHubVersion());
util.checkActionVersion(version, await api.getGitHubVersion()); util.checkActionVersion(version, await api.getGitHubVersion());
if (shouldReportWarning) { if (shouldReportError) {
t.true( t.true(
warningSpy.calledOnceWithExactly( warningSpy.calledOnceWithExactly(
sinon.match("CodeQL Action v2 will be deprecated"), sinon.match(
"CodeQL Action major versions v1 and v2 have been deprecated.",
),
), ),
); );
} else { } else {

View file

@ -1071,19 +1071,18 @@ export async function checkDiskUsage(
/** /**
* Prompt the customer to upgrade to CodeQL Action v3, if appropriate. * Prompt the customer to upgrade to CodeQL Action v3, if appropriate.
* *
* Check whether a customer is running v2. If they are, and we can determine that the GitHub * Check whether a customer is running v1 or v2. If they are, and we can determine that the GitHub
* instance supports v3, then log a warning about v2's upcoming deprecation prompting the customer * instance supports v3, then log an error prompting the customer to upgrade to v3.
* to upgrade to v3.
*/ */
export function checkActionVersion( export function checkActionVersion(
version: string, version: string,
githubVersion: GitHubVersion, githubVersion: GitHubVersion,
) { ) {
if ( if (
!semver.satisfies(version, ">=3") && // do not warn if the customer is already running v3 !semver.satisfies(version, ">=3") && // do not log error if the customer is already running v3
!process.env.CODEQL_V2_DEPRECATION_WARNING // do not warn if we have already warned !process.env[EnvVar.LOG_VERSION_DEPRECATION] // do not log error if we have already
) { ) {
// Only log a warning for versions of GHES that are compatible with CodeQL Action version 3. // Only error for versions of GHES that are compatible with CodeQL Action version 3.
// //
// GHES 3.11 shipped without the v3 tag, but it also shipped without this warning message code. // GHES 3.11 shipped without the v3 tag, but it also shipped without this warning message code.
// Therefore users who are seeing this warning message code have pulled in a new version of the // Therefore users who are seeing this warning message code have pulled in a new version of the
@ -1097,14 +1096,14 @@ export function checkActionVersion(
">=3.11", ">=3.11",
)) ))
) { ) {
core.warning( core.error(
"CodeQL Action v2 will be deprecated on December 5th, 2024. " + "CodeQL Action major versions v1 and v2 have been deprecated. " +
"Please update all occurrences of the CodeQL Action in your workflow files to v3. " + "Please update all occurrences of the CodeQL Action in your workflow files to v3. " +
"For more information, see " + "For more information, see " +
"https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/", "https://github.blog/changelog/2024-01-12-code-scanning-deprecation-of-codeql-action-v2/", // TODO: update to new changelog post when published
); );
// set CODEQL_V2_DEPRECATION_WARNING env var to prevent the warning from being logged multiple times // set LOG_VERSION_DEPRECATION env var to prevent the warning from being logged multiple times
core.exportVariable("CODEQL_V2_DEPRECATION_WARNING", "true"); core.exportVariable(EnvVar.LOG_VERSION_DEPRECATION, "true");
} }
} }
} }