Merge pull request 'linterのテスト' (#1) from develop into main

Reviewed-on: #1
This commit is contained in:
ry.yamafuji 2025-12-04 09:05:06 +09:00
commit 6f6c0c6190
6 changed files with 133 additions and 4 deletions

64
.github/workflows/pyruff.yml vendored Normal file
View File

@ -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
# ```

View File

@ -2,10 +2,10 @@ name: Python Test
on:
workflow_dispatch:
push:
pull_request:
branches:
- main
# - develop
- develop
paths:
- 'src/**'
- 'tests/**'

2
.gitignore vendored
View File

@ -3,7 +3,7 @@
__pycache__/
*.py[cod]
*$py.class
ruff-report.*
# C extensions
*.so

View File

@ -11,7 +11,7 @@ logger = get_logger(__name__)
def example():
logger.info("Application started")
print("Hello, World!")
print("Hello, World!")
example()

View File

@ -26,6 +26,7 @@ uv init <ProjectName>
# uv init <ProjectName> -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
```

View File

@ -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