Merge branch 'presentation-link-on-readme' of github.com:Zhi-704/Rail… #701
Workflow file for this run
This file contains 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: Quality Checks | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- '*' | |
jobs: | |
build: | |
name: pylint and pytest scores | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Install Python | |
- name: Install Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
# Install dependencies | |
- name: Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pytest pylint | |
for FILE in $(find . -name 'requirements.txt'); do | |
pip install -r $FILE | |
done | |
# Run pytest | |
- name: Run tests | |
run: | | |
pytest | |
# Write Pytest overview results to a file | |
- name: Record test results | |
if: '!cancelled()' | |
run: | | |
[ ! -f .util/pytest_scores.txt ] && touch '.util/pytest_scores.txt' | |
pytest -r N --tb=no > .util/pytest_scores.txt || true | |
- name: Create pylint_scores | |
if: '!cancelled()' | |
run: | | |
:> .util/pylint_scores.txt | |
# Run Pylint and Get output in file | |
- name: Run Pylint | |
if: '!cancelled()' | |
run: | | |
find . \( -name '*.py' ! -name 'test*.py' \) \ | |
-exec pylint {} \; >> .util/pylint_scores.txt | |
# Convert Pylint scores to JSON | |
- name: Convert Pylint scores to JSON | |
if: '!cancelled()' | |
run: python .util/parse_raw_python.py --input .util/pylint_scores.txt --output .util/pylint_scores.json --type pylint | |
# Convert Pytest scores to JSON | |
- name: Convert Pytest scores to JSON | |
if: '!cancelled()' | |
run: python .util/parse_raw_python.py --input .util/pytest_scores.txt --output .util/pytest_scores.json --type pytest | |
# Get the passed_percentage from pytest_scores.json | |
- name: Obtain passed_percentage from JSON | |
if: '!cancelled()' | |
run: | | |
echo "PASSED_PERCENTAGE=$(jq '.passed_percentage' .util/pytest_scores.json)" >> $GITHUB_ENV | |
env: | |
CODE_QUALITY: ${{ env.PASSED_PERCENTAGE }} | |
BADGE_PATH: .github/badges/passed_percentage.svg | |
# Get the number_of_tests from pytest_scores.json | |
- name: Obtain total_tests from JSON | |
if: '!cancelled()' | |
run: | | |
echo "TOTAL_TESTS=$(jq '.total' .util/pytest_scores.json)" >> $GITHUB_ENV | |
env: | |
CODE_QUALITY: ${{ env.TOTAL_TESTS }} | |
BADGE_PATH: .github/badges/number_of_tests.svg | |
# Get the passing_tests from pytest_scores.json | |
- name: Obtain passing_tests from JSON | |
if: '!cancelled()' | |
run: | | |
echo "PASSING_TESTS=$(jq '.passed' .util/pytest_scores.json)" >> $GITHUB_ENV | |
env: | |
CODE_QUALITY: ${{ env.PASSING_TESTS }} | |
BADGE_PATH: .github/badges/number_of_tests.svg | |
# Get the avg_score from pylint_scores.json | |
- name: Obtain avg_score from JSON | |
if: '!cancelled()' | |
run: | | |
echo "AVG_SCORE=$(jq '.avg_score' .util/pylint_scores.json)" >> $GITHUB_ENV | |
env: | |
CODE_QUALITY: ${{ env.AVG_SCORE }} | |
BADGE_PATH: .github/badges/avg_score.svg | |
- name: Fail pylint if score below threshold | |
if: '!cancelled()' | |
run: | | |
result=$(echo "$AVG_SCORE < 9.0" | bc -l) | |
if [ "$result" -eq 1 ]; then | |
echo "[FAILED] Code quality score: $AVG_SCORE." | |
exit 1 | |
fi | |
echo "[PASS] Code quality score: $AVG_SCORE." | |
exit 0 | |
# Generate the badge for passed_percentage | |
- name: Generate the badge SVG image for passed_percentage | |
if: '!cancelled()' | |
uses: emibcn/badge-action@v1 | |
id: passed_percentage_badge | |
with: | |
label: 'Passing Tests: ' | |
status: ${{ format('{0}%', env.PASSED_PERCENTAGE) }} | |
color: 'blue' | |
path: .github/badges/passed_percentage.svg | |
scale: 1.5 | |
- name: Upload badge as artefact | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: badge | |
path: .github/badges/passed_percentage.svg | |
if-no-files-found: ignore | |
# Generate the badge for number_of_tests | |
- name: Generate the badge SVG image for number_of_tests | |
if: '!cancelled()' | |
uses: emibcn/badge-action@v1 | |
id: number_of_tests_badge | |
with: | |
label: 'Passing/Total Tests: ' | |
status: ${{ format('{0}/{1}', env.PASSING_TESTS , env.TOTAL_TESTS) }} | |
color: 'blue' | |
path: .github/badges/number_of_tests.svg | |
scale: 1.5 | |
- name: Upload badge as artefact | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: badge | |
path: .github/badges/number_of_tests.svg | |
if-no-files-found: ignore | |
# Generate the badge for avg_score | |
- name: Generate the badge SVG image for avg_score | |
if: '!cancelled()' | |
uses: emibcn/badge-action@v1 | |
id: avg_score_badge | |
with: | |
label: 'Pylint Score: ' | |
status: ${{ format('{0}/10', env.AVG_SCORE) }} | |
color: 'blue' | |
path: .github/badges/avg_score.svg | |
scale: 1.5 | |
- name: Upload badge as artefact | |
if: '!cancelled()' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: badge | |
path: .github/badges/avg_score.svg | |
if-no-files-found: ignore | |
# Commit results | |
- name: Push results | |
if: '!cancelled()' | |
run: | | |
git config --local user.email "${{ secrets.WORKFLOW_EMAIL }}" | |
git config --local user.name "Testing bot" | |
git add .util/pytest_scores.txt | |
git add .util/pytest_scores.json | |
git add .util/pylint_scores.txt | |
git add .util/pylint_scores.json | |
git add .github/badges/passed_percentage.svg | |
git add .github/badges/avg_score.svg | |
git add .github/badges/number_of_tests.svg | |
git commit -m "Update scores" || true | |
echo "Event Type: ${{ github.event_name }}" | |
if [[ "${{ github.event_name }}" == "push" ]]; then | |
echo "Pushing" | |
git push | |
else | |
echo "No Push" | |
fi |