Skip to content

more badge work

more badge work #10

Workflow file for this run

name: pylint
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v4
- 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 pylint
pip install .[dev]
- name: Analyzing the code with pylint
run: |
# Create a timestamp for the output file
TIMESTAMP=$(date +"%Y%m%d_%H%M%S_%Z")
OUTPUT_FILE="pylint_output_${TIMESTAMP}.txt"
pylint src/rattlesnake/**/*.py --output-format=text --reports=yes > "$OUTPUT_FILE" || true # Allow the command to fail without failing the job
# Extract the score from pylint output
SCORE=$(grep "Your code has been rated at" "$OUTPUT_FILE" | awk '{print $7}' | cut -d'/' -f1)
echo "Pylint score: $SCORE out of 10.0"
echo "PYLINT_SCORE=$SCORE" >> $GITHUB_ENV
# Determine badge color based on score
if (( $(echo "$SCORE >= 8.0" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$SCORE >= 6.0" | bc -l) )); then
COLOR="yellow"
elif (( $(echo "$SCORE >= 4.0" | bc -l) )); then
COLOR="orange"
else
COLOR="red"
fi
echo "BADGE_COLOR=$COLOR" >> $GITHUB_ENV
- name: Create pylint badge
if: github.ref == 'refs/heads/main' # Only create badge on main branch
run: |
# Create badges directory if it doesn't exist
mkdir -p badges
# Download badge using shields.io
curl -o badges/pylint.svg "https://img.shields.io/badge/pylint-${{ env.PYLINT_SCORE }}-${{ env.BADGE_COLOR }}.svg"
- name: Commit badge
# if: github.ref == 'refs/heads/main' # Only create badge on main branch
if: github.ref == 'refs/heads/dev' # Only create badge on dev branch
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add badges/pylint.svg
git diff --staged --quiet || git commit -m "Update pylint badge [skip ci]"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload pylint output as artifact
uses: actions/upload-artifact@v4
with:
name: pylint-output-${{ github.run_id }} # Use the run ID to ensure uniqueness
path: pylint_output*.txt # Uplaod timestamped output file
retention-days: 7 # Retain the artifact for 7 days