|
1 | | -import { fixCodeQualityCategory } from "./actions-util"; |
| 1 | +import { |
| 2 | + fixCodeQualityCategory, |
| 3 | + getOptionalInput, |
| 4 | + getRequiredInput, |
| 5 | +} from "./actions-util"; |
2 | 6 | import { Logger } from "./logging"; |
3 | 7 | import { ConfigurationError } from "./util"; |
4 | 8 |
|
@@ -41,6 +45,55 @@ export async function parseAnalysisKinds( |
41 | 45 | ); |
42 | 46 | } |
43 | 47 |
|
| 48 | +// Used to avoid re-parsing the input after we have done it once. |
| 49 | +let cachedAnalysisKinds: AnalysisKind[] | undefined; |
| 50 | + |
| 51 | +/** |
| 52 | + * Initialises the analysis kinds for the analysis based on the `analysis-kinds` input. |
| 53 | + * This function will also use the deprecated `quality-queries` input as an indicator to enable `code-quality`. |
| 54 | + * If the `analysis-kinds` input cannot be parsed, a `ConfigurationError` is thrown. |
| 55 | + * |
| 56 | + * @param logger The logger to use. |
| 57 | + * @param skipCache For testing, whether to ignore the cached values (default: false). |
| 58 | + * |
| 59 | + * @returns The array of enabled analysis kinds. |
| 60 | + * @throws A `ConfigurationError` if the `analysis-kinds` input cannot be parsed. |
| 61 | + */ |
| 62 | +export async function getAnalysisKinds( |
| 63 | + logger: Logger, |
| 64 | + skipCache: boolean = false, |
| 65 | +): Promise<AnalysisKind[]> { |
| 66 | + if (!skipCache && cachedAnalysisKinds !== undefined) { |
| 67 | + return cachedAnalysisKinds; |
| 68 | + } |
| 69 | + |
| 70 | + cachedAnalysisKinds = await parseAnalysisKinds( |
| 71 | + getRequiredInput("analysis-kinds"), |
| 72 | + ); |
| 73 | + |
| 74 | + // Warn that `quality-queries` is deprecated if there is an argument for it. |
| 75 | + const qualityQueriesInput = getOptionalInput("quality-queries"); |
| 76 | + |
| 77 | + if (qualityQueriesInput !== undefined) { |
| 78 | + logger.warning( |
| 79 | + "The `quality-queries` input is deprecated and will be removed in a future version of the CodeQL Action. " + |
| 80 | + "Use the `analysis-kinds` input to configure different analysis kinds instead.", |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + // For backwards compatibility, add Code Quality to the enabled analysis kinds |
| 85 | + // if an input to `quality-queries` was specified. We should remove this once |
| 86 | + // `quality-queries` is no longer used. |
| 87 | + if ( |
| 88 | + !cachedAnalysisKinds.includes(AnalysisKind.CodeQuality) && |
| 89 | + qualityQueriesInput !== undefined |
| 90 | + ) { |
| 91 | + cachedAnalysisKinds.push(AnalysisKind.CodeQuality); |
| 92 | + } |
| 93 | + |
| 94 | + return cachedAnalysisKinds; |
| 95 | +} |
| 96 | + |
44 | 97 | /** The queries to use for Code Quality analyses. */ |
45 | 98 | export const codeQualityQueries: string[] = ["code-quality"]; |
46 | 99 |
|
|
0 commit comments