Skip to content

Commit

Permalink
Merge branch 'main' into doc/known-issues-design
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti authored Jan 7, 2025
2 parents 137b20d + 30274eb commit ffa435f
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 184 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ jobs:
uses: actions/[email protected]
with:
name: lint-python${{ matrix.python-version }}
path: .lint.txt
path: |
.lint.txt
.lint.json
include-hidden-files: true

Type-Check:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
working-directory: ./artifacts
run: |
poetry run coverage combine --keep coverage-python3.9*/.coverage
# Errors during copying are ignored because they are checked in the next step
cp .coverage ../ || true
cp lint-python3.9/.lint.txt ../ || true
cp lint-python3.9/.lint.json ../ || true
cp security-python3.9/.security.json ../ || true
- name: Validate Artifacts
Expand All @@ -53,6 +55,5 @@ jobs:
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY
cat .lint.txt >> $GITHUB_STEP_SUMMARY
poetry run tbx lint pretty-print >> $GITHUB_STEP_SUMMARY
poetry run tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY
4 changes: 4 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

## ✨ Added

* added tbx task for markdown formating of .lint.json

## 🐞 Fixed
* Fixed an issue in the CI workflow that caused it to be executed twice on the initial push of a PR if the PR branch was on the repo itself.

Expand Down
2 changes: 2 additions & 0 deletions exasol/toolbox/nox/_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def check_artifacts(session: Session) -> None:
error = False
if msg := _validate_lint_txt(Path(PROJECT_CONFIG.root, ".lint.txt")):
print(f"error in [.lint.txt]: {msg}")
if msg := _validate_lint_json(Path(PROJECT_CONFIG.root, ".lint.json")):
print(f"error in [.lint.json]: {msg}")
if msg := _validate_security_json(Path(PROJECT_CONFIG.root, ".security.json")):
print(f"error in [.security.json]: {msg}")
error = True
Expand Down
4 changes: 3 additions & 1 deletion exasol/toolbox/templates/github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ jobs:
uses: actions/[email protected]
with:
name: lint-python${{ matrix.python-version }}
path: .lint.txt
path: |
.lint.txt
.lint.json
include-hidden-files: true

Type-Check:
Expand Down
14 changes: 9 additions & 5 deletions exasol/toolbox/templates/github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ jobs:
working-directory: ./artifacts
run: |
poetry run coverage combine --keep coverage-python3.9*/.coverage
cp .coverage ../
cp lint-python3.9/.lint.txt ../
cp security-python3.9/.security.json ../
# Errors during copying are ignored because they are checked in the next step
cp .coverage ../ || true
cp lint-python3.9/.lint.txt ../ || true
cp lint-python3.9/.lint.txt ../ || true
cp security-python3.9/.security.json ../ || true
- name: Validate Artifacts
run: poetry run nox -s artifacts:validate

- name: Generate Report
run: poetry run nox -s project:report -- -- --format json | tee metrics.json
Expand All @@ -50,6 +55,5 @@ jobs:
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY
cat .lint.txt >> $GITHUB_STEP_SUMMARY
poetry run tbx security pretty-print >> $GITHUB_STEP_SUMMARY
poetry run tbx security pretty-print .security.json >> $GITHUB_STEP_SUMMARY
80 changes: 80 additions & 0 deletions exasol/toolbox/tools/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json
from collections.abc import Iterable
from dataclasses import dataclass
from inspect import cleandoc
from pathlib import Path

import typer

CLI = typer.Typer()


@dataclass(frozen=True)
class Finding:
type: str
module: str
obj: str
line: int
column: int
endLine: int
endColumn: int
path: str
symbol: str
message: str
message_id: str


def lint_issue_from_json(data: str) -> Iterable[Finding]:
issues = json.loads(data)
for issue in issues:
yield Finding(
type=issue["type"],
module=issue["module"],
obj=issue["obj"],
line=issue["line"],
column=issue["column"],
endLine=issue["endLine"],
endColumn=issue["endColumn"],
path=issue["path"],
symbol=issue["symbol"],
message=issue["message"],
message_id=issue["message-id"],
)


def lint_issue_to_markdown(lint_issues: Iterable[Finding]) -> str:
def _header() -> str:
header = "# Static Code Analysis\n\n"
header += "|File|line/<br>column|id|message|\n"
header += "|---|:-:|:-:|---|\n"
return header

def _rows(findings: Iterable[Finding]) -> str:
rows = ""
for finding in findings:
rows += f"|{finding.path}"
rows += f"|line: {finding.line}/<br>column: {finding.column}"
rows += f"|{finding.message_id}"
rows += f"|{finding.message}|\n"
return rows

template = cleandoc(
"""
{header}{rows}
"""
)
lint_issues = sorted(lint_issues, key=lambda i: (i.path, i.message_id, i.line))
return template.format(header=_header(), rows=_rows(lint_issues))


@CLI.command(name="pretty-print")
def lint_json_to_markdown(
path: Path = typer.Argument(default=Path(".lint.json"), help="path to lint.json"),
) -> None:
"""converts the lint json to a Markdown table"""
issues = lint_issue_from_json(path.read_text())
print(lint_issue_to_markdown(issues))


if __name__ == "__main__":
CLI()
2 changes: 2 additions & 0 deletions exasol/toolbox/tools/tbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from exasol.toolbox.tools import (
issue,
lint,
security,
workflow,
)
Expand All @@ -10,6 +11,7 @@
CLI.add_typer(workflow.CLI, name="workflow", help="Manage github workflows")
CLI.add_typer(security.CLI, name="security", help="Security related helpers")
CLI.add_typer(issue.CLI, name="issue", help="Manage issue templates")
CLI.add_typer(lint.CLI, name="lint", help="linting related helpers")

if __name__ == "__main__":
CLI()
Loading

0 comments on commit ffa435f

Please sign in to comment.