revert to pylint name #83
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pylint | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
pull_request: | |
branches: | |
- main | |
- dev | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.11" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
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") | |
PYLINT_OUTPUT_FILE="pylint_output_${TIMESTAMP}.txt" | |
# Generate text report | |
pylint src/rattlesnake/**/*.py --output-format=text --reports=yes > "$PYLINT_OUTPUT_FILE" || true | |
# Extract the score from pylint output | |
SCORE=$(grep "Your code has been rated at" "$PYLINT_OUTPUT_FILE" | awk '{print $7}' | cut -d'/' -f1 || echo "0") | |
# Output the score and file name | |
echo "🏁 Pylint analysis completed. 🏁" | |
echo " 📄 Output file: $PYLINT_OUTPUT_FILE" | |
echo " 🏆 Pylint score: $SCORE out of 10" | |
echo "PYLINT_SCORE=$SCORE" >> $GITHUB_ENV | |
echo "PYLINT_OUTPUT_FILE=$PYLINT_OUTPUT_FILE" >> $GITHUB_ENV | |
# Determine badge color based on score and add it as an environment variable | |
python3 src/rattlesnake/cicd/pylint_badge_color.py "$SCORE" | |
- name: Confirm new environment variables | |
run: | | |
echo "PYLINT_OUTPUT_FILE=${{ env.PYLINT_OUTPUT_FILE }}" | |
echo "PYLINT_SCORE=${{ env.PYLINT_SCORE }}" | |
echo "BADGE_COLOR=${{ env.BADGE_COLOR }}" | |
- name: Create custom Pylint Report in HTML format (refined version) | |
run: | | |
# Read the pylint output and create a custom HTML report, to be saved to | |
# https://sandialabs.github.io/rattlesnake-vibration-controller/reports/pylint/ | |
python src/rattlesnake/cicd/report_lint.py \ | |
--input_file ${{ env.PYLINT_OUTPUT_FILE }} \ | |
--output_file pylint_report.html \ | |
--run_id ${{ github.run_id }} \ | |
--ref_name ${{ github.ref_name }} \ | |
--github_sha ${{ github.sha }} \ | |
--github_repo ${{ github.repository }} | |
- name: Prepare GitHub Pages main landing page content | |
if: github.ref == 'refs/heads/dev' # Only deploy on dev branch | |
run: | | |
# Create pages directory structure | |
mkdir -p pages/reports/pylint | |
# Copy the pylint report as the main report | |
cp pylint_report.html pages/reports/pylint/index.html | |
# Create a main index page for all reports located at | |
# https://sandialabs.github.io/rattlesnake-vibration-controller/ | |
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 Summary</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> $(formatted_time)</p> | |
<a href="./reports/pylint/" class="report-link">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/main' # Only create badge on main branch | |
if: github.ref == 'refs/heads/dev' # Only create badge on dev branch, update to main branch later | |
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 (dev branch for now) | |
# if: github.ref == 'refs/heads/main' # Only create badge on main branch | |
if: github.ref == 'refs/heads/dev' # Only create badge on dev branch, update to main branch later | |
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 |