Skip to content

Commit f9640d9

Browse files
authored
Merge pull request #295 from codacy/feat/codacy-cli-action-CY2806
feat: Create a GitHub action to run Codacy's CLI [CY-2806]
2 parents 85d779e + 56931a7 commit f9640d9

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,59 @@ codacy-analysis-cli analyse \
257257

258258
> In alternative to setting `--api-token` you can define CODACY_API_TOKEN in the environment.
259259
260+
## GitHub Action
261+
262+
The analysis CLI is available to be executed as a GitHub Action. The following is an example of a workflow
263+
using the CLI as an action, to analyse each commit and pull request.
264+
265+
```yaml
266+
name: codacy-analysis-cli
267+
268+
on: ["push"]
269+
270+
jobs:
271+
codacy-analysis-cli:
272+
runs-on: ubuntu-latest
273+
name: codacy-analysis-cli
274+
steps:
275+
- name: Checkout code
276+
uses: actions/checkout@master
277+
- name: Run codacy-analysis-cli
278+
uses: codacy/codacy-analysis-cli@master
279+
```
280+
281+
Running the action with the default configurations will:
282+
283+
- Analyse the current commit or pull request running all supported tools, with the default configuration,
284+
for the languages you are using.
285+
- Print analysis results into the console (you can check them in GitHub's action workflow panel).
286+
- Fail the workflow if at least one issue is found in your code.
287+
288+
Check the next section to see how you can further configure this action.
289+
290+
### Caveats
291+
292+
This action supports all [CLI configuration options](#commands-and-configuration) with the following exceptions:
293+
294+
- `--commit-uuid` -- **Not supported**. The action will only analyse the commit that triggered it.
295+
- `--api-token` -- **Not supported**. Use [`--project-token`](#project-token) instead.
296+
- `--username` -- **Not supported**. Use [`--project-token`](#project-token) instead.
297+
- `--project` -- **Not supported**. Use [`--project-token`](#project-token) instead.
298+
299+
The command `validate-configuration` is also **not supported**.
300+
301+
When using `--project-token` make sure to use [GitHub security features](#https://docs.github.com/en/actions/reference/encrypted-secrets)
302+
to prevent you from committing a secret token to your code. For example, if you store your Codacy project
303+
token in GitHub, this is how you would use it in the action workflow.
304+
305+
```yaml
306+
# ...
307+
uses: codacy/codacy-analysis-cli@master
308+
with:
309+
project-token: ${{ secrets.<PROJECT_TOKEN_NAME> }}
310+
# ...
311+
```
312+
260313
## Build
261314

262315
### Compile

action.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# action.yml
2+
name: "codacy-analysis-cli"
3+
author: "Codacy"
4+
description: "Execute Codacy code analysis using your remote Codacy configuration"
5+
branding:
6+
icon: 'check'
7+
color: 'gray-dark'
8+
inputs:
9+
verbose:
10+
required: false
11+
description: "Run with verbose output"
12+
project-token:
13+
required: false
14+
description: "A token to fetch your remote Codacy configuration for the project being analysed"
15+
codacy-api-base-url:
16+
required: false
17+
description: "Codacy's API URL, to retrieve the configuration."
18+
format:
19+
required: false
20+
description: "Format of the output file"
21+
output:
22+
required: false
23+
description: "Send analysis results to an output file"
24+
directory:
25+
required: false
26+
description: "The directory to be analysed"
27+
parallel:
28+
required: false
29+
description: "Number of tools to run in parallel"
30+
max-allowed-issues:
31+
required: false
32+
description: "Maximum number of issues allowed for the analysis to succeed"
33+
tool:
34+
required: false
35+
description: "The name of the tool to analyse the code"
36+
tool-timeout:
37+
required: false
38+
description: "Maximum time each tool has to execute"
39+
upload:
40+
required: false
41+
description: "Upload analysis results to Codacy"
42+
fail-if-incomplete:
43+
required: false
44+
description: "Fail the analysis if any tool fails to run"
45+
allow-network:
46+
required: false
47+
description: "Allow network access for tools"
48+
force-file-permissions:
49+
required: false
50+
description: "Force files to be readable by changing the permissions before running the analysis"
51+
runs:
52+
using: "composite"
53+
steps:
54+
- name: "Codacy CLI"
55+
shell: bash
56+
run: >-
57+
${{ github.action_path }}/bin/codacy-analysis-cli.sh
58+
analyse
59+
$(if [ ${{ inputs.verbose }} = true ]; then echo "--verbose"; fi)
60+
$(if [ ${{ inputs.project-token }} ]; then echo "--project-token ${{ inputs.project-token }}"; fi)
61+
$(if [ ${{ inputs.codacy-api-base-url }} ]; then echo "--codacy-api-base-url ${{ inputs.codacy-api-base-url }}"; fi)
62+
$(if [ ${{ inputs.format }} ]; then echo "--format ${{ inputs.format }}"; fi)
63+
$(if [ ${{ inputs.output }} ]; then echo "--output ${{ inputs.output }}"; fi)
64+
$(if [ ${{ inputs.directory }} ]; then echo "--directory ${{ inputs.directory }}"; fi)
65+
$(if [ ${{ inputs.parallel }} ]; then echo "--parallel ${{ inputs.parallel }}"; fi)
66+
$(if [ ${{ inputs.max-allowed-issues }} ]; then echo "--max-allowed-issues ${{ inputs.max-allowed-issues }}"; fi)
67+
$(if [ ${{ inputs.tool }} ]; then echo "--tool ${{ inputs.tool }}"; fi)
68+
$(if [ ${{ inputs.tool-timeout }} ]; then echo "--tool-timeout ${{ inputs.tool-timeout }}"; fi)
69+
$(if [ ${{ inputs.upload }} = true ]; then echo "--upload"; fi)
70+
$(if [ ${{ inputs.fail-if-incomplete }} = true ]; then echo "--fail-if-incomplete"; fi)
71+
$(if [ ${{ inputs.allow-network }} = true ]; then echo "--allow-network"; fi)
72+
$(if [ ${{ inputs.force-file-permissions }} = true ]; then echo "--force-file-permissions"; fi)

0 commit comments

Comments
 (0)