| 1 |
name: Pylint |
| 2 |
|
| 3 |
on: |
| 4 |
workflow_dispatch: |
| 5 |
pull_request: |
| 6 |
branches: [ master ] |
| 7 |
push: |
| 8 |
branches: [ master ] |
| 9 |
|
| 10 |
jobs: |
| 11 |
pylint: |
| 12 |
|
| 13 |
runs-on: ubuntu-20.04 |
| 14 |
defaults: |
| 15 |
run: |
| 16 |
shell: bash |
| 17 |
outputs: |
| 18 |
branch: ${{ steps.extract_branch.outputs.branch }} |
| 19 |
rating: ${{ steps.analyze.outputs.rating }} |
| 20 |
path: ${{ steps.analyze.outputs.path }} |
| 21 |
|
| 22 |
steps: |
| 23 |
- uses: actions/checkout@v3 |
| 24 |
with: |
| 25 |
fetch-depth: 0 |
| 26 |
|
| 27 |
- name: Extract base branch name |
| 28 |
id: extract_branch |
| 29 |
shell: bash |
| 30 |
run: | |
| 31 |
TMP_PULL_BASE_REF="${{ github.base_ref }}" |
| 32 |
TMP_GITHUB_REF="${GITHUB_REF#refs/heads/}" |
| 33 |
EXPORT_VALUE="" |
| 34 |
if [ "${TMP_PULL_BASE_REF}" != "" ] |
| 35 |
then |
| 36 |
EXPORT_VALUE="${TMP_PULL_BASE_REF}" |
| 37 |
else |
| 38 |
EXPORT_VALUE="${TMP_GITHUB_REF}" |
| 39 |
fi |
| 40 |
echo "branch=${EXPORT_VALUE}" >> $GITHUB_OUTPUT |
| 41 |
|
| 42 |
- name: Set up Python 3.9 |
| 43 |
uses: actions/setup-python@v4 |
| 44 |
with: |
| 45 |
python-version: 3.9 |
| 46 |
|
| 47 |
- name: Install tox |
| 48 |
run: | |
| 49 |
python -m pip install --upgrade pip wheel |
| 50 |
pip install tox |
| 51 |
|
| 52 |
- name: Run pylint |
| 53 |
id: analyze |
| 54 |
env: |
| 55 |
BADGE_PATH: badges/pylint-score.svg |
| 56 |
run: | |
| 57 |
rating=$(bash -c 'tox -e lint' | grep 'Your code has been rated at' | cut -f7 -d " ") |
| 58 |
echo "Pylint score: ${rating}" |
| 59 |
echo "rating=${rating}" >> $GITHUB_OUTPUT |
| 60 |
echo "path=${BADGE_PATH}" >> $GITHUB_OUTPUT |
| 61 |
|
| 62 |
badge: |
| 63 |
# Only generate and publish if these conditions are met: |
| 64 |
# - The previous job/analyze step ended successfully |
| 65 |
# - At least one of these is true: |
| 66 |
# - This is a push event and the push event is on branch 'main' or 'develop' |
| 67 |
# Note: if this repo is personal (ie, not an org repo) then you can |
| 68 |
# use the following to change the scope of the next 2 jobs |
| 69 |
# instead of running on branch push as shown below: |
| 70 |
# - This is a pull request event and the pull actor is the same as the repo owner |
| 71 |
# if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/main' }} |
| 72 |
name: Generate badge image with pylint score |
| 73 |
runs-on: ubuntu-20.04 |
| 74 |
needs: [pylint] |
| 75 |
if: ${{ github.event_name == 'push' }} |
| 76 |
|
| 77 |
steps: |
| 78 |
- uses: actions/checkout@v3 |
| 79 |
with: |
| 80 |
ref: badges |
| 81 |
path: badges |
| 82 |
|
| 83 |
# Use the output from the `analyze` step |
| 84 |
- name: Create pylint badge |
| 85 |
uses: emibcn/[email protected] |
| 86 |
id: badge |
| 87 |
with: |
| 88 |
label: 'Pylint score' |
| 89 |
status: ${{ needs.pylint.outputs.rating }} |
| 90 |
color: 'green' |
| 91 |
path: ${{ needs.pylint.outputs.path }} |
| 92 |
|
| 93 |
- name: Commit badge |
| 94 |
env: |
| 95 |
BRANCH: ${{ needs.pylint.outputs.branch }} |
| 96 |
FILE: 'pylint-score.svg' |
| 97 |
working-directory: ./badges |
| 98 |
run: | |
| 99 |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 100 |
git config --local user.name "github-actions[bot]" |
| 101 |
mkdir -p "${BRANCH}" |
| 102 |
mv "${FILE}" "${BRANCH}" |
| 103 |
git add "${BRANCH}/${FILE}" |
| 104 |
# Will give error if badge has not changed |
| 105 |
git commit -m "Add/Update badge" || true |
| 106 |
|
| 107 |
- name: Push badge commit |
| 108 |
uses: ad-m/github-push-action@master |
| 109 |
with: |
| 110 |
github_token: ${{ secrets.GITHUB_TOKEN }} |
| 111 |
branch: badges |
| 112 |
directory: badges |