Refactor: reuse getArtifactUploaderClient in start-proxy-action

This commit is contained in:
Angela P Wen
2024-09-26 13:41:28 -07:00
parent ce99e3489b
commit 0c5c594f45
9 changed files with 62 additions and 81 deletions
+1 -1
View File
@@ -2,9 +2,9 @@ import test from "ava";
import * as debugArtifacts from "./debug-artifacts";
import { Feature } from "./feature-flags";
import { getActionsLogger } from "./logging";
import { createFeatures } from "./testing-utils";
import { GitHubVariant } from "./util";
import { getActionsLogger } from "./logging";
test("sanitizeArtifactName", (t) => {
t.deepEqual(
+30 -19
View File
@@ -263,25 +263,11 @@ export async function uploadDebugArtifacts(
}
}
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
// until it is supported. We also use the legacy version of the client if the feature flag is disabled.
let artifactUploader: artifact.ArtifactClient | artifactLegacy.ArtifactClient;
if (ghVariant === GitHubVariant.GHES) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the `v2` version is not yet supported on GHES.",
);
artifactUploader = artifactLegacy.create();
} else if (!(await features.getValue(Feature.ArtifactV2Upgrade))) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the value of the relevant feature flag is false. To use the `v2` version of the client, set the `CODEQL_ACTION_ARTIFACT_V2_UPGRADE` environment variable to true.",
);
artifactUploader = artifactLegacy.create();
} else {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v2` client.",
);
artifactUploader = new artifact.DefaultArtifactClient();
}
const artifactUploader = await getArtifactUploaderClient(
logger,
ghVariant,
features,
);
try {
await artifactUploader.uploadArtifact(
@@ -299,6 +285,31 @@ export async function uploadDebugArtifacts(
}
}
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
// until it is supported. We also use the legacy version of the client if the feature flag is disabled.
export async function getArtifactUploaderClient(
logger: Logger,
ghVariant: GitHubVariant,
features: FeatureEnablement,
): Promise<artifact.ArtifactClient | artifactLegacy.ArtifactClient> {
if (ghVariant === GitHubVariant.GHES) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the `v2` version is not yet supported on GHES.",
);
return artifactLegacy.create();
} else if (!(await features.getValue(Feature.ArtifactV2Upgrade))) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the value of the relevant feature flag is false. To use the `v2` version of the client, set the `CODEQL_ACTION_ARTIFACT_V2_UPGRADE` environment variable to true.",
);
return artifactLegacy.create();
} else {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v2` client.",
);
return new artifact.DefaultArtifactClient();
}
}
/**
* If a database has not been finalized, we cannot run the `codeql database bundle`
* command in the CLI because it will return an error. Instead we directly zip
+7 -25
View File
@@ -3,21 +3,19 @@
* It will run after the all steps in this job, in reverse order in relation to
* other `post:` hooks.
*/
import * as artifact from "@actions/artifact";
import * as artifactLegacy from "@actions/artifact-legacy";
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import { getGitHubVersion } from "./api-client";
import * as configUtils from "./config-utils";
import { Feature, Features } from "./feature-flags";
import { getArtifactUploaderClient } from "./debug-artifacts";
import { Features } from "./feature-flags";
import { getActionsLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
checkGitHubVersionInRange,
getErrorMessage,
getRequiredEnvParam,
GitHubVariant,
} from "./util";
async function runWrapper() {
@@ -62,27 +60,11 @@ async function runWrapper() {
);
try {
// `@actions/artifact@v2` is not yet supported on GHES so the legacy version of the client will be used on GHES
// until it is supported. We also use the legacy version of the client if the feature flag is disabled.
let artifactUploader:
| artifact.ArtifactClient
| artifactLegacy.ArtifactClient;
if (gitHubVersion.type === GitHubVariant.GHES) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the `v2` version is not yet supported on GHES.",
);
artifactUploader = artifactLegacy.create();
} else if (!(await features.getValue(Feature.ArtifactV2Upgrade))) {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v1` client because the value of the relevant feature flag is false. To use the `v2` version of the client, set the `CODEQL_ACTION_ARTIFACT_V2_UPGRADE` environment variable to true.",
);
artifactUploader = artifactLegacy.create();
} else {
logger.info(
"Uploading debug artifacts using the `@actions/artifact@v2` client.",
);
artifactUploader = new artifact.DefaultArtifactClient();
}
const artifactUploader = await getArtifactUploaderClient(
logger,
gitHubVersion.type,
features,
);
await artifactUploader.uploadArtifact(
"proxy-log-file",