GitHub Action
Dynamic PyLint Badge connected with GitHub Artifact
This repository is a fork of Silleellie/pylint-github-action
and still in beta
GitHub action that lets you easily lint one or multiple packages (or python files) of your project and adds a dynamic badge
to your README.md
that lets you display the obtained score!
Each time the action is run, packages (or python files) specified will be linted and a badge in the README.md
is updated dynamically
following one of the below rules:
Range PyLint score | Badge |
---|---|
Bad score: PyLint score |
|
Ok score: |
|
Good score: |
|
Perfect score: PyLint score |
NEW: You can now fully customize the badge color of each of the above ranges! Check usage and scenario sections for more!
The action can be triggered by a Pull request
, a Push
or manually with workflow_dispatch
.
- IMPORTANT! Follow the 'Preliminary steps' section in order to allow the bot to update your README.md with the pylint badge!
A quick example on how you would typically use this action (more examples in scenario section)
- name: PyLint Scanning
id: pylint-scanning
uses: YaoYinYing/[email protected]
with:
lint-path: src # lint src package
python-version: ${{ env.lint-python-version }} # python version which will lint the package
badge-text: pylint score
badge-file-name: pylint_scan
conda-env-name: my-package
And after running the action, the GitHub action will update your PyLint badge file to artifacts named upload-my-awesome-badge
To use this action you should perform two simple first-time-only operations:
- In order to have a dynamic updated badge, before using for the first time this action, you should have a third party storage access (R2, S3, etc.) with publicly readable bucket.
- Add a section to your GA yml to download updated badge from artifact and upload it to R2:
- jobs:
DevTests: # # Previous run with linting
...
UpdateLinting:
runs-on: 'ubuntu-latest'
needs: DevTests # Previous run with linting as trigger
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: PyLint Badge Fetching
id: pylint-badge-fetch
uses: actions/download-artifact@v4
with:
name: upload-my-awesome-badge
path: badge_dir_with_uniq_name
- name: Display structure of downloaded files
run: ls -R badge_dir_with_uniq_name
- name: Upload to R2
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
command: r2 object put ${{ secrets.R2_BUCKET }}/badge_dir_with_uniq_name/my-code/pylint/pylint_scan.svg --file badge_dir_with_uniq_name/pylint_scan.svg --content-type image/svg+xml
After lint running, a new badge will be upload to R2 bucket ${{ secrets.R2_BUCKET }}
.
- Now you can add a markdown record to your README.md for this pylint badge:
[![pylint](https://R2-bucket-url/badge_dir_with_uniq_name/my-code/pylint/pylint_scan.svg)](https://github.com/YaoYinYing/pylint-github-action)
- Done!
- uses: YaoYinYing/[email protected]
with:
# The path, relative to the root of the repo, of the package(s) or pyton file(s) to lint
lint-path: src
# Python version which will install all dependencies and lint package(s)
python-version: 3.11
# Conda environment name for the package.
conda-env-name: base
# The path, relative to the root of the repo, of the requirements to install. If no such file here, leave it as default.
requirements-path: requirements.txt
# Text to display in the badge
badge-text: PyLint
# Color of the badge for pylint scores < 5. Hex, rgb, rgba, hsl, hsla and css named colors can all be used
color-bad-score: red
# Color of the badge for pylint scores in range [5,8). Hex, rgb, rgba, hsl, hsla and css named colors can all be used
color-ok-score: orange
# Color of the badge for pylint scores in range [8,10). Hex, rgb, rgba, hsl, hsla and css named colors can all be used
color-good-score: yellow
# Color of the badge for pylint scores == 10. Hex, rgb, rgba, hsl, hsla and css named colors can all be used
color-perfect-score: brightgreen
# The name of the artifact name for the badge file to upload.
badge-artifact-name: upload-my-awesome-badge
# The basename of badge file.
badge-file-name: badge
- uses: YaoYinYing/[email protected]
with:
lint-path: src
python-version: 3.11
- uses: YaoYinYing/[email protected]
with:
lint-path: main.py
python-version: 3.11
- uses: YaoYinYing/[email protected]
with:
lint-path: |
src
app
other_src/inner_src
python-version: 3.11
- uses: YaoYinYing/[email protected]
with:
lint-path: |
file1.py
file2.py
other_src/file3.py
python-version: 3.11
- uses: YaoYinYing/[email protected]
with:
lint-path: |
src
app
main.py
python-version: 3.11
- uses: YaoYinYing/[email protected]
with:
lint-path: src
python-version: 3.11
requirements-path: requirements/requirements-dev.txt
- uses: YaoYinYing/[email protected]
with:
lint-path: src
python-version: 3.11
badge-text: alternative text
In this case we are extending what we consider a perfect score: all scores in range
- uses: YaoYinYing/[email protected]
with:
lint-path: src
python-version: 3.11
color-good-score: brightgreen
color-perfect-score: brightgreen
In this example we are changing the color for the bad score range ($[0,5)$) to purple (hex code: 800080)
- uses: YaoYinYing/[email protected]
with:
lint-path: src
python-version: 3.11
color-bad-score: 800080
If you encounter issue like fatal: detected dubious ownership in repository at '/__w/<repo-name>/<repo-name>'
, you should add a CI step in your main test workflow (DevTests
, for the above example):
-
name: Set ownership
run: |
# this is to fix GIT not liking owner of the checkout dir
# https://github.com/actions/runner/issues/2033#issuecomment-1204205989
chown -R $(id -u):$(id -g) $PWD
shell: bash
This is a composite GitHub action which uses the following godly working actions:
- Silleellie/pylint-github-action
- actions/checkout
- actions/upload-artifact
- actions/download-artifact
- actions/setup-python
- cloudflare/wrangler-action
Massive thanks to shields.io, which is used to create the badge!