Skip to content

Commit

Permalink
⚡ Allow using nightlies for development purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Apr 25, 2024
1 parent a4f50a6 commit 528bfd7
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ jobs:
with:
args: --print-problems,--log-level,debug,--config,.github/qodana.yaml
pr-mode: true
use-nightly: true
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
5 changes: 5 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ inputs:
description: 'Commit message for the commit with quick-fixes. Not used if `push-fixes` is set to `none`'
required: false
default: "🤖 Apply quick-fixes by Qodana"
use-nightly:
description: 'Use unstable Qodana CLI nightly'
required: false
default: "false"
deprecationMessage: 'This option is for development purposes only. Do not use it in production.'
runs:
using: 'node20'
main: 'scan/dist/index.js'
13 changes: 11 additions & 2 deletions common/qodana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const EXECUTABLE = 'qodana'
export const VERSION = version

export const COVERAGE_THRESHOLD = 50

export function getQodanaSha256(arch: string, platform: string): string {
switch (`${platform}_${arch}`) {
case 'windows_x86_64':
Expand Down Expand Up @@ -54,15 +55,20 @@ export function getProcessPlatformName(): string {
/**
* Gets Qodana CLI download URL from the GitHub Releases API.
*/
export function getQodanaUrl(arch: string, platform: string): string {
export function getQodanaUrl(
arch: string,
platform: string,
nightly = false
): string {
if (!SUPPORTED_PLATFORMS.includes(platform)) {
throw new Error(`Unsupported platform: ${platform}`)
}
if (!SUPPORTED_ARCHS.includes(arch)) {
throw new Error(`Unsupported architecture: ${arch}`)
}
const archive = platform === 'windows' ? 'zip' : 'tar.gz'
return `https://github.com/JetBrains/qodana-cli/releases/download/v${version}/qodana_${platform}_${arch}.${archive}`
const cli_version = nightly ? 'nightly' : `v${version}`
return `https://github.com/JetBrains/qodana-cli/releases/download/${cli_version}/qodana_${platform}_${arch}.${archive}`
}

// eslint-disable-next-line no-shadow -- shadowing is intentional here (ESLint bug)
Expand Down Expand Up @@ -155,11 +161,13 @@ export function getQodanaScanArgs(
}
return cliArgs
}

export const NONE = 'none'
export const BRANCH = 'branch'
export const PULL_REQUEST = 'pull-request'
const PUSH_FIXES_TYPES = [NONE, BRANCH, PULL_REQUEST]
export type PushFixesType = (typeof PUSH_FIXES_TYPES)[number]

/**
* The context of the current run – described in action.yaml.
*/
Expand All @@ -180,6 +188,7 @@ export interface Inputs {
githubToken: string
pushFixes: PushFixesType
commitMessage: string
useNightly: boolean
}

/**
Expand Down
3 changes: 2 additions & 1 deletion scan/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export function inputsDefaultFixture(): Inputs {
postComment: true,
githubToken: '',
pushFixes: 'none',
commitMessage: ''
commitMessage: '',
useNightly: false
}
}

Expand Down
28 changes: 16 additions & 12 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24344,15 +24344,16 @@ function getProcessArchName() {
function getProcessPlatformName() {
return process.platform === "win32" ? "windows" : process.platform;
}
function getQodanaUrl(arch, platform) {
function getQodanaUrl(arch, platform, nightly = false) {
if (!SUPPORTED_PLATFORMS.includes(platform)) {
throw new Error(`Unsupported platform: ${platform}`);
}
if (!SUPPORTED_ARCHS.includes(arch)) {
throw new Error(`Unsupported architecture: ${arch}`);
}
const archive = platform === "windows" ? "zip" : "tar.gz";
return `https://github.com/JetBrains/qodana-cli/releases/download/v${version2}/qodana_${platform}_${arch}.${archive}`;
const cli_version = nightly ? "nightly" : `v${version2}`;
return `https://github.com/JetBrains/qodana-cli/releases/download/${cli_version}/qodana_${platform}_${arch}.${archive}`;
}
function isExecutionSuccessful(exitCode) {
return Object.values(QodanaExitCode).includes(exitCode);
Expand Down Expand Up @@ -126409,7 +126410,8 @@ var require_utils9 = __commonJS({
postComment: core2.getBooleanInput("post-pr-comment"),
githubToken: core2.getInput("github-token"),
pushFixes: core2.getInput("push-fixes"),
commitMessage: core2.getInput("commit-message")
commitMessage: core2.getInput("commit-message"),
useNightly: core2.getBooleanInput("use-nightly")
};
}
__name(getInputs, "getInputs");
Expand Down Expand Up @@ -126465,23 +126467,25 @@ var require_utils9 = __commonJS({
}
__name(pushQuickFixes, "pushQuickFixes");
exports2.pushQuickFixes = pushQuickFixes;
function prepareAgent(args) {
return __awaiter3(this, void 0, void 0, function* () {
function prepareAgent(args_1) {
return __awaiter3(this, arguments, void 0, function* (args, useNightly = false) {
const arch = (0, qodana_12.getProcessArchName)();
const platform = (0, qodana_12.getProcessPlatformName)();
const expectedChecksum = (0, qodana_12.getQodanaSha256)(arch, platform);
const temp = yield tc.downloadTool((0, qodana_12.getQodanaUrl)(arch, platform));
const actualChecksum = (0, qodana_12.sha256sum)(temp);
if (expectedChecksum !== actualChecksum) {
core2.setFailed((0, qodana_12.getQodanaSha256MismatchMessage)(expectedChecksum, actualChecksum));
const temp = yield tc.downloadTool((0, qodana_12.getQodanaUrl)(arch, platform, useNightly));
if (!useNightly) {
const expectedChecksum = (0, qodana_12.getQodanaSha256)(arch, platform);
const actualChecksum = (0, qodana_12.sha256sum)(temp);
if (expectedChecksum !== actualChecksum) {
core2.setFailed((0, qodana_12.getQodanaSha256MismatchMessage)(expectedChecksum, actualChecksum));
}
}
let extractRoot;
if (process.platform === "win32") {
extractRoot = yield tc.extractZip(temp);
} else {
extractRoot = yield tc.extractTar(temp);
}
core2.addPath(yield tc.cacheDir(extractRoot, qodana_12.EXECUTABLE, qodana_12.VERSION));
core2.addPath(yield tc.cacheDir(extractRoot, qodana_12.EXECUTABLE, useNightly ? "nightly" : qodana_12.VERSION));
if (!(0, qodana_12.isNativeMode)(args)) {
const exitCode = yield qodana(getInputs(), (0, qodana_12.getQodanaPullArgs)(args));
if (exitCode !== 0) {
Expand Down Expand Up @@ -126841,7 +126845,7 @@ function main() {
const restoreCachesPromise = (0, utils_1.restoreCaches)(inputs.cacheDir, inputs.primaryCacheKey, inputs.additionalCacheKey, inputs.useCaches);
yield Promise.all([
(0, utils_1.putReaction)(utils_1.ANALYSIS_STARTED_REACTION, utils_1.ANALYSIS_FINISHED_REACTION),
(0, utils_1.prepareAgent)(inputs.args),
(0, utils_1.prepareAgent)(inputs.args, inputs.useNightly),
restoreCachesPromise
]);
const reservedCacheKey = yield restoreCachesPromise;
Expand Down
2 changes: 1 addition & 1 deletion scan/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main(): Promise<void> {
)
await Promise.all([
putReaction(ANALYSIS_STARTED_REACTION, ANALYSIS_FINISHED_REACTION),
prepareAgent(inputs.args),
prepareAgent(inputs.args, inputs.useNightly),
restoreCachesPromise
])
const reservedCacheKey = await restoreCachesPromise
Expand Down
31 changes: 21 additions & 10 deletions scan/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import path from 'path'
import * as fs from 'fs'
import * as os from 'os'
import {COMMIT_EMAIL, COMMIT_USER, prFixesBody} from './output'

export const ANALYSIS_FINISHED_REACTION = '+1'
export const ANALYSIS_STARTED_REACTION = 'eyes'
const REACTIONS = [
Expand Down Expand Up @@ -68,9 +69,11 @@ export function getInputs(): Inputs {
postComment: core.getBooleanInput('post-pr-comment'),
githubToken: core.getInput('github-token'),
pushFixes: core.getInput('push-fixes'),
commitMessage: core.getInput('commit-message')
commitMessage: core.getInput('commit-message'),
useNightly: core.getBooleanInput('use-nightly')
}
}

/**
* Runs the qodana command with the given arguments.
* @param inputs the action inputs.
Expand Down Expand Up @@ -141,25 +144,33 @@ export async function pushQuickFixes(
/**
* Prepares the agent for qodana scan: install Qodana CLI and pull the linter.
* @param args qodana arguments
* @param useNightly whether to use a nightly version of Qodana CLI
*/
export async function prepareAgent(args: string[]): Promise<void> {
export async function prepareAgent(
args: string[],
useNightly = false
): Promise<void> {
const arch = getProcessArchName()
const platform = getProcessPlatformName()
const expectedChecksum = getQodanaSha256(arch, platform)
const temp = await tc.downloadTool(getQodanaUrl(arch, platform))
const actualChecksum = sha256sum(temp)
if (expectedChecksum !== actualChecksum) {
core.setFailed(
getQodanaSha256MismatchMessage(expectedChecksum, actualChecksum)
)
const temp = await tc.downloadTool(getQodanaUrl(arch, platform, useNightly))
if (!useNightly) {
const expectedChecksum = getQodanaSha256(arch, platform)
const actualChecksum = sha256sum(temp)
if (expectedChecksum !== actualChecksum) {
core.setFailed(
getQodanaSha256MismatchMessage(expectedChecksum, actualChecksum)
)
}
}
let extractRoot
if (process.platform === 'win32') {
extractRoot = await tc.extractZip(temp)
} else {
extractRoot = await tc.extractTar(temp)
}
core.addPath(await tc.cacheDir(extractRoot, EXECUTABLE, VERSION))
core.addPath(
await tc.cacheDir(extractRoot, EXECUTABLE, useNightly ? 'nightly' : VERSION)
)
if (!isNativeMode(args)) {
const exitCode = await qodana(getInputs(), getQodanaPullArgs(args))
if (exitCode !== 0) {
Expand Down
22 changes: 13 additions & 9 deletions vsts/QodanaScan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ function getProcessArchName() {
function getProcessPlatformName() {
return process.platform === "win32" ? "windows" : process.platform;
}
function getQodanaUrl(arch, platform) {
function getQodanaUrl(arch, platform, nightly = false) {
if (!SUPPORTED_PLATFORMS.includes(platform)) {
throw new Error(`Unsupported platform: ${platform}`);
}
if (!SUPPORTED_ARCHS.includes(arch)) {
throw new Error(`Unsupported architecture: ${arch}`);
}
const archive = platform === "windows" ? "zip" : "tar.gz";
return `https://github.com/JetBrains/qodana-cli/releases/download/v${version}/qodana_${platform}_${arch}.${archive}`;
const cli_version = nightly ? "nightly" : `v${version}`;
return `https://github.com/JetBrains/qodana-cli/releases/download/${cli_version}/qodana_${platform}_${arch}.${archive}`;
}
function isExecutionSuccessful(exitCode) {
return Object.values(QodanaExitCode).includes(exitCode);
Expand Down Expand Up @@ -5016,6 +5017,7 @@ var require_utils2 = __commonJS({
uploadResult: tl2.getBoolInput("uploadResult", false) || false,
uploadSarif: tl2.getBoolInput("uploadSarif", false) || true,
artifactName: tl2.getInput("artifactName", false) || "qodana-report",
useNightly: tl2.getBoolInput("useNightly", false) || false,
// Not used by the Azure task
postComment: false,
additionalCacheKey: "",
Expand Down Expand Up @@ -5043,23 +5045,25 @@ var require_utils2 = __commonJS({
});
}
exports2.qodana = qodana;
function prepareAgent(args) {
return __awaiter2(this, void 0, void 0, function* () {
function prepareAgent(args_1) {
return __awaiter2(this, arguments, void 0, function* (args, useNightly = false) {
const arch = (0, qodana_12.getProcessArchName)();
const platform = (0, qodana_12.getProcessPlatformName)();
const expectedChecksum = (0, qodana_12.getQodanaSha256)(arch, platform);
const temp = yield tool.downloadTool((0, qodana_12.getQodanaUrl)(arch, platform));
const actualChecksum = (0, qodana_12.sha256sum)(temp);
if (expectedChecksum !== actualChecksum) {
setFailed((0, qodana_12.getQodanaSha256MismatchMessage)(expectedChecksum, actualChecksum));
if (!useNightly) {
const expectedChecksum = (0, qodana_12.getQodanaSha256)(arch, platform);
const actualChecksum = (0, qodana_12.sha256sum)(temp);
if (expectedChecksum !== actualChecksum) {
setFailed((0, qodana_12.getQodanaSha256MismatchMessage)(expectedChecksum, actualChecksum));
}
}
let extractRoot;
if (process.platform === "win32") {
extractRoot = yield tool.extractZip(temp);
} else {
extractRoot = yield tool.extractTar(temp);
}
tool.prependPath(yield tool.cacheDir(extractRoot, qodana_12.EXECUTABLE, qodana_12.VERSION));
tool.prependPath(yield tool.cacheDir(extractRoot, qodana_12.EXECUTABLE, useNightly ? "nightly" : qodana_12.VERSION));
if (!(0, qodana_12.isNativeMode)(args)) {
const pull = yield qodana((0, qodana_12.getQodanaPullArgs)(args));
if (pull !== 0) {
Expand Down
8 changes: 8 additions & 0 deletions vsts/QodanaScan/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
"defaultValue": "$(Agent.TempDirectory)/qodana/cache",
"required": false,
"helpMarkDown": "Directory to store Qodana caches"
},
{
"name": "useNightly",
"type": "boolean",
"label": "Use unstable Qodana CLI nightly",
"defaultValue": false,
"required": false,
"helpMarkDown": "This option is for development purposes only. Do not use it in production."
}
],
"execution": {
Expand Down
27 changes: 21 additions & 6 deletions vsts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function getInputs(): Inputs {
uploadResult: tl.getBoolInput('uploadResult', false) || false,
uploadSarif: tl.getBoolInput('uploadSarif', false) || true,
artifactName: tl.getInput('artifactName', false) || 'qodana-report',
useNightly: tl.getBoolInput('useNightly', false) || false,
// Not used by the Azure task
postComment: false,
additionalCacheKey: '',
Expand Down Expand Up @@ -73,23 +74,37 @@ export async function qodana(args: string[] = []): Promise<number> {
/**
* Prepares the agent for qodana scan: install Qodana CLI and pull the linter.
* @param args qodana arguments
* @param useNightly whether to use a nightly version of Qodana CLI
*/
export async function prepareAgent(args: string[]): Promise<void> {
export async function prepareAgent(
args: string[],
useNightly = false
): Promise<void> {
const arch = getProcessArchName()
const platform = getProcessPlatformName()
const expectedChecksum = getQodanaSha256(arch, platform)
const temp = await tool.downloadTool(getQodanaUrl(arch, platform))
const actualChecksum = sha256sum(temp)
if (expectedChecksum !== actualChecksum) {
setFailed(getQodanaSha256MismatchMessage(expectedChecksum, actualChecksum))
if (!useNightly) {
const expectedChecksum = getQodanaSha256(arch, platform)
const actualChecksum = sha256sum(temp)
if (expectedChecksum !== actualChecksum) {
setFailed(
getQodanaSha256MismatchMessage(expectedChecksum, actualChecksum)
)
}
}
let extractRoot
if (process.platform === 'win32') {
extractRoot = await tool.extractZip(temp)
} else {
extractRoot = await tool.extractTar(temp)
}
tool.prependPath(await tool.cacheDir(extractRoot, EXECUTABLE, VERSION))
tool.prependPath(
await tool.cacheDir(
extractRoot,
EXECUTABLE,
useNightly ? 'nightly' : VERSION
)
)
if (!isNativeMode(args)) {
const pull = await qodana(getQodanaPullArgs(args))
if (pull !== 0) {
Expand Down

0 comments on commit 528bfd7

Please sign in to comment.