Skip to content

Commit

Permalink
🚸 Do not enable push-fixes in pr-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 18, 2023
1 parent ef55588 commit 8954cfd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ to
- Or set the action `args` property with the quick-fix strategy to use: `--apply-fixes` or `--cleanup`
2. Set `push-fixes` property to
- `pull-request`: create a new branch with fixes and create a pull request to the original branch
- or `branch`: push fixes to the original branch
- or `branch`: push fixes to the original branch. Also, set `pr-mode` to `false`: currently, this mode is not supported for applying fixes.
3. Set the correct permissions for the job (`contents: write`, `pull-requests: write`, `checks: write`)
- If you use `pull-request` value for `push-fixes` property: [**allow GitHub Actions to create and approve pull requests**](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests)

Expand All @@ -98,13 +98,14 @@ Example configuration:
- name: Qodana Scan
uses: JetBrains/qodana-action@v2023.2
with:
pr-mode: false
args: --apply-fixes
push-fixes: pull-request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

> **Note:**
> **Note**
> Qodana could automatically modify not only the code, but also the configuration in `.idea`: if you do not wish to push these changes, add `.idea` to your `.gitignore` file.
If you want to do different `git` operations in the same job, you can disable `push-fixes` and do the wanted operations manually
Expand Down
9 changes: 2 additions & 7 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,11 @@ inputs:
primary-cache-key:
description: 'Set the primary cache key'
required: false
default: ""
default: "qodana-2023.2-${{ github.ref }}-${{ github.sha }}"
additional-cache-key:
description: 'Set the additional cache key'
required: false
default: ""
additional-cache-hash:
description: 'Pass additional cache hash extension'
required: false
default: "${{ github.sha }}"
deprecationMessage: 'Use `primary-cache-key` and `additional-cache-key` to configure cache keys'
default: "qodana-2023.2-${{ github.ref }}"
cache-default-branch-only:
description: 'Upload cache for the default branch only'
required: false
Expand Down
29 changes: 11 additions & 18 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68725,7 +68725,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
}
__name(getCoverageStats, "getCoverageStats");
exports2.getCoverageStats = getCoverageStats;
function publishOutput(failedByThreshold, resultsDir, useAnnotations, postComment, execute) {
function publishOutput(failedByThreshold, resultsDir, useAnnotations, postComment, isPrMode, execute) {
var _a, _b;
return __awaiter3(this, void 0, void 0, function* () {
if (!execute) {
Expand All @@ -68751,7 +68751,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
}
const annotations = (_a = problems.annotations) !== null && _a !== void 0 ? _a : [];
const toolName = (_b = problems.title.split("found by ")[1]) !== null && _b !== void 0 ? _b : QODANA_CHECK_NAME;
problems.summary = getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, (0, utils_12.isPRMode)());
problems.summary = getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, isPrMode);
yield Promise.all([
(0, utils_12.putReaction)(utils_12.ANALYSIS_FINISHED_REACTION, utils_12.ANALYSIS_STARTED_REACTION),
(0, utils_12.postResultsToPRComments)(toolName, problems.summary, postComment),
Expand Down Expand Up @@ -69145,7 +69145,7 @@ var require_utils8 = __commonJS({
return mod && mod.__esModule ? mod : { "default": mod };
};
Object.defineProperty(exports2, "__esModule", { value: true });
exports2.publishGitHubCheck = exports2.putReaction = exports2.updateComment = exports2.createComment = exports2.findCommentByTag = exports2.postResultsToPRComments = exports2.getWorkflowRunUrl = exports2.isNeedToUploadCache = exports2.isPRMode = exports2.restoreCaches = exports2.uploadCaches = exports2.uploadArtifacts = exports2.prepareAgent = exports2.pushQuickFixes = exports2.qodana = exports2.getInputs = exports2.ANALYSIS_STARTED_REACTION = exports2.ANALYSIS_FINISHED_REACTION = void 0;
exports2.publishGitHubCheck = exports2.putReaction = exports2.updateComment = exports2.createComment = exports2.findCommentByTag = exports2.postResultsToPRComments = exports2.getWorkflowRunUrl = exports2.isNeedToUploadCache = exports2.restoreCaches = exports2.uploadCaches = exports2.uploadArtifacts = exports2.prepareAgent = exports2.pushQuickFixes = exports2.qodana = exports2.getInputs = exports2.ANALYSIS_STARTED_REACTION = exports2.ANALYSIS_FINISHED_REACTION = void 0;
var artifact = __importStar3(require_artifact_client2());
var cache = __importStar3(require_cache());
var core2 = __importStar3(require_core());
Expand All @@ -69166,8 +69166,8 @@ var require_utils8 = __commonJS({
args: core2.getInput("args").split(",").map((arg) => arg.trim()),
resultsDir: core2.getInput("results-dir"),
cacheDir: core2.getInput("cache-dir"),
primaryCacheKey: core2.getInput("primary-cache-key") || `qodana-${qodana_12.VERSION}-${process.env.GITHUB_REF}-${process.env.GITHUB_SHA}`,
additionalCacheKey: core2.getInput("additional-cache-key") || core2.getInput("additional-cache-hash") || `qodana-${qodana_12.VERSION}-${process.env.GITHUB_REF}}-`,
primaryCacheKey: core2.getInput("primary-cache-key"),
additionalCacheKey: core2.getInput("additional-cache-key"),
cacheDefaultBranchOnly: core2.getBooleanInput("cache-default-branch-only"),
uploadResult: core2.getBooleanInput("upload-result"),
uploadSarif: false,
Expand All @@ -69187,7 +69187,7 @@ var require_utils8 = __commonJS({
return __awaiter3(this, void 0, void 0, function* () {
if (args.length === 0) {
args = (0, qodana_12.getQodanaScanArgs)(inputs.args, inputs.resultsDir, inputs.cacheDir);
if (isPRMode() && github.context.payload.pull_request !== void 0) {
if (inputs.prMode && github.context.payload.pull_request !== void 0) {
const pr = github.context.payload.pull_request;
args.push("--commit", `CI${pr.base.sha}`);
}
Expand All @@ -69214,12 +69214,6 @@ var require_utils8 = __commonJS({
yield git(["config", "user.name", output_12.COMMIT_USER]);
yield git(["config", "user.email", output_12.COMMIT_EMAIL]);
yield git(["add", "."]);
if (isPRMode()) {
yield git(["stash"]);
yield git(["fetch", "origin", currentBranch]);
yield git(["reset", "--hard", `origin/${currentBranch}`]);
yield git(["stash", "apply", "stash@{0}"]);
}
const exitCode = yield git(["commit", "-m", commitMessage], {
ignoreReturnCode: true
});
Expand Down Expand Up @@ -69329,11 +69323,6 @@ var require_utils8 = __commonJS({
}
__name(restoreCaches, "restoreCaches");
exports2.restoreCaches = restoreCaches;
function isPRMode() {
return github.context.payload.pull_request !== void 0 && getInputs().prMode;
}
__name(isPRMode, "isPRMode");
exports2.isPRMode = isPRMode;
function isNeedToUploadCache(useCaches, cacheDefaultBranchOnly) {
var _a;
if (!useCaches && cacheDefaultBranchOnly) {
Expand Down Expand Up @@ -69610,6 +69599,10 @@ function main() {
return __awaiter2(this, void 0, void 0, function* () {
try {
const inputs = (0, utils_1.getInputs)();
if (inputs.pushFixes && inputs.prMode) {
inputs.pushFixes = qodana_1.NONE;
core.warning("push-fixes is currently not supported with pr-mode: true. Running Qodana with push-fixes: false.");
}
yield io.mkdirP(inputs.resultsDir);
yield io.mkdirP(inputs.cacheDir);
const restoreCachesPromise = (0, utils_1.restoreCaches)(inputs.cacheDir, inputs.primaryCacheKey, inputs.additionalCacheKey, inputs.useCaches);
Expand All @@ -69625,7 +69618,7 @@ function main() {
(0, utils_1.pushQuickFixes)(inputs.pushFixes, inputs.commitMessage),
(0, utils_1.uploadArtifacts)(inputs.resultsDir, inputs.artifactName, inputs.uploadResult),
(0, utils_1.uploadCaches)(inputs.cacheDir, inputs.primaryCacheKey, reservedCacheKey, canUploadCache),
(0, output_1.publishOutput)(exitCode === qodana_1.QodanaExitCode.FailThreshold, inputs.resultsDir, inputs.useAnnotations, inputs.postComment, (0, qodana_1.isExecutionSuccessful)(exitCode))
(0, output_1.publishOutput)(exitCode === qodana_1.QodanaExitCode.FailThreshold, inputs.resultsDir, inputs.useAnnotations, inputs.postComment, inputs.prMode, (0, qodana_1.isExecutionSuccessful)(exitCode))
]);
if (!(0, qodana_1.isExecutionSuccessful)(exitCode)) {
setFailed(`qodana scan failed with exit code ${exitCode}`);
Expand Down
10 changes: 9 additions & 1 deletion scan/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as io from '@actions/io'
import {
FAIL_THRESHOLD_OUTPUT,
QodanaExitCode,
isExecutionSuccessful
isExecutionSuccessful,
NONE
} from '../../common/qodana'
import {
ANALYSIS_FINISHED_REACTION,
Expand Down Expand Up @@ -43,6 +44,12 @@ function setFailed(message: string): void {
async function main(): Promise<void> {
try {
const inputs = getInputs()
if (inputs.pushFixes && inputs.prMode) {
inputs.pushFixes = NONE
core.warning(
'push-fixes is currently not supported with pr-mode: true. Running Qodana with push-fixes: false.'
)
}
await io.mkdirP(inputs.resultsDir)
await io.mkdirP(inputs.cacheDir)

Expand Down Expand Up @@ -81,6 +88,7 @@ async function main(): Promise<void> {
inputs.resultsDir,
inputs.useAnnotations,
inputs.postComment,
inputs.prMode,
isExecutionSuccessful(exitCode)
)
])
Expand Down
5 changes: 3 additions & 2 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import {
ANALYSIS_FINISHED_REACTION,
ANALYSIS_STARTED_REACTION,
isPRMode,
postResultsToPRComments,
putReaction
} from './utils'
Expand Down Expand Up @@ -97,6 +96,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`
* @param failedByThreshold flag if the Qodana failThreshold was reached.
* @param resultsDir The path to the results.
* @param postComment whether to post a PR comment or not.
* @param isPrMode
* @param execute whether to execute the promise or not.
* @param useAnnotations whether to publish annotations or not.
*/
Expand All @@ -105,6 +105,7 @@ export async function publishOutput(
resultsDir: string,
useAnnotations: boolean,
postComment: boolean,
isPrMode: boolean,
execute: boolean
): Promise<void> {
if (!execute) {
Expand Down Expand Up @@ -145,7 +146,7 @@ export async function publishOutput(
coverageInfo,
licensesInfo,
reportUrl,
isPRMode()
isPrMode
)

await Promise.all([
Expand Down
26 changes: 3 additions & 23 deletions scan/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ export function getInputs(): Inputs {
.map(arg => arg.trim()),
resultsDir: core.getInput('results-dir'),
cacheDir: core.getInput('cache-dir'),
primaryCacheKey:
core.getInput('primary-cache-key') ||
`qodana-${VERSION}-${process.env.GITHUB_REF}-${process.env.GITHUB_SHA}`,
additionalCacheKey:
core.getInput('additional-cache-key') ||
core.getInput('additional-cache-hash') ||
`qodana-${VERSION}-${process.env.GITHUB_REF}}-`,
primaryCacheKey: core.getInput('primary-cache-key'),
additionalCacheKey: core.getInput('additional-cache-key'),
cacheDefaultBranchOnly: core.getBooleanInput('cache-default-branch-only'),
uploadResult: core.getBooleanInput('upload-result'),
uploadSarif: false, // not used by the action
Expand All @@ -86,7 +81,7 @@ export async function qodana(
): Promise<number> {
if (args.length === 0) {
args = getQodanaScanArgs(inputs.args, inputs.resultsDir, inputs.cacheDir)
if (isPRMode() && github.context.payload.pull_request !== undefined) {
if (inputs.prMode && github.context.payload.pull_request !== undefined) {
const pr = github.context.payload.pull_request
args.push('--commit', `CI${pr.base.sha}`)
}
Expand Down Expand Up @@ -117,13 +112,6 @@ export async function pushQuickFixes(
await git(['config', 'user.name', COMMIT_USER])
await git(['config', 'user.email', COMMIT_EMAIL])
await git(['add', '.'])
if (isPRMode()) {
// temporary magic, to be fixed with local-changes
await git(['stash'])
await git(['fetch', 'origin', currentBranch])
await git(['reset', '--hard', `origin/${currentBranch}`])
await git(['stash', 'apply', 'stash@{0}'])
}
const exitCode = await git(['commit', '-m', commitMessage], {
ignoreReturnCode: true
})
Expand Down Expand Up @@ -283,14 +271,6 @@ export async function restoreCaches(
return ''
}

/**
* Determines if the action is running in PR mode.
* @returns {boolean} true if the action is running in PR mode, false otherwise.
*/
export function isPRMode(): boolean {
return github.context.payload.pull_request !== undefined && getInputs().prMode
}

/**
* Check if need to upload the cache.
*/
Expand Down

0 comments on commit 8954cfd

Please sign in to comment.