-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaction.yml
286 lines (272 loc) · 13.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# action.yml
name: "Codacy Analysis CLI"
author: "Codacy"
description: "Execute Codacy code analysis using your remote Codacy configuration"
branding:
icon: "check"
color: "gray-dark"
inputs:
verbose:
required: false
description: "Run with verbose output"
project-token:
required: false
description: "API project token to retrieve your remote Codacy configuration for the project being analyzed"
api-token:
required: false
description: "API account token to retrieve your remote Codacy configuration for the project being analyzed"
codacy-api-base-url:
required: false
description: "Codacy API URL to retrieve your remote Codacy configuration"
format:
required: false
description: "Output file format"
output:
required: false
description: "Path to a file to save the analysis results"
directory:
required: false
description: "Directory to analyze"
parallel:
required: false
description: "Number of tools to run in parallel"
max-tool-memory:
required: false
description: "Maximum allowed memory for running each tool (bytes)"
max-allowed-issues:
required: false
default: "2147483647"
description: "Maximum number of issues allowed for the analysis to succeed"
registry-address:
required: false
default: ""
description: "Alternative registry address (e.g. artprod.mycompany/)"
tool:
required: false
description: >-
Only run a specific tool or tool category (metrics, issues, duplication).
For the full list of tools, see https://docs.codacy.com/repositories-configure/codacy-configuration-file/#which-tools-can-be-configured-and-which-name-should-i-use
tool-timeout:
required: false
description: "Tool execution timeout (e.g. 15minutes, 1hour)"
upload:
required: false
description: "Upload analysis results to Codacy"
upload-batch-size:
required: false
description: "Maximum number of results in each batch to upload to Codacy"
fail-if-incomplete:
required: false
description: "Fail the analysis if any tool fails to run"
allow-network:
required: false
description: "Allow the tools to access the network"
force-file-permissions:
required: false
description: "Force files to be readable by changing the permissions before running the analysis"
gh-code-scanning-compat:
required: false
description: >-
Reduce issue severity by one level for non-security issues, for compatibility with GitHub's code scanning feature.
This option only has an effect when used with 'format: sarif'.
run-docker-tools:
required: false
default: "true"
description: >-
Run all dockerized tools supported by Codacy.
For the full list of tools, see https://docs.codacy.com/repositories-configure/codacy-configuration-file/#which-tools-can-be-configured-and-which-name-should-i-use
run-gosec:
required: false
description: "Run Gosec"
run-staticcheck:
required: false
description: "Run Staticcheck"
clang-tidy-output:
required: false
description: "Path to a file containing the output of Clang-Tidy."
faux-pas-output:
required: false
description: "Path to a file containing the output of Faux Pas."
skip-uncommitted-files-check:
required: false
description: "Skip validation of uncommitted changes"
skip-container-engine-check:
required: false
description: "Skip check for the presence of a known container engine before executing"
runs:
using: "composite"
steps:
- name: "Set Global Variables"
shell: bash
run: |
echo "CODACY_BASE_URL_OR_DEFAULT=$(if [ -n "${{ inputs.codacy-api-base-url }}" ]; then echo "${{ inputs.codacy-api-base-url }}"; else echo "https://api.codacy.com"; fi)" >> "$GITHUB_ENV"
echo "OWNER_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 1)" >> "$GITHUB_ENV"
echo "REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d '/' -f 2)" >> "$GITHUB_ENV"
echo "ORGANIZATION_PROVIDER=$(if [ "$GITHUB_SERVER_URL" == "https://github.com" ]; then echo "gh"; else echo "ghe"; fi)" >> "$GITHUB_ENV"
echo "COMMIT_SHA=$(if [ "${{ github.event_name }}" == "pull_request" ]; then echo "${{ github.event.pull_request.head.sha }}"; else echo "${{ github.sha }}"; fi)" >> "$GITHUB_ENV"
if [ -n "${{ inputs.skip-container-engine-check }}" ]; then
echo "SKIP_CONTAINER_ENGINE_CHECK=${{ inputs.skip-container-engine-check }}" >> "$GITHUB_ENV"
fi
- name: "Prepare curl authentication header"
shell: bash
run: |
if [ -n "${{ inputs.api-token }}" ]; then
echo "CURL_CODACY_AUTH_AUTHENTICATION=api-token: ${{ inputs.api-token }}" >> $GITHUB_ENV
elif [ -n "${{ inputs.project-token }}" ]; then
echo "CURL_CODACY_AUTH_AUTHENTICATION=project-token: ${{ inputs.project-token }}" >> $GITHUB_ENV
elif [ "${{ inputs.upload }}" == "true" ]; then
echo "At least one authentication method is required to upload results."
exit 1
fi
- name: "Run GoSec"
shell: bash
run: |
set -eux
if [ "${{ inputs.run-gosec }}" == "true" ]; then
cd /tmp
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s v2.15.0
chmod +x ./bin/gosec
CODACY_GOSEC_VERSION=$(curl -SL "https://artifacts.codacy.com/bin/codacy-gosec/latest" -o-)
curl -fsSL "https://artifacts.codacy.com/bin/codacy-gosec/$CODACY_GOSEC_VERSION/codacy-gosec-$CODACY_GOSEC_VERSION" -o /tmp/codacy-gosec
chmod +x /tmp/codacy-gosec
cd -
/tmp/bin/gosec -no-fail -fmt json -log /tmp/log.txt ./... > /tmp/gosec-out.json
/tmp/codacy-gosec < /tmp/gosec-out.json > /tmp/codacy-out.json
if [ "${{ inputs.upload }}" == "true" ]; then
curl -XPOST -L -H "$CURL_CODACY_AUTH_AUTHENTICATION" \
-H "Content-type: application/json" --data-binary @/tmp/codacy-out.json \
"${CODACY_BASE_URL_OR_DEFAULT}/2.0/$ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME/commit/$COMMIT_SHA/issuesRemoteResults"
else
cat /tmp/codacy-out.json
fi
else
echo "Skipping GoSec"
fi
- name: set-up go
if: ${{ inputs.run-staticcheck == 'true' }}
uses: actions/setup-go@v3
with:
go-version: 1.20.2
- name: "Run StaticCheck"
shell: bash
run: |
set -eux
if [ "${{ inputs.run-staticcheck }}" == "true" ]; then
cd /tmp
go install honnef.co/go/tools/cmd/[email protected]
chmod +x /home/runner/go/bin/staticcheck
CODACY_STATICCHECK_VERSION=$(curl -SL "https://artifacts.codacy.com/bin/codacy-staticcheck/latest" -o-)
curl -fsSL "https://artifacts.codacy.com/bin/codacy-staticcheck/$CODACY_STATICCHECK_VERSION/codacy-staticcheck-$CODACY_STATICCHECK_VERSION" -o /tmp/codacy-staticcheck
chmod +x /tmp/codacy-staticcheck
cd -
find . -type f -name go.mod -exec bash -c 'cd $(dirname $1); cp $1 $1.codacy.bak; PKGS=$(go list ./...); /home/runner/go/bin/staticcheck -f json $PKGS; mv $1.codacy.bak $1' _ {} \; > /tmp/staticcheck-out.json
/tmp/codacy-staticcheck < /tmp/staticcheck-out.json > /tmp/codacy-out.json
if [ "${{ inputs.upload }}" == "true" ]; then
curl -XPOST -L -H "$CURL_CODACY_AUTH_AUTHENTICATION" \
-H "Content-type: application/json" --data-binary @/tmp/codacy-out.json \
"${CODACY_BASE_URL_OR_DEFAULT}/2.0/$ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME/commit/$COMMIT_SHA/issuesRemoteResults"
else
cat /tmp/codacy-out.json
fi
else
echo "Skipping StaticCheck"
fi
- name: "Parse and Push Clang Tidy results"
shell: bash
run: |
set -eux
if [ -n "${{ inputs.clang-tidy-output }}" ]; then
cd /tmp
CODACY_CLANG_TIDY_VERSION=$(curl -SL "https://artifacts.codacy.com/bin/codacy-clang-tidy/latest" -o-)
curl -fsSL "https://artifacts.codacy.com/bin/codacy-clang-tidy/$CODACY_CLANG_TIDY_VERSION/codacy-clang-tidy-linux-$CODACY_CLANG_TIDY_VERSION" -o /tmp/codacy-clang-tidy
chmod +x /tmp/codacy-clang-tidy
cd -
/tmp/codacy-clang-tidy < "${{ inputs.clang-tidy-output }}" > /tmp/codacy-out.json
if [ "${{ inputs.upload }}" == "true" ]; then
curl -XPOST -L -H "$CURL_CODACY_AUTH_AUTHENTICATION" \
-H "Content-type: application/json" --data-binary @/tmp/codacy-out.json \
"${CODACY_BASE_URL_OR_DEFAULT}/2.0/$ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME/commit/$COMMIT_SHA/issuesRemoteResults"
else
cat /tmp/codacy-out.json
fi
else
echo "Skipping Clang Tidy"
fi
- name: "Parse and Push Faux Pas results"
shell: bash
run: |
set -eux
if [ -n "${{ inputs.faux-pas-output }}" ]; then
cd /tmp
CODACY_FAUX_PAS_VERSION=$(curl -SL "https://artifacts.codacy.com/bin/codacy-faux-pas/latest" -o-)
curl -fsSL "https://artifacts.codacy.com/bin/codacy-faux-pas/$CODACY_FAUX_PAS_VERSION/codacy-faux-pas-$CODACY_FAUX_PAS_VERSION" -o /tmp/codacy-faux-pas
chmod +x /tmp/codacy-faux-pas
cd -
/tmp/codacy-faux-pas < "${{ inputs.faux-pas-output }}" > /tmp/codacy-out.json
if [ "${{ inputs.upload }}" == "true" ]; then
curl -XPOST -L -H "$CURL_CODACY_AUTH_AUTHENTICATION" \
-H "Content-type: application/json" --data-binary @/tmp/codacy-out.json \
"${CODACY_BASE_URL_OR_DEFAULT}/2.0/$ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME/commit/$COMMIT_SHA/issuesRemoteResults"
else
cat /tmp/codacy-out.json
fi
else
echo "Skipping Faux Pas"
fi
- name: "Set Codacy CLI version"
shell: bash
run: echo "CODACY_ANALYSIS_CLI_VERSION=7.9.11" >> $GITHUB_ENV
- name: "Set script path environment variable"
shell: bash
run: echo "CLI_SCRIPT_PATH=${{ github.action_path }}/codacy-analysis-cli.sh" >> $GITHUB_ENV
- name: "Download Codacy CLI script"
shell: bash
run: wget -O - https://raw.githubusercontent.com/codacy/codacy-analysis-cli/${{ env.CODACY_ANALYSIS_CLI_VERSION }}/bin/codacy-analysis-cli.sh > ${{ env.CLI_SCRIPT_PATH }}
- name: "Change Codacy CLI script permissions"
shell: bash
run: chmod +x "${{ env.CLI_SCRIPT_PATH }}"
- name: "Run Codacy CLI"
shell: bash
run: |
if [ -n "${{ inputs.registry-address }}" ]; then
export REGISTRY_ADDRESS=${{ inputs.registry-address }}
fi
if [ "${{ inputs.run-docker-tools }}" == "true" ]; then
${{ env.CLI_SCRIPT_PATH }} \
analyze \
--skip-commit-uuid-validation \
--commit-uuid $COMMIT_SHA \
$(if [ "${{ inputs.verbose }}" == "true" ]; then echo "--verbose"; fi) \
$(if [ -n "${{ inputs.project-token }}" ]; then echo "--project-token ${{ inputs.project-token }}"; fi) \
$(if [ -n "${{ inputs.api-token }}" ]; then echo "--api-token ${{ inputs.api-token }} --username $OWNER_NAME --project $REPOSITORY_NAME --provider $ORGANIZATION_PROVIDER"; fi) \
$(if [ -n "${{ inputs.codacy-api-base-url }}" ]; then echo "--codacy-api-base-url ${{ inputs.codacy-api-base-url }}"; fi) \
$(if [ -n "${{ inputs.format }}" ]; then echo "--format ${{ inputs.format }}"; fi) \
$(if [ -n "${{ inputs.output }}" ]; then echo "--output ${{ inputs.output }}"; fi) \
$(if [ -n "${{ inputs.directory }}" ]; then echo "--directory ${{ inputs.directory }}"; fi) \
$(if [ -n "${{ inputs.parallel }}" ]; then echo "--parallel ${{ inputs.parallel }}"; fi) \
$(if [ -n "${{ inputs.max-tool-memory }}" ]; then echo "--max-tool-memory ${{ inputs.max-tool-memory }}"; fi) \
$(if [ -n "${{ inputs.max-allowed-issues }}" ]; then echo "--max-allowed-issues ${{ inputs.max-allowed-issues }}"; fi) \
$(if [ -n "${{ inputs.tool }}" ]; then echo "--tool ${{ inputs.tool }}"; fi) \
$(if [ -n "${{ inputs.tool-timeout }}" ]; then echo "--tool-timeout ${{ inputs.tool-timeout }}"; fi) \
$(if [ "${{ inputs.skip-uncommitted-files-check }}" == "true" ]; then echo "--skip-uncommitted-files-check"; fi) \
$(if [ "${{ inputs.upload }}" == "true" ]; then echo "--upload"; fi) \
$(if [ -n "${{ inputs.upload-batch-size }}" ]; then echo "--upload-batch-size ${{ inputs.upload-batch-size }}"; fi) \
$(if [ "${{ inputs.fail-if-incomplete }}" == "true" ]; then echo "--fail-if-incomplete"; fi) \
$(if [ "${{ inputs.allow-network }}" == "true" ]; then echo "--allow-network"; fi) \
$(if [ "${{ inputs.force-file-permissions }}" == "true" ]; then echo "--force-file-permissions"; fi) \
$(if [ "${{ inputs.gh-code-scanning-compat }}" == "true" ]; then echo "--gh-code-scanning-compat"; fi) \
$(if [ -n "${{ inputs.registry-address }}" ]; then echo "--registry-address ${{ inputs.registry-address }}"; fi)
else
echo "Skipping docker tools"
fi
- name: "Let Codacy know it can start processing the analysis results"
shell: bash
run: |
if [ "${{ inputs.upload }}" == "true" ]; then
echo "Uploading results for $ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME commit $COMMIT_SHA"
curl -XPOST -L -H "$CURL_CODACY_AUTH_AUTHENTICATION" \
-H "Content-type: application/json" \
"${CODACY_BASE_URL_OR_DEFAULT}/2.0/$ORGANIZATION_PROVIDER/$OWNER_NAME/$REPOSITORY_NAME/commit/$COMMIT_SHA/resultsFinal"
else
echo "Skipping results upload"
fi