Skip to content

Commit

Permalink
docs(poetry-ruff): add documentation for Ruff workflow
Browse files Browse the repository at this point in the history
Closes: #69
  • Loading branch information
koeaw committed Aug 12, 2024
1 parent 9566f50 commit 32dfbb5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ various repositories of the Prosopograhy and Networks group at the
* poetry-deptry.yml

* poetry-djlint.yml

* poetry-ruff.yml
* [poetry-ruff](docs/poetry-ruff.md)
63 changes: 63 additions & 0 deletions docs/poetry-ruff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Documentation for `poetry-ruff.yml` workflow

[poetry-ruff.yml](../.github/workflows/poetry-ruff.yml) is a reusable GitHub workflow for the [Ruff](https://docs.astral.sh/ruff/) linter and code formatter for Python.


## How to use

The Ruff workflow can be used for either [linting](https://docs.astral.sh/ruff/linter/) or [formatting](https://docs.astral.sh/ruff/formatter/) – or both.

If you need only one of these, create one new workflow file in all repositories whose files should get inspected by Ruff. If you need both, create two separate new workflow files.

Ruff differentiates between formatting and linting based on arguments with which it is called. When not configured otherwise, the parent Prosnet workflow defaults to _linting_.


The following example config runs the [Ruff linter](https://docs.astral.sh/ruff/formatter/) on all pull requests:

```yml
name: Run Ruff linter

on: pull_request

jobs:
ruff-linter:
uses: acdh-oeaw/prosnet-workflows/.github/workflows/poetry-ruff.yml@RELEASE_VERSION
with:
src: "."
```
This second examples runs the [Ruff formatter](https://docs.astral.sh/ruff/formatter/) on all PRs:
```yml
name: Run Ruff formatter

on: pull_request

jobs:
ruff-formatter:
uses: acdh-oeaw/prosnet-workflows/.github/workflows/poetry-ruff.yml@RELEASE_VERSION
with:
src: "."
options: "format --check"
```
### Required settings
* `RELEASE_VERSION` needs to be set to a valid prosnet-workflows [release tag](https://github.com/acdh-oeaw/prosnet-workflows/releases), branch name or SHA.
* `src` refers to the path from which Ruff will work its way down the hierarchical file structure. The example uses `"."`, the current working directory, which may serve you best. Only change it if you need Ruff to start from a different directory instead.


### Optional settings

The following optional variables can be added to the `with` section of the config:

* `options`: Arguments with which to run `poetry run ruff`. Default is `check`, which runs Ruff as linter. Set this explicitly to override the default, e.g. use `format` to run Ruff as code formatter. See the Ruff [linter](https://docs.astral.sh/ruff/linter/) and [formatter](https://docs.astral.sh/ruff/formatter/) docs for details on more fine-grained settings.
* `python-version`: The Python version for which to set up Poetry, which is used to run Ruff. For APIS projects, the prosnet-workflows default should work best.


**Other configurations**

The `name` of your workflow can be whatever makes sense to you. It's how the workflow will show up in the "Actions" tab.

If you use two Ruff workflows in the same repository, take care to name them differently to make it easier to differentiate workflow runs. The same applies to the `jobs` section in the config as well as the file names themselves.

0 comments on commit 32dfbb5

Please sign in to comment.