mirror of
https://github.com/github/codeql-action.git
synced 2026-10-30 01:27:22 +00:00
Refactor swift check out of init-action.ts
This commit is contained in:
@@ -56,6 +56,7 @@ import {
|
||||
runDatabaseInitCluster,
|
||||
} from "./init";
|
||||
import { JavaEnvVars, BuiltInLanguage } from "./languages";
|
||||
import { isSwiftCompatible } from "./languages/swift";
|
||||
import { Logger, withGroupAsync } from "./logging";
|
||||
import {
|
||||
downloadOverlayBaseDatabaseFromCache,
|
||||
@@ -418,14 +419,7 @@ async function run(
|
||||
logger,
|
||||
});
|
||||
|
||||
if (
|
||||
config.languages.includes(BuiltInLanguage.swift) &&
|
||||
process.platform !== "darwin"
|
||||
) {
|
||||
throw new ConfigurationError(
|
||||
`Swift analysis is only supported on macOS runner images. Please migrate to a macOS runner.`,
|
||||
);
|
||||
}
|
||||
isSwiftCompatible(actionState, config);
|
||||
|
||||
if (repositoryPropertiesResult.isFailure()) {
|
||||
addNoLanguageDiagnostic(
|
||||
|
||||
43
src/languages/swift.test.ts
Normal file
43
src/languages/swift.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import test from "ava";
|
||||
|
||||
import { createTestConfig, initAllState } from "../testing-utils";
|
||||
|
||||
import { isSwiftCompatible } from "./swift";
|
||||
|
||||
import { BuiltInLanguage } from ".";
|
||||
|
||||
test("isSwiftCompatible doesn't throw for non-Swift languages", (t) => {
|
||||
for (const language of Object.values(BuiltInLanguage)) {
|
||||
if (language === BuiltInLanguage.swift) {
|
||||
continue;
|
||||
}
|
||||
|
||||
t.notThrows(() =>
|
||||
isSwiftCompatible(
|
||||
initAllState(),
|
||||
createTestConfig({ languages: [language] }),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("isSwiftCompatible doesn't throw for Swift on darwin", (t) => {
|
||||
t.notThrows(() => {
|
||||
isSwiftCompatible(
|
||||
initAllState({ platform: "darwin" }),
|
||||
createTestConfig({ languages: [BuiltInLanguage.swift] }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const nonDarwinPlatforms: NodeJS.Platform[] = ["linux", "win32"];
|
||||
for (const nonDarwinPlatform of nonDarwinPlatforms) {
|
||||
test(`isSwiftCompatible throws for Swift on ${nonDarwinPlatform}`, (t) => {
|
||||
t.throws(() => {
|
||||
isSwiftCompatible(
|
||||
initAllState({ platform: nonDarwinPlatform }),
|
||||
createTestConfig({ languages: [BuiltInLanguage.swift] }),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
28
src/languages/swift.ts
Normal file
28
src/languages/swift.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ActionState } from "../action-common";
|
||||
import { Config } from "../config-utils";
|
||||
import { ConfigurationError } from "../util";
|
||||
|
||||
import { BuiltInLanguage } from ".";
|
||||
|
||||
/**
|
||||
* Determines whether we can run a Swift analysis on the current runner.
|
||||
*
|
||||
* @param action The Action state.
|
||||
* @param config The Action configuration.
|
||||
*
|
||||
* @throws {ConfigurationError} If Swift analysis is not possible on the current runner.
|
||||
* @returns True if we can run a Swift analysis.
|
||||
*/
|
||||
export function isSwiftCompatible(
|
||||
action: ActionState<["Base"]>,
|
||||
config: Config,
|
||||
) {
|
||||
if (
|
||||
config.languages.includes(BuiltInLanguage.swift) &&
|
||||
action.platform !== "darwin"
|
||||
) {
|
||||
throw new ConfigurationError(
|
||||
`Swift analysis is only supported on macOS runner images. Please migrate to a macOS runner.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user