-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
130 lines (117 loc) · 4.05 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
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.5.0'. 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"
fix:
description: "Automatically fix issues where possible. Either 'true' or 'false'."
required: false
default: "false"
in_place:
description: "Change files in place. Either 'true' or 'false'."
required: false
default: "false"
deprecationMessage: >
This input is deprecated and will be removed in a future release. Please update
your Sourcery `version` and use `fix` instead of `in_place`.
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.fix }} == "true" ]; then
SOURCERY_OPTIONS+=( "--fix" )
elif [ ${{ inputs.fix }} != "false" ]; then
echo "Invalid value for input 'fix'"
echo "Expected either 'true' or 'false'"
echo "Got '${{ inputs.fix }}'"
exit 1
fi
# this input is deprecated and will be removed in a future release
# we are keeping it here because users might have pinned Sourcery to an older
# version that does not support `--fix`
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 }}