Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- New `output-file` input parameter to write isort output to a file instead of stdout
- Useful for keeping GitHub Actions logs clean when using `--diff` or `--check-only`
- Output file is written relative to repository root
- File can be uploaded as an artifact for later analysis

## [1.1.1] - 2024-10-14

### Added
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ Optional. Paths to python requirements files to install before running isort.
If multiple requirements files are provided, they should be separated by a space.
If custom package installation is required, dependencies should be installed in a separate step before using this action.

### `output-file`

Optional. Path to write isort output to a file instead of stdout.
Useful for keeping GitHub Actions logs clean when using `--diff` or `--check-only`.
The output file is written relative to the repository root.
If specified, the isort output will be saved to this file without appearing in the job log.

## Outputs

### `isort-result`
Expand All @@ -32,6 +39,8 @@ Output of the `isort` CLI.

## Example usage

### Basic usage

```yaml
name: Run isort
on:
Expand All @@ -47,6 +56,28 @@ jobs:
requirements-files: "requirements.txt requirements-test.txt"
```

### With output file (to keep logs clean)

```yaml
name: Run isort with file output
on:
- push

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: isort/isort-action@v1
with:
output-file: "isort-output.txt"
- uses: actions/upload-artifact@v4
if: always()
with:
name: isort-output
path: isort-output.txt
```

## Developing

Before starting on a new feature, please review the [contributing guide][contributors-guide].
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ inputs:
required: false
default: ""

output-file:
description: >
Optional path to write isort output to a file instead of stdout.
Useful for keeping logs clean when using --diff or --check-only.
required: false
default: ""

outputs:
isort-result:
description: isort result
Expand All @@ -88,5 +95,7 @@ runs:
${{ inputs.configuration }}
${{ inputs.sort-paths || inputs.sortPaths }}
shell: bash
env:
OUTPUT_FILE: ${{ inputs.output-file }}
- run: echo "::remove-matcher owner=isort-matcher::"
shell: bash
6 changes: 6 additions & 0 deletions bin/run_isort
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ echo "Running isort $*"
isort_result=$(isort "$@" 2>&1)
exit_code=$?

# If OUTPUT_FILE is specified, write isort output to that file
if [ -n "${OUTPUT_FILE}" ]; then
echo "${isort_result}" > "${OUTPUT_FILE}"
echo "isort output written to ${OUTPUT_FILE}"
fi

# The isort output can be a multiline string. By default, GITHUB_OUTPUT expects
# output to be on a single line, so a (random) delimiter needs to be used
# so that the output is parsed properly.
Expand Down