-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (81 loc) · 3.94 KB
/
Copy pathcodacy.yml
File metadata and controls
92 lines (81 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow checks out code, performs a Codacy security scan
# and integrates the results with the
# GitHub Advanced Security code scanning feature. For more information on
# the Codacy security scan action usage and parameters, see
# https://github.com/codacy/codacy-analysis-cli-action.
# For more information on Codacy Analysis CLI in general, see
# https://github.com/codacy/codacy-analysis-cli.
name: Codacy Security Scan
on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '41 3 * * 0'
permissions:
contents: read
jobs:
codacy-security-scan:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v7.0.1
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@562ee3e92b8e92df8b67e0a5ff8aa8e261919c08
with:
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
# You can also omit the token and run the tools that support default configurations
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
# GitHub Code Scanning limits SARIF uploads to at most 20 runs per file and rejects
# multiple runs sharing the same category (see https://docs.github.com/en/code-security/reference/code-scanning/sarif-files/troubleshoot-sarif-uploads/results-exceed-limit).
# Codacy CLI emits up to 30 runs (many for inactive tools with 0 results).
# Filter to retain runs with findings first, cap to <= 20 runs, and assign distinct category IDs.
- name: Uniquify SARIF run categories for code scanning
run: |
python3 <<'PY'
import json
# Read Codacy output (may be root-owned / non-writable from Docker); write a new file.
with open("results.sarif", encoding="utf-8") as f:
data = json.load(f)
runs = data.get("runs") or []
# Prioritize runs that have findings. Drop empty runs to stay under GitHub's 20-run limit.
non_empty_runs = [r for r in runs if r.get("results")]
empty_runs = [r for r in runs if not r.get("results")]
if non_empty_runs:
selected_runs = (non_empty_runs + empty_runs)[:20]
else:
selected_runs = runs[:20]
for i, run in enumerate(selected_runs):
ad = dict(run.get("automationDetails") or {})
ad["id"] = f"codacy-analysis-run-{i}"
run["automationDetails"] = ad
data["runs"] = selected_runs
with open("results-upload.sarif", "w", encoding="utf-8") as f:
json.dump(data, f)
PY
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: results-upload.sarif