I am relatively new to GitHub, and I am trying to write a GitHub workflow to automatically generate a badge that would be displayed on the README.md file. The workflow works without errors, but the file I expected to be generated is nowhere to be found.
I tried using the search feature to locate the two files I expected to be created (pylint.out
and pylint_badge.svg
), but I found nothing. I tested pylint_test.py
on my local machine, and it works fine. Maybe I configured the YAML file incorrectly?
Here's my code:
pylint_test.py (in the root directory)
from pylint.lint import Run
from pylint.reporters.text import TextReporter
from pybadges import badge
import os
grade = None
color = None
abs = "/home/runner/work/DigitsSolver/DigitsSolver/"
with open(abs + "pylint.out", "w+") as f:
reporter = TextReporter(f)
Run([abs + "solver"], reporter=reporter, exit=False)
with open(abs + "pylint.out", "r") as f:
f = f.read()
target = "Your code has been rated at "
f = f[f.index(target) + len(target):]
f = f[:f.index("/")]
grade = float(f)
if grade <= 1.2:
color = '#e7241d'
elif grade <= 3.6:
color = '#ef832c'
elif grade <= 6.0:
color = '#fffd46'
elif grade <= 8.4:
color = '#9cfa40'
else:
color = '#60f83d'
s = badge(left_text='pylint score', right_text=str(grade), right_color=color)
with open(abs + "pylint_badge.svg", "w+") as f:
f.write(s)
pylint-badge.yml (under the .github/workflow/
directory)
name: Pylint
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pybadges
pip install pylint
- name: Analyze the code with pylint
run: |
python pylint_test.py