forked from sourcery-ai/action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
111 lines (99 loc) · 3.24 KB
/
action.yml
File metadata and controls
111 lines (99 loc) · 3.24 KB
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
name: "Sourcery Action"
branding:
icon: 'box'
color: 'orange'
description: "A GitHub Action for running Sourcery."
inputs:
token:
description: >
The Sourcery token for logging in.
The Sourcery token can be retrieved from
[your dashboard](https://sourcery.ai/dashboard/profile) and uploaded to your
GitHub repository as a
[GitHub secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
required: true
target:
description: "File(s) or directory(ies) to review."
required: false
default: "."
version:
description: >
Sourcery CLI version, e.g. '1.0.3'. If empty, default to the latest version
available.
required: false
default: ""
verbose:
description: >
Verbose output with explanation and code snippets. Either 'true' or 'false'.
required: false
default: "true"
check:
description: "Fail job if issues are found. Either 'true' or 'false'."
required: false
default: "true"
in_place:
description: "Change files in place. Either 'true' or 'false'."
required: false
default: "false"
config:
description: "Location of the Sourcery YAML configuration file."
required: false
default: ""
diff_ref:
description: >
Reference to compare the current branch with and run Sourcery on the diff.
If empty, run Sourcery on the entire codebase.
To review only code that changed in a PR, use
"github.event.pull_request.base.sha".
required: false
default: ""
runs:
using: composite
steps:
- name: Install Sourcery
shell: bash
run: |
if [ -z ${{ inputs.version }} ]
then
python3 -m pip install sourcery
else
python3 -m pip install sourcery==${{ inputs.version }}
fi
- name: Authenticate Sourcery
shell: bash
run: |
sourcery login --token ${{ inputs.token }}
- name: Sourcery review
shell: bash
run: |
if [ ${{ inputs.check }} == "true" ]; then
SOURCERY_OPTIONS+=( "--check" )
elif [ ${{ inputs.check }} != "false" ]; then
echo "Invalid value for input 'check'"
echo "Expected either 'true' or 'false'"
echo "Got '${{ inputs.check }}'"
exit 1
fi
if [ ${{ inputs.in_place }} == "true" ]; then
SOURCERY_OPTIONS+=( "--in-place" )
elif [ ${{ inputs.in_place }} != "false" ]; then
echo "Invalid value for input 'in_place'"
echo "Expected either 'true' or 'false'"
echo "Got '${{ inputs.in_place }}'"
exit 1
fi
if [ ${{ inputs.verbose }} == "true" ]; then
SOURCERY_OPTIONS+=( "--verbose" )
elif [ ${{ inputs.verbose }} != "false" ]; then
echo "Invalid value for input 'verbose'"
echo "Expected either 'true' or 'false'"
echo "Got '${{ inputs.verbose }}'"
exit 1
fi
if [ -n "${{ inputs.config }}" ]; then
SOURCERY_OPTIONS+=( "--config ${{ inputs.config }}" )
fi
if [ -n "${{ inputs.diff_ref }}" ]; then
SOURCERY_OPTIONS+=( "--diff=git diff ${{ inputs.diff_ref }}" )
fi
sourcery review "${SOURCERY_OPTIONS[@]}" ${{ inputs.target }}