generated from dciborow/pyaction
-
Notifications
You must be signed in to change notification settings - Fork 19
/
action.yml
210 lines (195 loc) · 5.91 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
name: 'Python Actions Collection'
description: 'Run actions for Python Project on pull requests to improve code review experience.'
author: 'dciborow'
inputs:
# Python Project Configuration is expected to be in a pyproject.toml
root:
description: |
Project root directory.
Default '.'
default: '.'
toml:
description: |
pyproject.toml location.
Default pyproject.toml
default: 'pyproject.toml'
python_version:
description: |
Python Version
Default is '3.7'.
default: '3.7'
# Python Tooling
black:
description: |
Run Black
Default is false.
default: false
bandit:
description: |
Run Bandit
Default is false.
default: false
pylint:
description: |
Run Pylint
Default is false.
default: false
pyright:
description: |
Run Pyright
Default is false.
default: false
flake8:
description: |
Run Flake8
Default is false.
default: false
pytest:
description: |
Run tests with PyTest
Default is false.
default: false
pypi_publish:
description: |
Publish to PyPi
Default is false
default: false
# Advanced Settings
args:
description: |
Customize which tests run with Pytest Markers
default: ''
pypi_repo:
description: |
PyPi Target. Use this to point to private or test locations.
Default testpypi
default: 'pypi'
pypi_password:
description: |
Credentials for PyPi
default: ''
version_suffix:
description: |
Value to append to version in order to produce unique id for PyPi.
Examples include:
'-rc {{ github.run_attempt }}'
'-dev {{ github.run_attempt }}'
default: ''
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
workdir:
description: 'Working directory relative to the root directory.'
default: 'src'
testdir:
description: 'Test directory'
default: 'tests'
coverage:
description: 'Flags for code coverage'
default: true
flags:
description: 'Flags for code coverage'
default: 'unittests'
### Flags for reviewdog ###
level:
description: 'Report level for reviewdog [info,warning,error]'
default: 'error'
reporter:
description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].'
default: 'github-pr-check'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Default is added.
default: 'added'
fail_on_error:
description: |
Exit code for reviewdog when errors are found [true,false]
Default is `false`.
default: 'false'
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
runs:
using: "composite"
steps:
- if: ${{ inputs.black == 'true' }}
uses: rickstaa/action-black@v1
id: action_black
with:
black_args: "--config ${{ inputs.root }}/${{ inputs.toml }} ${{ inputs.root }}/${{ inputs.workdir }}"
- if: steps.action_black.outputs.is_formatted == 'true'
uses: reviewdog/action-suggester@v1
with:
tool_name: blackfmt
fail_on_error: true
- if: ${{ inputs.bandit == 'true' }}
uses: dciborow/[email protected]
with:
workdir: ${{ inputs.root }}
- if: ${{ inputs.flake8 == 'true' }}
run: |
if [ $(cat pyproject.toml | grep "tool.flake8") ]; then
python -m pip install --upgrade pip
python -m pip install flake8-pyproject
fi
shell: bash
- if: ${{ inputs.flake8 == 'true' }}
uses: reviewdog/action-flake8@v3
with:
github_token: ${{ inputs.github_token }}
workdir: ${{ inputs.root }}/${{ inputs.workdir }}
- if: ${{ inputs.pylint == 'true' }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: 'pip' # caching pip dependencies
- if: ${{ inputs.pylint == 'true' }}
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install pylint
cd "${{ inputs.root }}/${{ inputs.workdir }}"
python -m flit install || python -m pip install .
- if: ${{ inputs.pylint == 'true' }}
uses: dciborow/[email protected]
with:
github_token: ${{ inputs.github_token }}
workdir: ${{ inputs.root }}/${{ inputs.workdir }}
- if: ${{ inputs.pyright == 'true' }}
uses: jakebailey/[email protected]
with:
working-directory: ${{ inputs.root }}/${{ inputs.workdir }}
project: ${{ inputs.toml }}
- if: ${{ inputs.pytest == 'true' || inputs.pypi_publish == 'true' }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: 'pip' # caching pip dependencies
- if: ${{ inputs.pytest == 'true' }}
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install pytest pytest-xdist pytest-cov flit requests_mock
cd "${{ inputs.root }}/${{ inputs.workdir }}"
python -m flit install || python -m pip install .
python -m pytest '${{ inputs.args }}' ${{ inputs.testdir }}
- if: ${{ inputs.pytest == 'true' && inputs.coverage == 'true' }}
uses: codecov/codecov-action@v3
with:
flags: ${{ inputs.flags }}
- if: ${{ inputs.pypi_publish == 'true' }}
shell: bash
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ inputs.pypi_password }}
run: |
cd "${{ inputs.root }}"
python -m pip install --upgrade pip
python -m pip install flit
sed -i -r 's/\"[0-9]\.[0-9]\.[0-9]+\"/&\"${{ inputs.version_suffix }}\"/g' src/*/__init__.py
python -m flit publish $repository --repository ${{ inputs.pypi_repo }} --pypirc .pypirc
# Ref: https://haya14busa.github.io/github-action-brandings/
branding:
icon: 'check'
color: 'blue'