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

Rewrite ecosystem checks and add ruff format reports #8223

Merged
merged 76 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
4b79f57
Refactor ecosystem checks into module
zanieb Oct 17, 2023
ab49eaa
Add formatter ecosystem checks
zanieb Oct 24, 2023
92f935e
Update formatter if
zanieb Oct 25, 2023
d6aa117
Lint
zanieb Oct 25, 2023
ff3dc64
Check against v0.0.292 for debugging
zanieb Oct 25, 2023
071c54e
Add unidiff dep
zanieb Oct 25, 2023
f72c37f
Write results separately then combine
zanieb Oct 25, 2023
246830c
Skip tests for now
zanieb Oct 25, 2023
4288d8a
Skip fuzz and bench as well
zanieb Oct 25, 2023
fc6a3c1
Skip more CI checks to speed things up
zanieb Oct 25, 2023
cbc24a3
Use `<pre>` for check output
zanieb Oct 25, 2023
368cb3e
Add max lines per project to `ruff check`
zanieb Oct 25, 2023
8950145
Remove file links (only do line links)
zanieb Oct 25, 2023
f779069
Tweak pull request comment
zanieb Oct 25, 2023
28bfab5
Fix titles
zanieb Oct 25, 2023
3fd64da
Fix file paths
zanieb Oct 25, 2023
c437a89
Fix paths
zanieb Oct 25, 2023
8a48dfe
Continue the battle for if-comment
zanieb Oct 25, 2023
b049c86
Revert all changes to `pr-comment`
zanieb Oct 25, 2023
c547ec1
Combine reports into a single artifact again
zanieb Oct 25, 2023
d6e35f7
Move rule change table into details block
zanieb Oct 25, 2023
9c63d80
Change table title
zanieb Oct 25, 2023
8898906
Update options display
zanieb Oct 25, 2023
11e9965
Fix formatting of command
zanieb Oct 25, 2023
c2cae71
Improve rule table title
zanieb Oct 25, 2023
db5dfd4
Loosen linked ranges for format diffs since they are not correct
zanieb Oct 26, 2023
1f4e87f
Use `set` instead of `sorted` in `RuleChanges.from_diff`
zanieb Oct 26, 2023
1c820b0
Clean up Python implementation; enable all projects
zanieb Oct 26, 2023
c806b4a
Sort imports
zanieb Oct 26, 2023
6025081
Add messy fixable detection to reduce rule changes
zanieb Oct 27, 2023
333aedc
Refactor fixable detection
zanieb Oct 26, 2023
5a055aa
Fix titles
zanieb Oct 26, 2023
88e3663
Fix affected rules total
zanieb Oct 26, 2023
25bda80
Improve limits per rule code
zanieb Oct 26, 2023
250b226
Restore changelog
zanieb Oct 26, 2023
89f9803
Restructuring parsing
zanieb Oct 26, 2023
d4e9418
Fix calculation to ignore fixes
zanieb Oct 26, 2023
1f6b28c
Fix table
zanieb Oct 26, 2023
ce29007
Restore display of fixes
zanieb Oct 26, 2023
615e569
Fix added / removed counts for `format`
zanieb Oct 26, 2023
2e36781
Add more truncation?
zanieb Oct 26, 2023
9a8bd09
Fix table
zanieb Oct 26, 2023
9cdf864
Enable all projects again
zanieb Oct 26, 2023
85de1e9
Add completed project count to summary title
zanieb Oct 26, 2023
e0def9e
Truncate more aggressively
zanieb Oct 26, 2023
1bbe88f
Fix project truncation
zanieb Oct 26, 2023
2270485
Display errors in code fences
zanieb Oct 26, 2023
06f71f5
Remove comma for consistency
zanieb Oct 26, 2023
087d9c7
Test adding color to diff; fix newline in error report
zanieb Oct 26, 2023
823ec4c
Strip all newlines from error reports
zanieb Oct 26, 2023
6f593ca
in files -> across files
zanieb Oct 26, 2023
a1bec32
Fix error rendering
zanieb Oct 26, 2023
3936bc1
Drop coloring
zanieb Oct 26, 2023
7dc97fd
Improve readme description.
zanieb Oct 27, 2023
d512784
Undo changes to CI
zanieb Oct 27, 2023
63f1122
Run CI workflow when its changed
zanieb Oct 27, 2023
54bc493
Add deprecation message to old ecosystem script
zanieb Oct 27, 2023
23050b3
Guard against dataclass types in jsonable implementation
zanieb Oct 27, 2023
e304d46
Add mutability note for `RuleChanges`
zanieb Oct 27, 2023
8441db6
Fix `total_changes_by_rule` type annotation
zanieb Oct 27, 2023
c4bddb8
Use `cls` in `DiagnosticLine.try_from_string`
zanieb Oct 27, 2023
2a14b94
Explicitly cast checkout directory to string
zanieb Oct 27, 2023
a16c04c
Fix `limited_parallelism` type annotation
zanieb Oct 27, 2023
05ab316
Rename `cache` variable; update `clone` type
zanieb Oct 27, 2023
5f28912
Remove format ignore lines re
zanieb Oct 27, 2023
39c04c8
Fix spacing in examples
zanieb Oct 27, 2023
eb769ac
Improve handling of ruff executable lookup
zanieb Oct 27, 2023
b6066c6
Fix missing newline
zanieb Oct 27, 2023
c3354ad
Lint
zanieb Oct 27, 2023
1337c4a
Add docstrings for formatting
zanieb Oct 27, 2023
0c1a7ff
Fix chmod
zanieb Oct 27, 2023
ee1883a
Fix missing space
zanieb Oct 27, 2023
7d4b59d
Merge branch 'main' into zanie/ecosystem-format
zanieb Oct 27, 2023
7d51226
Show a different summary if there are only errors
zanieb Oct 27, 2023
16e511a
Use `FormatOptions`; exclude file from `demisto/content` with syntax …
zanieb Oct 27, 2023
88bf2ac
Lint
zanieb Oct 27, 2023
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
37 changes: 30 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- "!crates/ruff_dev/**"
- "!crates/ruff_shrinking/**"
- scripts/*
- .github/workflows/ci.yaml

formatter:
- Cargo.toml
Expand All @@ -57,6 +58,7 @@ jobs:
- crates/ruff_python_parser/**
- crates/ruff_dev/**
- scripts/*
- .github/workflows/ci.yaml

cargo-fmt:
name: "cargo fmt"
Expand Down Expand Up @@ -182,35 +184,56 @@ jobs:
- cargo-test-linux
- determine_changes
# Only runs on pull requests, since that is the only we way we can find the base version for comparison.
if: github.event_name == 'pull_request' && needs.determine_changes.outputs.linter == 'true'
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- uses: actions/download-artifact@v3
name: Download Ruff binary
name: Download comparison Ruff binary
id: ruff-target
with:
name: ruff
path: target/debug

- uses: dawidd6/action-download-artifact@v2
name: Download base results
name: Download baseline Ruff binary
with:
name: ruff
branch: ${{ github.event.pull_request.base.ref }}
check_artifacts: true

- name: Run ecosystem check
- name: Install ruff-ecosystem
run: |
pip install ./python/ruff-ecosystem

- name: Run `ruff check` ecosystem check
if: ${{ needs.determine_changes.outputs.linter == 'true' }}
run: |
# Make executable, since artifact download doesn't preserve this
chmod +x ruff ${{ steps.ruff-target.outputs.download-path }}/ruff
chmod +x ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff

ruff-ecosystem check ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown | tee ecosystem-result-check

scripts/check_ecosystem.py ruff ${{ steps.ruff-target.outputs.download-path }}/ruff | tee ecosystem-result
cat ecosystem-result > $GITHUB_STEP_SUMMARY
cat ecosystem-result-check > $GITHUB_STEP_SUMMARY
cat ecosystem-result-check > ecosystem-result
echo "" >> ecosystem-result

- name: Run `ruff format` ecosystem check
if: ${{ needs.determine_changes.outputs.formatter == 'true' }}
run: |
# Make executable, since artifact download doesn't preserve this
chmod +x ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff

ruff-ecosystem format ./ruff ${{ steps.ruff-target.outputs.download-path }}/ruff --cache ./checkouts --output-format markdown | tee ecosystem-result-format

cat ecosystem-result-format > $GITHUB_STEP_SUMMARY
cat ecosystem-result-format >> ecosystem-result

- name: Export pull request number
run: |
echo ${{ github.event.number }} > pr-number

- uses: actions/upload-artifact@v3
Expand Down
46 changes: 46 additions & 0 deletions python/ruff-ecosystem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ruff-ecosystem

Compare lint and format results for two different ruff versions (e.g. main and a PR) on real world projects.

## Installation

From the Ruff project root, install with `pip`:

```shell
pip install -e ./python/ruff-ecosystem
```

## Usage

```shell
ruff-ecosystem <check | format> <baseline executable> <comparison executable>
```

Note executable paths may be absolute, relative to the current working directory, or will be looked up in the
current Python environment and PATH.

Run `ruff check` ecosystem checks comparing your debug build to your system Ruff:

```shell
ruff-ecosystem check ruff "./target/debug/ruff"
```

Run `ruff format` ecosystem checks comparing your debug build to your system Ruff:

```shell
ruff-ecosystem format ruff "./target/debug/ruff"
```

## Development

When developing, it can be useful to set the `--pdb` flag to drop into a debugger on failure:

```shell
ruff-ecosystem check ruff "./target/debug/ruff" --pdb
```

You can also provide a path to cache checkouts to speed up repeated runs:

```shell
ruff-ecosystem check ruff "./target/debug/ruff" --cache ./repos
```
15 changes: 15 additions & 0 deletions python/ruff-ecosystem/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ruff-ecosystem"
version = "0.0.0"
dependencies = ["unidiff==0.7.5"]

[project.scripts]
ruff-ecosystem = "ruff_ecosystem.cli:entrypoint"

[tool.ruff]
extend-select = ["I"]
preview = true
3 changes: 3 additions & 0 deletions python/ruff-ecosystem/ruff_ecosystem/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import logging

logger = logging.getLogger("ruff-ecosystem")
8 changes: 8 additions & 0 deletions python/ruff-ecosystem/ruff_ecosystem/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Enables usage with `python -m ruff_ecosystem`
"""

import ruff_ecosystem.cli

if __name__ == "__main__":
ruff_ecosystem.cli.entrypoint()
Loading