Skip to content

Commit 7c2d18c

Browse files
authored
Create detekt.yml
1 parent ded0992 commit 7c2d18c

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

.github/workflows/detekt.yml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 modifing the $DETEKT_RELEASE_TAG
17+
# environment variable.
18+
name: Scan with Detekt
19+
20+
on:
21+
# Triggers the workflow on push or pull request events but only for default and protected branches
22+
push:
23+
branches: [ "main" ]
24+
pull_request:
25+
branches: [ "main" ]
26+
schedule:
27+
- cron: '33 14 * * 4'
28+
29+
# Allows you to run this workflow manually from the Actions tab
30+
workflow_dispatch:
31+
32+
env:
33+
# Release tag associated with version of Detekt to be installed
34+
# SARIF support (required for this workflow) was introduced in Detekt v1.15.0
35+
DETEKT_RELEASE_TAG: v1.15.0
36+
37+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
38+
jobs:
39+
# This workflow contains a single job called "scan"
40+
scan:
41+
name: Scan
42+
# The type of runner that the job will run on
43+
runs-on: ubuntu-latest
44+
45+
# Steps represent a sequence of tasks that will be executed as part of the job
46+
steps:
47+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
48+
- uses: actions/checkout@v3
49+
50+
# Gets the download URL associated with the $DETEKT_RELEASE_TAG
51+
- name: Get Detekt download URL
52+
id: detekt_info
53+
env:
54+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: |
56+
gh api graphql --field tagName=$DETEKT_RELEASE_TAG --raw-field query='
57+
query getReleaseAssetDownloadUrl($tagName: String!) {
58+
repository(name: "detekt", owner: "detekt") {
59+
release(tagName: $tagName) {
60+
releaseAssets(name: "detekt", first: 1) {
61+
nodes {
62+
downloadUrl
63+
}
64+
}
65+
tagCommit {
66+
oid
67+
}
68+
}
69+
}
70+
}
71+
' 1> gh_response.json
72+
73+
DETEKT_RELEASE_SHA=$(jq --raw-output '.data.repository.release.releaseAssets.tagCommit.oid' gh_response.json)
74+
if [ $DETEKT_RELEASE_SHA != "37f0a1d006977512f1f216506cd695039607c3e5" ]; then
75+
echo "Release tag doesn't match expected commit SHA"
76+
exit 1
77+
fi
78+
79+
DETEKT_DOWNLOAD_URL=$(jq --raw-output '.data.repository.release.releaseAssets.nodes[0].downloadUrl' gh_response.json)
80+
echo "::set-output name=download_url::$DETEKT_DOWNLOAD_URL"
81+
82+
# Sets up the detekt cli
83+
- name: Setup Detekt
84+
run: |
85+
dest=$( mktemp -d )
86+
curl --request GET \
87+
--url ${{ steps.detekt_info.outputs.download_url }} \
88+
--silent \
89+
--location \
90+
--output $dest/detekt
91+
chmod a+x $dest/detekt
92+
echo $dest >> $GITHUB_PATH
93+
94+
# Performs static analysis using Detekt
95+
- name: Run Detekt
96+
continue-on-error: true
97+
run: |
98+
detekt --input ${{ github.workspace }} --report sarif:${{ github.workspace }}/detekt.sarif.json
99+
100+
# Modifies the SARIF output produced by Detekt so that absolute URIs are relative
101+
# This is so we can easily map results onto their source files
102+
# This can be removed once relative URI support lands in Detekt: https://git.io/JLBbA
103+
- name: Make artifact location URIs relative
104+
continue-on-error: true
105+
run: |
106+
echo "$(
107+
jq \
108+
--arg github_workspace ${{ github.workspace }} \
109+
'. | ( .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= if test($github_workspace) then .[($github_workspace | length | . + 1):] else . end )' \
110+
${{ github.workspace }}/detekt.sarif.json
111+
)" > ${{ github.workspace }}/detekt.sarif.json
112+
113+
# Uploads results to GitHub repository using the upload-sarif action
114+
- uses: github/codeql-action/upload-sarif@v2
115+
with:
116+
# Path to SARIF file relative to the root of the repository
117+
sarif_file: ${{ github.workspace }}/detekt.sarif.json
118+
checkout_path: ${{ github.workspace }}

0 commit comments

Comments
 (0)