Skip to content

Commit

Permalink
Merge branch 'implement-ruff-as-check' of https://github.com/ministry…
Browse files Browse the repository at this point in the history
…ofjustice/hmpps-ldap-automation-cli into implement-ruff-as-check
  • Loading branch information
georgepstaylor committed Sep 18, 2024
2 parents ce1b528 + 0d2f99a commit efbebbf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/format-python.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Ensure formatted code
on:
pull_request:
types: [ opened, edited, reopened, synchronize, ready_for_review ]
types: [ opened, reopened, synchronize, ready_for_review ]
workflow_dispatch:

permissions:
Expand All @@ -27,11 +27,14 @@ jobs:
gh pr comment ${{ github.event.pull_request.number }} --body "All Python code is properly formatted."
else
echo "$output"
echo "Errors:" > output.txt
echo "<details><summary>:rotating_light: Python code is not properly formatted. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "Some Python code is not properly formatted." >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff format` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
Expand All @@ -47,18 +50,21 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: |
set +e
output=$(ruff format --check)
output=$(ruff check)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "All Python code is properly formatted."
gh pr comment ${{ github.event.pull_request.number }} --body "All Python code is properly formatted."
else
echo "$output"
echo "Errors:" > output.txt
echo "<details><summary>:rotating_light: Linting errors found in Python code. Click to expand.</summary>" > output.txt
echo "" >> output.txt
echo '```' >> output.txt
echo "$output" >> output.txt
echo '```' >> output.txt
echo "Linting errors found in Python code." >> output.txt
echo "" >> output.txt
echo '</details>' >> output.txt
echo "" >> output.txt
echo 'Please run `ruff check --fix` to format the code.' >> output.txt
gh pr comment ${{ github.event.pull_request.number }} --body-file output.txt
exit 1
Expand Down

0 comments on commit efbebbf

Please sign in to comment.