forked from defunkt/pystache
-
Notifications
You must be signed in to change notification settings - Fork 5
112 lines (99 loc) · 3.3 KB
/
pylint.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
name: Pylint
on:
workflow_dispatch:
pull_request:
branches: [ master ]
push:
branches: [ master ]
jobs:
pylint:
runs-on: ubuntu-20.04
defaults:
run:
shell: bash
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
rating: ${{ steps.analyze.outputs.rating }}
path: ${{ steps.analyze.outputs.path }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Extract base branch name
id: extract_branch
shell: bash
run: |
TMP_PULL_BASE_REF="${{ github.base_ref }}"
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}"
EXPORT_VALUE=""
if [ "${TMP_PULL_BASE_REF}" != "" ]
then
EXPORT_VALUE="${TMP_PULL_BASE_REF}"
else
EXPORT_VALUE="${TMP_GITHUB_REF}"
fi
echo "branch=${EXPORT_VALUE}" >> $GITHUB_OUTPUT
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install tox
run: |
python -m pip install --upgrade pip wheel
pip install tox
- name: Run pylint
id: analyze
env:
BADGE_PATH: badges/pylint-score.svg
run: |
rating=$(bash -c 'tox -e lint' | grep 'Your code has been rated at' | cut -f7 -d " ")
echo "Pylint score: ${rating}"
echo "rating=${rating}" >> $GITHUB_OUTPUT
echo "path=${BADGE_PATH}" >> $GITHUB_OUTPUT
badge:
# Only generate and publish if these conditions are met:
# - The previous job/analyze step ended successfully
# - At least one of these is true:
# - This is a push event and the push event is on branch 'main' or 'develop'
# Note: if this repo is personal (ie, not an org repo) then you can
# use the following to change the scope of the next 2 jobs
# instead of running on branch push as shown below:
# - This is a pull request event and the pull actor is the same as the repo owner
# if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/main' }}
name: Generate badge image with pylint score
runs-on: ubuntu-20.04
needs: [pylint]
if: ${{ github.event_name == 'push' }}
steps:
- uses: actions/checkout@v3
with:
ref: badges
path: badges
# Use the output from the `analyze` step
- name: Create pylint badge
uses: emibcn/[email protected]
id: badge
with:
label: 'Pylint score'
status: ${{ needs.pylint.outputs.rating }}
color: 'green'
path: ${{ needs.pylint.outputs.path }}
- name: Commit badge
env:
BRANCH: ${{ needs.pylint.outputs.branch }}
FILE: 'pylint-score.svg'
working-directory: ./badges
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
mkdir -p "${BRANCH}"
mv "${FILE}" "${BRANCH}"
git add "${BRANCH}/${FILE}"
# Will give error if badge has not changed
git commit -m "Add/Update badge" || true
- name: Push badge commit
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: badges
directory: badges