Skip to content

Commit

Permalink
🚸 Handle the deprecated parameters in the action
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Feb 15, 2022
1 parent 57c773d commit 2cc5f0d
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 72 deletions.
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -172,17 +172,17 @@ To do it, follow these steps:

Most likely you won't need other options than `args`: all other options can be useful if you are configuring multiple Qodana Scan jobs in one workflow.

| Name | Description | Default Value |
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------|
| `args` | Additional [Qodana CLI `scan` command](https://github.com/jetbrains/qodana-cli#scan) arguments, split the arguments with commas (`,`), e.g. `-i,frontend,--print-problems`. Optional. | - |
| `resultsDir` | Directory to store the analysis results. Optional. | `${{ runner.temp }}/qodana/results` |
| `uploadResults` | Upload Qodana results as an artifact to the job. Optional. | `true` |
| `artifactName` | Specify Qodana results artifact name, used for results uploading. Optional. | `qodana-report` |
| `cacheDir` | Directory to store Qodana cache. Optional. | `${{ runner.temp }}/qodana/caches` |
| `syncCache` | Utilize GitHub caches for Qodana runs. Optional. | `true` |
| `additionalCacheHash` | Allows customizing the generated cache hash. Optional. | `${{ github.sha }}` |
| `useAnnotations` | Use annotation to mark the results in the GitHub user interface. Optional. | `true` |
| `githubToken` | GitHub token to be used for uploading results. Optional. | `${{ github.token }}` |
| Name | Description | Default Value |
|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------|
| `args` | Additional [Qodana CLI `scan` command](https://github.com/jetbrains/qodana-cli#scan) arguments, split the arguments with commas (`,`), e.g. `-i,frontend,--print-problems`. Optional. | - |
| `results-dir` | Directory to store the analysis results. Optional. | `${{ runner.temp }}/qodana/results` |
| `upload-result` | Upload Qodana results as an artifact to the job. Optional. | `true` |
| `artifact-name` | Specify Qodana results artifact name, used for results uploading. Optional. | `qodana-report` |
| `cache-dir` | Directory to store Qodana cache. Optional. | `${{ runner.temp }}/qodana/caches` |
| `use-caches` | Utilize GitHub caches for Qodana runs. Optional. | `true` |
| `additional-cache-hash` | Allows customizing the generated cache hash. Optional. | `${{ github.sha }}` |
| `use-annotations` | Use annotation to mark the results in the GitHub user interface. Optional. | `true` |
| `github-token` | GitHub token to be used for uploading results. Optional. | `${{ github.token }}` |

## Issue Tracker

Expand Down
76 changes: 67 additions & 9 deletions action.yaml
Expand Up @@ -9,38 +9,96 @@ inputs:
description: 'Additional Qodana CLI arguments. Separate multiple arguments with commas (`,`).'
required: false
default: ""
resultsDir:
results-dir:
description: 'Directory to store the analysis results'
required: false
default: "${{ runner.temp }}/qodana/results"
cacheDir:
cache-dir:
description: 'Directory to store Qodana caches'
required: false
default: "${{ runner.temp }}/qodana/caches"
syncCache:
use-caches:
description: 'Automatically restore and save Qodana caches using GitHub caches'
required: false
default: "true"
additionalCacheHash:
additional-cache-hash:
description: 'Pass additional cache hash extension'
required: false
default: "${{ github.sha }}"
uploadResults:
upload-result:
description: 'Upload Qodana results as an artifact to the job'
required: false
default: "true"
artifactName:
artifact-name:
description: 'Specify Qodana results artifact name, used for results uploading'
required: false
default: "qodana-report"
useAnnotations:
description: 'Use annotation to mark the results in the GitHub user interface'
use-annotations:
description: 'Use annotations to mark the results in the GitHub user interface'
required: false
default: "true"
githubToken:
github-token:
description: 'GitHub token to be used for uploading annotations'
required: false
default: ${{ github.token }}
# deprecated options
linter:
description: '[DEPRECATED] Qodana linter – [official Qodana Docker image](#supported-qodana-docker-images).'
required: false
deprecationMessage: 'Use `args` (e.g. `args: -linter,<linter>`) instead'
project-dir:
description: '[DEPRECATED] Root directory of the project to be analyzed'
required: false
deprecationMessage: 'Use `args` (e.g. `args: --project-dir,<path>`) instead'
idea-config-dir:
description: '[DEPRECATED] IntelliJ IDEA configuration directory'
required: false
deprecationMessage: 'Use `args` to mount the directory (e.g. `args: -v,<path>:/root/.config/idea`) instead'
gradle-settings-path:
description: '[DEPRECATED] Provide path to gradle.properties file. An example: "/your/custom/path/gradle.properties"'
required: false
deprecationMessage: 'Use `args` to mount the file (e.g. `args: -v,<path>:/root/.gradle/gradle.properties`) instead'
additional-volumes:
description: '[DEPRECATED] Mount additional volumes to Docker container'
required: false
deprecationMessage: 'Use `args` to mount any directory (e.g. `args: -v,<path1>:<path2>,-v,<path3>:<path4>`) instead'
additional-env-variables:
description: '[DEPRECATED] Pass additional environment variables to docker container'
required: false
deprecationMessage: 'Use `args` to pass any environment variable (e.g. `args: -e,<key1>=<value1>,-e,<key2>=<value2>`) instead'
fail-threshold:
description: '[DEPRECATED] Set the number of problems that will serve as a quality gate. If this number is reached, the pipeline run is terminated'
required: false
deprecationMessage: 'Use `args` to pass the threshold (e.g. `args: --fail-threshold,<number>`) instead'
inspected-dir:
description: '[DEPRECATED] Directory to be inspected. If not specified, the whole project is inspected by default'
required: false
deprecationMessage: 'Use `args` to pass the directory (e.g. `args: -d,<path>`) instead'
baseline-path:
description: '[DEPRECATED] Run in baseline mode. Provide the path to an existing SARIF report to be used in the baseline state calculation'
required: false
deprecationMessage: 'Use `args` to pass the baseline path (e.g. `args: -b,<path>`) instead'
baseline-include-absent:
description: '[DEPRECATED] Include the results from the baseline absent in the current Qodana run in the output report'
required: false
deprecationMessage: 'Use `args` to pass the baseline include absent flag (e.g. `args: --baseline-include-absent`) instead'
changes:
description: '[DEPRECATED] Inspect uncommitted changes and report new problems'
required: false
deprecationMessage: 'Use `args` to pass the changes flag (e.g. `args: --changes`) instead'
script:
description: '[DEPRECATED] Override the default docker scenario'
required: false
deprecationMessage: 'Use `args` to pass the script (e.g. `args: --script,<name>`) instead'
profile-name:
description: '[DEPRECATED] Name of a profile defined in the project'
required: false
deprecationMessage: 'Use `args` to pass the profile name (e.g. `args: --profile-name,<name>`) instead'
profile-path:
description: '[DEPRECATED] Absolute path to the profile file'
required: false
deprecationMessage: 'Use `args` to pass the profile path (e.g. `args: --profile-path,<path>`) instead'

runs:
using: 'node12'
main: 'scan/dist/index.js'
8 changes: 4 additions & 4 deletions common/qodana.ts
@@ -1,6 +1,6 @@
// noinspection JSUnusedGlobalSymbols

export const VERSION = '0.7.4'
export const VERSION = '0.7.5'
export const EXECUTABLE = 'qodana'
export const FAIL_THRESHOLD_OUTPUT =
'The number of problems exceeds the failThreshold'
Expand Down Expand Up @@ -29,7 +29,7 @@ export interface Inputs {
resultsDir: string
cacheDir: string
additionalCacheHash: string
uploadResults: boolean
uploadResult: boolean
artifactName: string
useCaches: boolean
githubToken: string
Expand Down Expand Up @@ -107,13 +107,13 @@ export function getQodanaScanArgs(
args: string[],
resultsDir: string,
cacheDir: string,
env = 'cli'
env = `cli`
): string[] {
const cliArgs: string[] = [
'scan',
'--skip-pull',
'-e',
`QODANA_ENV=${env}`,
`QODANA_ENV=${env}:${VERSION}`,
'--cache-dir',
cacheDir,
'--results-dir',
Expand Down
13 changes: 9 additions & 4 deletions scan/__tests__/main.test.ts
Expand Up @@ -5,7 +5,7 @@ import {
QODANA_HELP_STRING,
QODANA_CHECK_NAME
} from '../src/annotations'
import {getQodanaScanArgs, Inputs} from '../../common/qodana'
import {getQodanaScanArgs, Inputs, VERSION} from '../../common/qodana'

function outputEmptyFixture(): Output {
return {
Expand Down Expand Up @@ -62,7 +62,7 @@ function inputsDefaultFixture(): Inputs {
resultsDir: '${{ runner.temp }}/qodana-results',
cacheDir: '${{ runner.temp }}/qodana-caches',
additionalCacheHash: '',
uploadResults: true,
uploadResult: true,
artifactName: 'Qodana report',
useCaches: true,
useAnnotations: true,
Expand All @@ -75,7 +75,7 @@ function defaultDockerRunCommandFixture(): string[] {
'scan',
'--skip-pull',
'-e',
'QODANA_ENV=github',
`QODANA_ENV=github:${VERSION}`,
'--cache-dir',
'${{ runner.temp }}/qodana-caches',
'--results-dir',
Expand All @@ -87,7 +87,12 @@ function defaultDockerRunCommandFixture(): string[] {

test('qodana scan command args', () => {
const inputs = inputsDefaultFixture()
const result = getQodanaScanArgs(inputs.args, inputs.resultsDir, inputs.cacheDir, 'github')
const result = getQodanaScanArgs(
inputs.args,
inputs.resultsDir,
inputs.cacheDir,
'github'
)
expect(result).toEqual(defaultDockerRunCommandFixture())
})

Expand Down
91 changes: 78 additions & 13 deletions scan/dist/index.js
Expand Up @@ -1815,12 +1815,12 @@ function getQodanaPullArgs(args) {
}
return pullArgs;
}
function getQodanaScanArgs(args, resultsDir, cacheDir, env = "cli") {
function getQodanaScanArgs(args, resultsDir, cacheDir, env = `cli`) {
const cliArgs = [
"scan",
"--skip-pull",
"-e",
`QODANA_ENV=${env}`,
`QODANA_ENV=${env}:${VERSION}`,
"--cache-dir",
cacheDir,
"--results-dir",
Expand All @@ -1834,7 +1834,7 @@ function getQodanaScanArgs(args, resultsDir, cacheDir, env = "cli") {
var VERSION, EXECUTABLE, FAIL_THRESHOLD_OUTPUT, QODANA_SARIF_NAME, QodanaExitCode;
var init_qodana = __esm({
"../common/qodana.ts"() {
VERSION = "0.7.4";
VERSION = "0.7.5";
EXECUTABLE = "qodana";
FAIL_THRESHOLD_OUTPUT = "The number of problems exceeds the failThreshold";
QODANA_SARIF_NAME = "qodana.sarif.json";
Expand Down Expand Up @@ -66902,17 +66902,82 @@ var require_utils5 = __commonJS({
var tc = __importStar2(require_tool_cache());
var qodana_12 = (init_qodana(), __toCommonJS(qodana_exports));
var path_1 = __importDefault(require("path"));
function getDeprecatedInputs(args) {
const deprecatedInputs = {
linter: core2.getInput("linter"),
projectDir: core2.getInput("project-dir"),
additionalVolumes: core2.getMultilineInput("additional-volumes"),
additionalEnvVars: core2.getMultilineInput("additional-env-variables"),
inspectedDir: core2.getInput("inspected-dir"),
ideaConfigDir: core2.getInput("idea-config-dir"),
baselinePath: core2.getInput("baseline-path"),
baselineIncludeAbsent: core2.getBooleanInput("baseline-include-absent"),
failThreshold: core2.getInput("fail-threshold"),
profileName: core2.getInput("profile-name"),
profilePath: core2.getInput("profile-path"),
gradleSettingsPath: core2.getInput("gradle-settings-path"),
changes: core2.getBooleanInput("changes"),
script: core2.getInput("script")
};
if (deprecatedInputs.linter) {
args.push("-l", deprecatedInputs.linter);
}
if (deprecatedInputs.projectDir) {
args.push("-i", deprecatedInputs.projectDir);
}
if (deprecatedInputs.additionalVolumes) {
for (const volume of deprecatedInputs.additionalVolumes) {
args.push("-v", volume);
}
}
if (deprecatedInputs.additionalEnvVars) {
for (const envVar of deprecatedInputs.additionalEnvVars) {
args.push("-e", envVar);
}
}
if (deprecatedInputs.inspectedDir) {
args.push("-d", deprecatedInputs.inspectedDir);
}
if (deprecatedInputs.ideaConfigDir) {
args.push("-v", `${deprecatedInputs.ideaConfigDir}:/root/.config/idea`);
}
if (deprecatedInputs.baselinePath) {
args.push("-b", deprecatedInputs.baselinePath);
}
if (deprecatedInputs.baselineIncludeAbsent) {
args.push("--baseline-include-absent");
}
if (deprecatedInputs.failThreshold) {
args.push("--fail-threshold", deprecatedInputs.failThreshold);
}
if (deprecatedInputs.profileName) {
args.push("--profile-name", deprecatedInputs.profileName);
}
if (deprecatedInputs.profilePath) {
args.push("--profile-path", deprecatedInputs.profilePath);
}
if (deprecatedInputs.gradleSettingsPath) {
args.push("-v", `${deprecatedInputs.gradleSettingsPath}:/root/.gradle/gradle.properties`);
}
if (deprecatedInputs.changes) {
args.push("--changes");
}
if (deprecatedInputs.script) {
args.push("--script", deprecatedInputs.script);
}
return args;
}
function getInputs() {
return {
args: core2.getInput("args").split(","),
resultsDir: core2.getInput("resultsDir"),
cacheDir: core2.getInput("cacheDir"),
additionalCacheHash: core2.getInput("additionalCacheHash"),
uploadResults: core2.getBooleanInput("uploadResults"),
artifactName: core2.getInput("artifactName"),
useCaches: core2.getBooleanInput("useCaches"),
githubToken: core2.getInput("githubToken"),
useAnnotations: core2.getBooleanInput("useAnnotations")
args: getDeprecatedInputs(core2.getInput("args").split(",")),
resultsDir: core2.getInput("results-dir"),
cacheDir: core2.getInput("cache-dir"),
additionalCacheHash: core2.getInput("additional-cache-hash"),
uploadResult: core2.getBooleanInput("upload-result"),
artifactName: core2.getInput("artifact-name"),
useCaches: core2.getBooleanInput("use-caches"),
githubToken: core2.getInput("github-token"),
useAnnotations: core2.getBooleanInput("use-annotations")
};
}
exports2.getInputs = getInputs;
Expand Down Expand Up @@ -69671,7 +69736,7 @@ function main() {
]);
const exitCode = yield (0, utils_1.qodana)();
yield Promise.all([
(0, utils_1.uploadReport)(inputs.resultsDir, inputs.artifactName, inputs.uploadResults),
(0, utils_1.uploadReport)(inputs.resultsDir, inputs.artifactName, inputs.uploadResult),
(0, utils_1.uploadCaches)(inputs.cacheDir, inputs.additionalCacheHash, inputs.useCaches && (0, qodana_1.isExecutionSuccessful)(exitCode)),
(0, annotations_1.publishAnnotations)(exitCode === qodana_1.QodanaExitCode.FailThreshold, inputs.githubToken, `${inputs.resultsDir}/${qodana_1.QODANA_SARIF_NAME}`, inputs.useAnnotations && (0, qodana_1.isExecutionSuccessful)(exitCode))
]);
Expand Down
2 changes: 1 addition & 1 deletion scan/package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Qodana is a code quality monitoring tool that identifies bugs, duplications, and imperfections.",
"main": "lib/main.js",
"scripts": {
"build": "rm -rf lib && tsc --build .",
"build": "rm -rf lib && rm -rf ../common/lib && tsc --build .",
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
Expand Down
6 changes: 1 addition & 5 deletions scan/src/main.ts
Expand Up @@ -51,11 +51,7 @@ async function main(): Promise<void> {
])
const exitCode = await qodana()
await Promise.all([
uploadReport(
inputs.resultsDir,
inputs.artifactName,
inputs.uploadResults
),
uploadReport(inputs.resultsDir, inputs.artifactName, inputs.uploadResult),
uploadCaches(
inputs.cacheDir,
inputs.additionalCacheHash,
Expand Down

0 comments on commit 2cc5f0d

Please sign in to comment.