Skip to content

Commit f40c93b

Browse files
authored
ci: create bypass-codacy-variation.yml
1 parent d79746d commit f40c93b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Bypass Codacy Coverage Variation
2+
3+
# This workflow injects a success check on 'Codacy Coverage Variation' when the check is not reported by Codacy,
4+
# so it can avoid bloking auto-merging on Pull Requests that has a check success requirement on it.
5+
6+
# Examples where 'Codacy Coverage Variation' is not reported by Codacy:
7+
# - Modification on just a test class, and your test classes are ignored at 'codacy.yml'.
8+
# - Modification of 'README.md', which has no coverage.
9+
# - Modification of a GitHub Action workflow, which has no coverage.
10+
11+
# In those cases, this workflow will bypass the 'Codacy Coverage Variation' check, allowing the PR to auto-merge.
12+
13+
on:
14+
pull_request:
15+
branches: [ "master", "main" ]
16+
17+
permissions:
18+
checks: write
19+
contents: read
20+
21+
jobs:
22+
bypass_check:
23+
runs-on: ubuntu-latest
24+
steps:
25+
26+
# Verifies which kind of files have changes.
27+
# 'has_code_changes' will be true if any java source file is modified.
28+
# 'has_non_coverable_changes' will be true if there is any Markdown, YAML file or any other kind of non coverable file.
29+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
30+
id: changes
31+
with:
32+
filters: |
33+
has_code_changes:
34+
- "src/main/**/*.java"
35+
has_non_coverable_changes:
36+
- "**/*.md"
37+
- "**/*.yml"
38+
- ".github/**"
39+
40+
# Bypass the 'Codacy Coverage Variation' when there are no coverable files able to trigger it.
41+
- name: Create Success Check for Variation
42+
if: steps.changes.outputs.has_code_changes == 'false' && steps.changes.outputs.has_non_coverable_changes == 'true'
43+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
44+
with:
45+
script: |
46+
const checkName = 'Codacy Coverage Variation';
47+
console.log(`Reporting manual success for: ${checkName}`);
48+
49+
await github.rest.checks.create({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
name: checkName,
53+
head_sha: context.payload.pull_request.head.sha,
54+
status: 'completed',
55+
conclusion: 'success',
56+
output: {
57+
title: 'Skipped by Dynamic Exclusion',
58+
summary: 'There are no coverable files. Bypass Codacy Coverage Variation success check.'
59+
}
60+
});

0 commit comments

Comments
 (0)