Skip to content

generate linkable pylint report #16

generate linkable pylint report

generate linkable pylint report #16

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.9"] # we only need to lint once, select one Python version
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 .[dev]
pip install pylint2html # For HTML report generation
- 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"
HTML_FILE="pylint_report_${TIMESTAMP}.html"
# Generate text report
pylint src/rattlesnake/**/*.py --output-format=text --reports=yes > "$OUTPUT_FILE" || true
# Generate HTML report
pylint src/rattlesnake/**/*.py --output-format=json > pylint_report.json || true
pylint2html pylint_report.json -o "$HTML_FILE"
# Extract the score from pylint output
SCORE=$(grep "Your code has been rated at" "$OUTPUT_FILE" | awk '{print $7}' | cut -d'/' -f1 || echo "0")
echo "Pylint score: $SCORE out of 10"
echo "PYLINT_SCORE=$SCORE" >> $GITHUB_ENV
echo "HTML_FILE=$HTML_FILE" >> $GITHUB_ENV
echo "OUTPUT_FILE=$OUTPUT_FILE" >> $GITHUB_ENV
# Determine badge color based on score (using Python instead of bc for better compatibility)
python3 << EOF
import os
try:
score = float("$SCORE")
except ValueError:
score = 0.0
if score >= 8.0:
color = "brightgreen"
elif score >= 6.0:
color = "yellow"
elif score >= 4.0:
color = "orange"
else:
color = "red"
with open(os.environ['GITHUB_ENV'], 'a') as f:
f.write(f"BADGE_COLOR={color}\n")
EOF
- name: Create enhanced HTML report
run: |
# Create a comprehensive HTML report with navigation
cat > pylint_enhanced_report.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pylint Report - Rattlesnake</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0; padding: 20px; background: #f6f8fa;
}
.header {
background: white; padding: 20px; border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 20px;
}
.score {
font-size: 2em; font-weight: bold; color: #0366d6;
}
.timestamp {
color: #6a737d; font-size: 0.9em;
}
.nav {
margin: 20px 0;
}
.nav a {
background: #0366d6; color: white; padding: 8px 16px;
text-decoration: none; border-radius: 6px; margin-right: 10px;
}
.nav a:hover {
background: #0256cc;
}
.report-content {
background: white; padding: 20px; border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
pre {
background: #f6f8fa; padding: 16px; border-radius: 6px;
overflow-x: auto; border-left: 3px solid #0366d6;
}
</style>
</head>
<body>
<div class="header">
<h1>🐍 Rattlesnake Pylint Report</h1>
<div class="score">Score: ${{ env.PYLINT_SCORE }}/10</div>
<div class="timestamp">Generated: $(date)</div>
<div class="timestamp">Run ID: ${{ github.run_id }}</div>
<div class="timestamp">Branch: ${{ github.ref_name }}</div>
</div>
<div class="nav">
<a href="#summary">Summary</a>
<a href="#detailed-report">Detailed Report</a>
<a href="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}">View Workflow Run</a>
<a href="https://github.com/${{ github.repository }}">Back to Repository</a>
</div>
<div class="report-content">
<h2 id="summary">Summary</h2>
<p>This report was generated from the latest pylint analysis of the Rattlesnake codebase.</p>
<p><strong>Overall Score:</strong> ${{ env.PYLINT_SCORE }}/10</p>
<h2 id="detailed-report">Detailed Report</h2>
<pre>
EOF
# Append the actual pylint output
cat "${{ env.OUTPUT_FILE }}" >> pylint_enhanced_report.html
# Close the HTML
cat >> pylint_enhanced_report.html << 'EOF'
</pre>
</div>
<footer style="text-align: center; margin-top: 40px; color: #6a737d;">
<p>Generated by GitHub Actions • <a href="https://github.com/${{ github.repository }}">Rattlesnake Project</a></p>
</footer>
</body>
</html>
EOF
- name: Prepare GitHub Pages content
if: github.ref == 'refs/heads/dev' # Only deploy on dev branch
run: |
# Create pages directory structure
mkdir -p pages/reports/pylint
# Copy the enhanced report as the main report
cp pylint_enhanced_report.html pages/reports/pylint/index.html
# Create a main index page for all reports
cat > pages/index.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rattlesnake Code Quality Reports</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0; padding: 20px; background: #f6f8fa;
}
.container {
max-width: 800px; margin: 0 auto;
}
.header {
background: white; padding: 30px; border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 30px; text-align: center;
}
.report-card {
background: white; padding: 20px; border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1); margin-bottom: 20px;
}
.report-card h3 {
margin-top: 0; color: #0366d6;
}
.report-link {
background: #0366d6; color: white; padding: 10px 20px;
text-decoration: none; border-radius: 6px; display: inline-block;
}
.report-link:hover {
background: #0256cc;
}
.badge {
margin: 10px 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🐍 Rattlesnake Code Quality Reports</h1>
<p>Automated code quality analysis for the Rattlesnake vibration controller</p>
<div class="badge">
<img src="https://github.com/${{ github.repository }}/raw/dev/badges/pylint.svg" alt="Pylint Score">
</div>
<div class="badge">
<img src="https://github.com/${{ github.repository }}/raw/dev/badges/coverage.svg" alt="Coverage">
</div>
</div>
<div class="report-card">
<h3>📊 Pylint Report</h3>
<p>Static code analysis results showing code quality metrics, style compliance, and potential issues.</p>
<p><strong>Latest Score:</strong> ${{ env.PYLINT_SCORE }}/10</p>
<p><strong>Last Updated:</strong> $(date)</p>
<a href="./reports/pylint/" class="report-link">View Pylint Report</a>
</div>
<div class="report-card">
<h3>🔗 Quick Links</h3>
<p>
<a href="https://github.com/${{ github.repository }}" class="report-link">GitHub Repository</a>
<a href="https://github.com/${{ github.repository }}/actions" class="report-link">GitHub Actions</a>
<a href="https://github.com/${{ github.repository }}/releases" class="report-link">Releases</a>
</p>
</div>
</div>
</body>
</html>
EOF
- name: Create pylint badge with GitHub Pages link
if: github.ref == 'refs/heads/dev' # Only create badge on dev 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"
# Create badge metadata with GitHub Pages link
cat > badges/pylint-info.json << EOF
{
"score": "${{ env.PYLINT_SCORE }}",
"color": "${{ env.BADGE_COLOR }}",
"pages_url": "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/reports/pylint/",
"workflow_url": "${{ github.server_url }}/${{ github.repository }}/actions/workflows/pylint.yml",
"run_id": "${{ github.run_id }}",
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
}
EOF
- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/dev'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./pages
publish_branch: gh-pages
commit_message: 'Deploy pylint report for ${{ github.sha }}'
- name: Commit badge to main repository
if: github.ref == 'refs/heads/dev'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add badges/pylint.svg badges/pylint-info.json
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 }}
path: pylint_output*.txt
retention-days: 7