-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaction.yml
105 lines (103 loc) · 3.77 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
name: "PyLint with dynamic badge"
description: "Perform pylint check on one or multiple packages/python files and update badge in README.md"
branding:
icon: edit-3
color: yellow
inputs:
lint-path:
description: "The path, relative to the root of the repo, of the package(s) or pyton file(s) to lint"
required: true
python-version:
description: "Python version which will install all dependencies and lint package(s)"
required: true
requirements-path:
description: "The path, relative to the root of the repo, of the requirements to install"
default: requirements.txt
required: false
readme-path:
description: "The path, relative to the root of the repo, of the README.md to update with the pylint badge"
default: README.md
required: false
pylintrc-path:
description: "The path, relative to the root of the repo, of the .pylintrc file containing custom lint rules to use"
default: ''
required: false
badge-text:
description: "Text to display in the badge"
default: PyLint
required: false
color-bad-score:
description: "Color of the badge for pylint scores < 5. Hex, rgb, rgba, hsl, hsla and css named colors can all be used"
default: red
required: false
color-ok-score:
description: "Color of the badge for pylint scores in range [5,8). Hex, rgb, rgba, hsl, hsla and css named colors can all be used"
default: orange
required: false
color-good-score:
description: "Color of the badge for pylint scores in range [8,10). Hex, rgb, rgba, hsl, hsla and css named colors can all be used"
default: yellow
required: false
color-perfect-score:
description: "Color of the badge for pylint scores == 10. Hex, rgb, rgba, hsl, hsla and css named colors can all be used"
default: brightgreen
required: false
runs:
using: "composite"
steps:
-
name: "Checkout Repository - PR"
uses: actions/checkout@v3
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.ref }}
-
name: "Checkout Repository - PUSH"
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
-
name: "Setup python"
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
-
name: "Setup installation requirements"
run: |
pip install --upgrade pip
pip install wheel pylint
pip install -r ${{ inputs.requirements-path }}
shell: bash
-
name: "Lint package(s)"
run: |
pkgs_pth=$(python3 -c 'import re; print(" ".join(re.findall("([^\s]+)", ${{ toJSON(inputs.lint-path) }})))')
pylint --exit-zero --rcfile=${{ inputs.pylintrc-path }} --output-format=text:pylint_score.txt,colorized $pkgs_pth
shell: bash
-
name: "Get numeric pylint score and badge color"
id: parameters-badge
run: |
python ${{ github.action_path }}/get_score_color.py \
${{ inputs.color-bad-score }} \
${{ inputs.color-ok-score }} \
${{ inputs.color-good-score }} \
${{ inputs.color-perfect-score }}
shell: bash
-
# $(echo ${{ inputs.badge-text }} | sed 's/ /%20/g') replaces spaces with %20
name: "Create badge and substitute it in README.md"
run: |
python ${{ github.action_path }}/create_subs_badge.py \
${{ inputs.readme-path }} \
${{ steps.parameters-badge.outputs.pylint_score }} \
$(echo ${{ inputs.badge-text }} | sed 's/ /%20/g') \
${{ steps.parameters-badge.outputs.badge_color }}
shell: bash
-
name: "Push README with changed badge to origin"
uses: EndBug/add-and-commit@v9
with:
add: 'README.md'
default_author: github_actions
message: 'Updated pylint badge'
push: 'true'