-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yml
162 lines (152 loc) · 6.95 KB
/
action.yml
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: "Code Climate Standalone"
author: "Sean Erswell-Liljefelt"
description: "Runs a detached version of CodeClimate which reports only in the workflow and does not require the CodeClimate Service"
branding:
color: gray-dark
icon: chevrons-up
inputs:
config_file:
description: "Optionally provide a path to your codeclimate.yml relative to your project"
required: false
default: ".codeclimate.yml"
html_report:
description: "Should a faster, second, execution occur in order to generate an HTML report"
required: false
default: "false"
info_threshold:
description: "The number of findings of this severity allowed before the job returns a failure"
required: false
default: "0"
minor_threshold:
description: "The number of findings of this severity allowed before the job returns a failure"
required: false
default: "0"
major_threshold:
description: "The number of findings of this severity allowed before the job returns a failure"
required: false
default: "0"
critical_threshold:
description: "The number of findings of this severity allowed before the job returns a failure"
required: false
default: "0"
blocker_threshold:
description: "The number of findings of this severity allowed before the job returns a failure"
required: false
default: "0"
outputs:
info_findings:
description: "The number of findings of severity INFO"
value: ${{ steps.cc.outputs.info }}
minor_findings:
description: "The number of findings of severity MINOR"
value: ${{ steps.cc.outputs.minor }}
major_findings:
description: "The number of findings of severity MAJOR"
value: ${{ steps.cc.outputs.major }}
critical_findings:
description: "The number of findings of severity CRITICAL"
value: ${{ steps.cc.outputs.critical }}
blocker_findings:
description: "The number of findings of severity BLOCKER"
value: ${{ steps.cc.outputs.blocker }}
runs:
using: "composite"
steps:
# Initial Run is performed to get the results in a parseable format
- name: Code Climate
shell: bash
id: cc
env:
CC_CONF: ${{ inputs.config_file }}
CC_BLOCKERS_ALLOWED: ${{ inputs.blocker_threshold }}
CC_CRITICAL_ALLOWED: ${{ inputs.critical_threshold }}
CC_MAJOR_ALLOWED: ${{ inputs.major_threshold }}
CC_MINOR_ALLOWED: ${{ inputs.minor_threshold }}
CC_INFO_ALLOWED: ${{ inputs.info_threshold }}
run: |
# If no configuration supplied the job will run with Code Climate's default settings
# and language detection. Providing your own config is highly recommended for speed
# and accuracy
echo "#### CONFIG ####"
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
echo "Using the repository code climate configuration"
else
echo "::warning::No configuration found, using Code Climate's default configuration"
fi
# Run once for JSON output
echo "#### INITIAL RUN ####"
docker run \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze -f json > raw.json
# Strip the json to only issues
jq -c 'map(select(.type | test("issue"; "i")))' raw.json > codeclimate-report.json
# Parse to provide simple job output
TOTAL_ISSUES=$(jq '. | length' codeclimate-report.json)
TOTAL_BLOCKER=$(jq 'map(select(.severity == "blocker")) | length' codeclimate-report.json)
TOTAL_CRITICAL=$(jq 'map(select(.severity == "critical")) | length' codeclimate-report.json)
TOTAL_MAJOR=$(jq 'map(select(.severity == "major")) | length' codeclimate-report.json)
TOTAL_MINOR=$(jq 'map(select(.severity == "minor")) | length' codeclimate-report.json)
TOTAL_INFO=$(jq 'map(select(.severity == "info")) | length' codeclimate-report.json)
# Set outputs
echo "total=$TOTAL_ISSUES" >> $GITHUB_OUTPUT
echo "info=$TOTAL_INFO" >> $GITHUB_OUTPUT
echo "minor=$TOTAL_MINOR" >> $GITHUB_OUTPUT
echo "major=$TOTAL_MAJOR" >> $GITHUB_OUTPUT
echo "critical=$TOTAL_CRITICAL" >> $GITHUB_OUTPUT
echo "blocker=$TOTAL_BLOCKER" >> $GITHUB_OUTPUT
# Second run purely to get the readable HTML report. The second run is much faster than the first
# as it does not need to redownload the images already pulled by the first run
- name: Generate HTML Report
shell: bash
env:
CC_CONF: ${{ inputs.config_file }}
HTML_REPORT: ${{ inputs.html_report }}
run: |
if [ "$HTML_REPORT" = true ]; then
# If no configuration supplied the job will run with Code Climate's default settings
# and language detection. Providing your own config is highly recommended for speed
# and accuracy
echo "#### CONFIG ####"
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
echo "Using the repository code climate configuration"
else
echo "::warning::No configuration found, using Code Climate's default configuration"
fi
# Run for HTML output
echo "#### GENERATING HTML VERSION ####"
docker run \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze -f html > codeclimate-report.html
else
echo "HTML REPORT not requested, skipping..."
fi
# Determine the result
- name: Parse Result
shell: bash
env:
CC_BLOCKERS_ALLOWED: ${{ inputs.blocker_threshold }}
CC_CRITICAL_ALLOWED: ${{ inputs.critical_threshold }}
CC_MAJOR_ALLOWED: ${{ inputs.major_threshold }}
CC_MINOR_ALLOWED: ${{ inputs.minor_threshold }}
CC_INFO_ALLOWED: ${{ inputs.info_threshold }}
run: |
# Output in logs
echo "#### RESULT ####"
echo "total_issues: ${{ steps.cc.outputs.total }}"
echo "info: ${{ steps.cc.outputs.info }} allowed: $CC_INFO_ALLOWED"
echo "minor: ${{ steps.cc.outputs.minor }} allowed: $CC_MINOR_ALLOWED"
echo "major: ${{ steps.cc.outputs.major }} allowed: $CC_MAJOR_ALLOWED"
echo "critical: ${{ steps.cc.outputs.critical }} allowed: $CC_CRITICAL_ALLOWED"
echo "blocker: ${{ steps.cc.outputs.blocker }} allowed: $CC_BLOCKERS_ALLOWED"
# Pass or Fail the job depending on the findings / inputs
if [ ${{ steps.cc.outputs.blocker }} -gt "$CC_BLOCKERS_ALLOWED" ] || [ ${{ steps.cc.outputs.critical }} -gt "$CC_CRITICAL_ALLOWED" ] || [ ${{ steps.cc.outputs.major }} -gt "$CC_MAJOR_ALLOWED" ] || [ ${{ steps.cc.outputs.minor }} -gt "$CC_MINOR_ALLOWED" ] || [ ${{ steps.cc.outputs.info }} -gt "$CC_INFO_ALLOWED" ]; then
exit 1
else
exit 0
fi