fill out the matrix #8
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: CI | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
pull_request: | |
branches: | |
- main | |
- dev | |
jobs: | |
lint: | |
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: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install .[dev] | |
- name: pylint analysis and custom pylint HTML report | |
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" | |
# Read the pylint output and create a custom HTML report. | |
python src/rattlesnake/cicd/report_pylint.py \ | |
--input_file "$PYLINT_OUTPUT_FILE" \ | |
--output_file pylint_report.html \ | |
--timestamp "$TIMESTAMP" \ | |
--run_id ${{ github.run_id }} \ | |
--ref_name ${{ github.ref_name }} \ | |
--github_sha ${{ github.sha }} \ | |
--github_repo ${{ github.repository }} | |
- name: Upload pylint artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pylint-report | |
path: | | |
pylint_report.html | |
pylint_output_*.txt | |
coverage: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [macos-latest] | |
python-version: ["3.11"] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install .[dev] | |
- name: pytest coverage and custom coverage HTML report | |
run: | | |
# Create a timestamp for the output file | |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S_%Z") | |
pytest -v --cov=rattlesnake --cov-report=html --cov-report=xml --cov-report=term-missing | |
python src/rattlesnake/cicd/report_pytest.py \ | |
--input_file coverage.xml \ | |
--output_file pytest_report.html \ | |
--timestamp "$TIMESTAMP" \ | |
--run_id ${{ github.run_id }} \ | |
--ref_name ${{ github.ref_name }} \ | |
--github_sha ${{ github.sha }} \ | |
--github_repo ${{ github.repository }} | |
- name: Upload pytest artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pytest-report | |
path: | | |
pytest_report.html | |
htmlcov/ | |
coverage.xml | |
deploy: | |
needs: [lint, coverage] | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/dev' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.11" | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install .[dev] | |
- name: Download pylint artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: pylint-report | |
path: pylint-report | |
- name: Download pytest artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: pytest-report | |
path: pytest-report | |
- name: Create badges | |
run: | | |
# Pylint badge | |
PYLINT_OUTPUT_FILE=$(ls pylint-report/pylint_output_*.txt) | |
SCORE=$(grep "Your code has been rated at" "$PYLINT_OUTPUT_FILE" | awk '{print $7}' | cut -d'/' -f1 || echo "0") | |
python3 src/rattlesnake/cicd/pylint_badge_color.py "$SCORE" | |
mkdir -p badges | |
curl -o badges/pylint.svg "https://img.shields.io/badge/pylint-${SCORE}-${{ env.BADGE_COLOR }}.svg" | |
cat > badges/pylint-info.json << EOF | |
{ | |
"score": "${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/ci.yml", | |
"run_id": "${{ github.run_id }}", | |
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" | |
} | |
EOF | |
# Pytest badge | |
python3 src/rattlesnake/cicd/coverage_badge_color.py pytest-report/coverage.xml | |
REPO_URL="${{ github.server_url }}/${{ github.repository }}" | |
WORKFLOW_URL="${REPO_URL}/actions/workflows/ci.yml" | |
curl -o badges/coverage.svg "https://img.shields.io/badge/coverage-${{ env.COVERAGE }}%25-${{ env.BADGE_COLOR_COV }}.svg" | |
cat > badges/coverage-info.json << EOF | |
{ | |
"coverage": "${{ env.COVERAGE }}", | |
"color": "${{ env.BADGE_COLOR_COV }}", | |
"pages_url": "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/reports/coverage/", | |
"workflow_url": "${WORKFLOW_URL}", | |
"run_id": "${{ github.run_id }}", | |
"artifact_url": "${REPO_URL}/actions/runs/${{ github.run_id }}", | |
"timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" | |
} | |
EOF | |
- name: Commit badges | |
run: | | |
git pull | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add badges/ | |
git diff --staged --quiet || git commit -m "Update badges [skip ci]" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Assemble pages directory | |
run: | | |
mkdir -p pages/reports/pylint | |
mkdir -p pages/reports/coverage | |
mv pylint-report/pylint_report.html pages/reports/pylint/index.html | |
mv pytest-report/pytest_report.html pages/reports/coverage/index.html | |
mv pytest-report/htmlcov pages/reports/coverage/ | |
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 Vibration Controller - Reports</title> | |
<style> | |
body { font-family: sans-serif; margin: 40px; background-color: #f6f8fa; } | |
.container { max-width: 800px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } | |
h1 { color: #333; } | |
a { color: #0366d6; text-decoration: none; } | |
a:hover { text-decoration: underline; } | |
ul { list-style-type: none; padding: 0; } | |
li { background-color: #f1f1f1; margin: 10px 0; padding: 15px; border-radius: 4px; } | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Rattlesnake Vibration Controller - Reports</h1> | |
<p>This page provides links to the latest reports generated by the CI/CD pipeline.</p> | |
<ul> | |
<li><a href="reports/pylint/index.html">Pylint Report</a></li> | |
<li><a href="reports/coverage/index.html">Pytest Coverage Report</a></li> | |
</ul> | |
</div> | |
</body> | |
</html> | |
EOF | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./pages | |
publish_branch: gh-pages | |
keep_files: true | |
commit_message: 'Deploy reports for ${{ github.sha }}' | |
matrix: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [macos-latest, ubuntu-latest, windows-latest] | |
python-version: ["3.11", "3.12"] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install .[dev] | |
- name: Run tests | |
run: | | |
pytest -v |