diff --git a/.github/workflows/pyruff.yml b/.github/workflows/pyruff.yml new file mode 100644 index 0000000..60e3137 --- /dev/null +++ b/.github/workflows/pyruff.yml @@ -0,0 +1,64 @@ +name: Python Lint with Ruff + +on: + workflow_dispatch: + pull_request: + branches: + - main + - develop + paths: + - 'src/**' + - 'tests/**' + - 'pyproject.toml' + - 'ruff.toml' + - 'requirements.txt' + - 'requirements-dev.txt' + +jobs: + python-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.12" + + - name: Install dependencies + id: installDependencies + run: | + pip install -r requirements.txt + pip install -r requirements-dev.txt + + + # - name: Run Ruff Lint + # id: runRuffLint + # run: | + + + - name: pull_request message with Ruff Lint results + id: prMessageRuffLint + run: | + curl -X POST \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -d "{\"body\": \"## :mag: Ruff Lint Results\n\`\`\`\ntest\n\`\`\`\"}" \ + ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/issues/${{ github.event.pull_request.number }}/comments + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + + + + # github + # - name: pull_request message with Ruff Lint results + # id: prMessageRuffLint + # uses: marocchino/sticky-pull-request-comment@v2 + # with: + # header: "## :mag: Ruff Lint Results" + # message: | + # ``` + # test + # ``` + diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e19a401..b4454e3 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -2,10 +2,10 @@ name: Python Test on: workflow_dispatch: - push: + pull_request: branches: - main - # - develop + - develop paths: - 'src/**' - 'tests/**' diff --git a/.gitignore b/.gitignore index c324259..1dddfae 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ __pycache__/ *.py[cod] *$py.class - +ruff-report.* # C extensions *.so diff --git a/examples/example.py b/examples/example.py index 0976ae4..029edea 100644 --- a/examples/example.py +++ b/examples/example.py @@ -11,7 +11,7 @@ logger = get_logger(__name__) def example(): logger.info("Application started") - print("Hello, World!") + print("Hello, World!") example() diff --git a/readme/python_init.md b/readme/python_init.md index 243aa6b..2a4d137 100644 --- a/readme/python_init.md +++ b/readme/python_init.md @@ -26,6 +26,7 @@ uv init # uv init -p 3.10とすると">=3.10,<3.11"となる ``` +同期する場合 ```sh uv sync @@ -52,3 +53,27 @@ line-length = 88 | E | E303 | 空行が多すぎる | | | E501 | 行が長すぎる | + +リンターを実行する場合 + +```sh +# プロジェクト全体のPythonファイルを確認する +ruff check . +# ソースコードのみ実行する場合 +ruff check src +``` + +**レポートを生成する場合** + +シンプルなレポートとしては`generate_linter.sh`を実行してください + +```sh +sh scripts/generate_linter.sh +``` + +形式を指定して出力する方法 + +```sh +ruff check . --output-format json --output-file ruff-report.json +``` + diff --git a/scripts/generate_linter.sh b/scripts/generate_linter.sh new file mode 100644 index 0000000..fbad27b --- /dev/null +++ b/scripts/generate_linter.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# scripts/genarater_linter.sh + +set -u # 未定義変数の利用で落とす(-e は付けない) + +RUFF_STATUS=0 +OUTPUT_MD=${1:-lint-result.md} + +{ + echo "## 🧹 Ruff Lint Result" + echo + echo "### Command" + echo '```bash' + echo '$ ruff check .' + echo '```' + echo + echo "### Output" + echo '```text' + # ruff がエラーになってもスクリプト自体は落とさず、ステータスだけ拾う + ruff check . || RUFF_STATUS=$? + echo '```' + echo + echo "### Summary" + echo + echo "| Tool | Status |" + echo "|------|--------|" + if [ "$RUFF_STATUS" -eq 0 ]; then + echo "| ruff | ✅ OK |" + else + echo "| ruff | ❌ Error (exit $RUFF_STATUS) |" + fi +} | tee "$OUTPUT_MD" + +# GitHub Actions から呼ばれた場合は、出力変数としてステータスを渡す +if [ -n "${GITHUB_OUTPUT:-}" ]; then + echo "ruff_status=$RUFF_STATUS" >> "$GITHUB_OUTPUT" +fi + +# ここでは常に 0 で終了(失敗にするかどうかはワークフロー側で制御) +exit 0 \ No newline at end of file