Skip to content

finish tests for main report #86

finish tests for main report

finish tests for main report #86

Workflow file for this run

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_pylint.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/
python src/rattlesnake/cicd/reports_main_page.py \
--github_repo ${{ github.repository }} \
--pylint_score ${{ env.PYLINT_SCORE }} \
--output_file pages/index.html
- 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