| 1 |
# Github action |
| 2 |
|
| 3 |
isort provides an official [Github Action][github-action-docs] that can be used as part of a CI/CD workflow to ensure a project's imports are properly sorted. |
| 4 |
The action can be found on the [Github Actions Marketplace][python-isort]. |
| 5 |
|
| 6 |
## Usage |
| 7 |
|
| 8 |
The `python-isort` plugin is designed to be run in combination with the [`checkout`][checkout-action] and [`setup-python`][setup-python] actions. |
| 9 |
By default, it will run recursively from the root of the repository being linted and will exit with an error if the code is not properly sorted. |
| 10 |
|
| 11 |
### Inputs |
| 12 |
|
| 13 |
#### `isort-version` |
| 14 |
|
| 15 |
Optional. Version of `isort` to use. Defaults to latest version of `isort`. |
| 16 |
|
| 17 |
#### `sort-paths` |
| 18 |
|
| 19 |
Optional. List of paths to sort, relative to your project root. Defaults to `.` |
| 20 |
|
| 21 |
#### `configuration` |
| 22 |
|
| 23 |
Optional. `isort` configuration options to pass to the `isort` CLI. Defaults to `--check-only --diff`. |
| 24 |
|
| 25 |
#### `requirements-files` |
| 26 |
|
| 27 |
Optional. Paths to python requirements files to install before running isort. |
| 28 |
If multiple requirements files are provided, they should be separated by a space. |
| 29 |
If custom package installation is required, dependencies should be installed in a separate step before using this action. |
| 30 |
|
| 31 |
!!! tip |
| 32 |
It is important that the project's dependencies be installed before running isort so that third-party libraries are properly sorted. |
| 33 |
|
| 34 |
### Outputs |
| 35 |
|
| 36 |
#### `isort-result` |
| 37 |
|
| 38 |
Output of the `isort` CLI. |
| 39 |
|
| 40 |
### Example usage |
| 41 |
|
| 42 |
```yaml |
| 43 |
name: Run isort |
| 44 |
on: |
| 45 |
- push |
| 46 |
|
| 47 |
jobs: |
| 48 |
build: |
| 49 |
runs-on: ubuntu-latest |
| 50 |
steps: |
| 51 |
- uses: actions/checkout@v4 |
| 52 |
- uses: actions/setup-python@v5 |
| 53 |
with: |
| 54 |
python-version: 3.13 |
| 55 |
- uses: isort/isort-action@v1 |
| 56 |
with: |
| 57 |
requirementsFiles: "requirements.txt requirements-test.txt" |
| 58 |
``` |
| 59 |
|
| 60 |
[github-action-docs]: https://docs.github.com/en/free-pro-team@latest/actions |
| 61 |
[python-isort]: https://github.com/marketplace/actions/python-isort |
| 62 |
[checkout-action]: https://github.com/actions/checkout |
| 63 |
[setup-python]: https://github.com/actions/setup-python |