Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruff workflow #2660

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
branches:
- "*"

pull_request_target:
branches:
- master

jobs:
black:
runs-on: ubuntu-latest
Expand All @@ -29,3 +33,85 @@ jobs:

- name: Run Black
run: black --check tardis
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Download Lock File
run: wget -q https://raw.githubusercontent.com/tardis-sn/tardis/master/conda-linux-64.lock

- name: Generate Cache Key
run: |
file_hash=$(cat conda-linux-64.lock | shasum -a 256 | cut -d' ' -f1)
echo "file_hash=$file_hash" >> "${GITHUB_OUTPUT}"
id: cache-environment-key

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: conda-linux-64.lock
cache-environment-key: ${{ steps.cache-environment-key.outputs.file_hash }}
cache-downloads-key: ${{ steps.cache-environment-key.outputs.file_hash }}
environment-name: tardis
cache-environment: true
cache-downloads: true

- name: Show statistics
run: ruff check --statistics --show-fixes . | tee ruff_stats.txt
id: ruff_stats

- name: Show entire output
run: ruff check . --output-format=full | tee ruff_full.txt
id: ruff_complete

- name: Find Comment
if: always() && github.event_name == 'pull_request_target'
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.number }}
body-includes: I ran ruff on the latest commit

- name: Post comment
if: github.event_name == 'pull_request_target'
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.BOT_TOKEN }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
*\*beep\* \*bop\**
Hi human,
I ran ruff on the latest commit (${{ github.event.pull_request.head.sha }}).
Here are the outputs produced.
Results can also be downloaded as artifacts [**here**](${{ env.URL }}).
Summarised output:
<details>

```diff
${{ steps.ruff_stats.outputs.content }}
```

</details>

Complete output(might be large):
<details>

```diff
${{ steps.ruff_complete.outputs.content }}
```

</details>
env:
URL: https://github.com/${{ github.repository_owner }}/${{ github.event.repository.name }}/actions/runs/${{ github.run_id }}?check_suite_focus=true

- name: Save results artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: ruff-results
path: |
ruff_full.txt
ruff_stats.txt

Loading