Skip to content

Commit

Permalink
feat: add Composite Action (#45)
Browse files Browse the repository at this point in the history
* feat: add Composite Action

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

style: pre-commit fixes

style: pre-commit fixes

* feat: split output

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored Jun 7, 2023
1 parent 0a0053e commit d1fc1cd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ jobs:
- uses: actions/checkout@v3

- uses: hynek/build-and-inspect-python-package@v1

action:
name: Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run repo-review action
uses: ./
with:
plugins: sp-repo-review==2023.06.01
46 changes: 46 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: repo-review
description: "Runs repo-review"
branding:
icon: package
color: blue
inputs:
plugins:
description: "Plugins to install, exactly as would be passed to pip install"
required: true
package-dir:
description: 'Input directory, defaults to "."'
required: false
default: ""
select:
description: "Checks to select, overrides pyproject.toml"
required: false
default: ""
ignore:
description: "Checks to ignore, overrides pyproject.toml"
required: false
default: ""

runs:
using: composite
steps:
- uses: actions/setup-python@v4
id: python
with:
python-version: "3.11"
update-environment: false

- name: Install repo-review and plugins
shell: bash
run: |
pipx install --python '${{ steps.python.outputs.python-path }}' '${{ github.action_path }}[cli]'
pipx inject repo-review ${{ inputs.plugins }}
- name: Run repo-review
shell: bash
run: >
repo-review .
--format split
--select "${{ inputs.select }}"
--ignore "${{ inputs.ignore }}"
--package-dir "${{ inputs.package-dir }}"
>> $GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,4 @@ flake8-unused-arguments.ignore-variadic-names = true

[tool.ruff.per-file-ignores]
"src/repo_review/_compat/**.py" = ["TID251"]
"src/**/__main__.py" = ["T20"]
25 changes: 17 additions & 8 deletions src/repo_review/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import itertools
import json
import sys
import typing
from collections.abc import Mapping
from pathlib import Path
Expand Down Expand Up @@ -33,9 +34,13 @@


def rich_printer(
families: Mapping[str, Family], processed: list[Result], *, output: Path | None
families: Mapping[str, Family],
processed: list[Result],
*,
output: Path | None = None,
stderr: bool = False,
) -> None:
console = rich.console.Console(record=True)
console = rich.console.Console(record=True, stderr=stderr)

for family, results_list in itertools.groupby(processed, lambda r: r.family):
family_name = families[family].get("name", family)
Expand Down Expand Up @@ -87,9 +92,9 @@ def rich_printer(
@click.option(
"--format",
"format_opt",
type=click.Choice(["rich", "json", "html"]),
type=click.Choice(["rich", "json", "html", "split"]),
default="rich",
help="Select output format.",
help="Select output format. 'split' produces html on stdout (or to a file), and rich on stderr.",
)
@click.option(
"--select",
Expand All @@ -116,7 +121,7 @@ def rich_printer(
def main(
package: Traversable,
output: Path | None,
format_opt: Literal["rich", "json", "html"],
format_opt: Literal["rich", "json", "html", "split"],
select: str,
ignore: str,
package_dir: str,
Expand Down Expand Up @@ -156,20 +161,24 @@ def main(
rich_printer(families, processed, output=output)
if len(processed) == 0:
rich.print("[bold red]No checks ran[/bold red]")
elif format_opt == "json":
if format_opt == "split":
rich_printer(families, processed, stderr=True)
if len(processed) == 0:
rich.print("[bold red]No checks ran[/bold red]", file=sys.stderr)
if format_opt == "json":
j = json.dumps(
{"families": families, "checks": as_simple_dict(processed)}, indent=2
)
if output:
output.write_text(j)
else:
rich.print_json(j)
elif format_opt == "html":
if format_opt in {"html", "split"}:
html = to_html(families, processed)
if output:
output.write_text(html)
else:
rich.print(html)
print(html)

if any(p.result is False for p in processed):
raise SystemExit(2)
Expand Down

0 comments on commit d1fc1cd

Please sign in to comment.