1- # This workflow uses actions that are not certified by GitHub.
2- # They are provided by a third-party and are governed by
3- # separate terms of service, privacy policy, and support
4- # documentation.
5-
6- # This workflow performs a static analysis of your Kotlin source code using
7- # Detekt.
8- #
9- # Scans are triggered:
10- # 1. On every push to default and protected branches
11- # 2. On every Pull Request targeting the default branch
12- # 3. On a weekly schedule
13- # 4. Manually, on demand, via the "workflow_dispatch" event
14- #
15- # The workflow should work with no modifications, but you might like to use a
16- # later version of the Detekt CLI by modifying the $DETEKT_RELEASE_TAG
17- # environment variable.
181name : Scan with Detekt
192
203on :
21- # Triggers the workflow on push or pull request events but only for default and protected branches
224 push :
235 branches : [ "beta" ]
246 pull_request :
257 branches : [ "beta" ]
268 schedule :
279 - cron : ' 0 0 * * *'
28-
29- # Allows you to run this workflow manually from the Actions tab
3010 workflow_dispatch :
3111
12+ permissions :
13+ security-events : write
14+ contents : read
15+
16+ concurrency :
17+ group : ${{ github.workflow }}
18+ cancel-in-progress : true
19+
20+ env :
21+ GITHUB_TOKEN : ${{ secrets.GH_PAT != '' && secrets.GH_PAT || secrets.GITHUB_TOKEN }}
22+
3223jobs :
3324 scan :
3425 name : Scan
3526 runs-on : ubuntu-latest
36- permissions :
37- security-events : write
38- contents : read
27+ if : github.actor != 'dependabot[bot]'
3928
4029 steps :
41- - uses : actions/checkout@v6
30+ - uses : actions/checkout@v7
4231 with :
4332 submodules : recursive
4433 fetch-depth : 0
@@ -59,50 +48,45 @@ jobs:
5948 continue-on-error : true
6049 run : ./gradlew detekt --continue
6150
62- - name : Check reports existence
63- id : check
64- if : always()
65- run : |
66- if [ -f app/build/reports/detekt/detekt.sarif ]; then echo "app=true" >> $GITHUB_OUTPUT; fi
67- if [ -f core/build/reports/detekt/detekt.sarif ]; then echo "core=true" >> $GITHUB_OUTPUT; fi
68- if [ -f runtime/build/reports/detekt/detekt.sarif ]; then echo "runtime=true" >> $GITHUB_OUTPUT; fi
69-
7051 - name : Merge SARIF files
52+ id : merge_sarif
7153 if : always()
7254 run : |
7355 mkdir -p merged-sarif
74- # Merge all available SARIF files into one. If app SARIF is missing, use a fallback or skip gracefully.
75- if [ ! -f app/build/reports/detekt/detekt.sarif ] && [ ! -f runtime/build/reports/detekt/detekt.sarif ] && [ ! -f core/build/reports/detekt/detekt.sarif ]; then
76- echo "No Detekt SARIF reports found to merge."
56+ mapfile -t sarif_files < <(find . -path '*/build/reports/detekt/detekt.sarif' -type f | sort)
57+ if (( ${#sarif_files[@]} == 0 )); then
58+ echo "No SARIF files found"
59+ echo "exists=false" >> "$GITHUB_OUTPUT"
7760 exit 0
7861 fi
7962
80- jq -s '
81- if length == 0 then empty else
82- {
83- "$schema": .[0]."$schema",
84- "version": .[0].version,
85- "runs": [
86- {
87- "tool": .[0].runs[0].tool,
88- "results": ([.[].runs[].results] | add)
89- }
90- ]
91- }
92- end
93- ' $([ -f app/build/reports/detekt/detekt.sarif ] && echo "app/build/reports/detekt/detekt.sarif") \
94- $([ -f runtime/build/reports/detekt/detekt.sarif ] && echo "runtime/build/reports/detekt/detekt.sarif") \
95- $([ -f core/build/reports/detekt/detekt.sarif ] && echo "core/build/reports/detekt/detekt.sarif") \
96- > merged-sarif/detekt.sarif 2>/dev/null || {
97- # Fallback if jq fails or files are missing
98- [ -f app/build/reports/detekt/detekt.sarif ] && cp app/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif || \
99- [ -f runtime/build/reports/detekt/detekt.sarif ] && cp runtime/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif || \
100- [ -f core/build/reports/detekt/detekt.sarif ] && cp core/build/reports/detekt/detekt.sarif merged-sarif/detekt.sarif
101- }
63+ python3 - "${sarif_files[@]}" <<'PY'
64+ import json
65+ import sys
66+ from pathlib import Path
67+
68+ inputs = [Path(path) for path in sys.argv[1:]]
69+ merged = None
70+ merged_runs = []
71+
72+ for path in inputs:
73+ data = json.loads(path.read_text())
74+ if merged is None:
75+ merged = data
76+ merged["runs"] = []
77+ merged_runs.extend(data.get("runs") or [])
78+
79+ if merged is None:
80+ raise SystemExit("No SARIF inputs")
81+
82+ merged["runs"] = merged_runs
83+ Path("merged-sarif/detekt.sarif").write_text(json.dumps(merged))
84+ PY
85+ echo "exists=true" >> "$GITHUB_OUTPUT"
10286
10387 - name : Upload merged SARIF results
10488 uses : github/codeql-action/upload-sarif@v4
105- if : always()
89+ if : always() && steps.merge_sarif.outputs.exists == 'true'
10690 continue-on-error : true
10791 with :
10892 sarif_file : merged-sarif/detekt.sarif
0 commit comments