Skip to content

Commit d8e599a

Browse files
authored
Merge pull request #6 from 7rikazhexde/bug#4. Closes #4
♻️Update Dependabot configuration and refine project dependencies in pyproject.toml and requirements.txt
2 parents fcae324 + e3c3e9f commit d8e599a

File tree

15 files changed

+1091
-217
lines changed

15 files changed

+1091
-217
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Local Test Workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
env:
12+
TZ: 'Asia/Tokyo'
13+
steps:
14+
- uses: actions/checkout@v4.2.2
15+
16+
- name: Test setup, run and check coverage
17+
if: always()
18+
shell: bash
19+
run: |
20+
python3 --version
21+
python3 -m pip install --upgrade pip
22+
python3 -m pip install "poetry>=1.7.0"
23+
poetry install
24+
25+
# テスト実行とカバレッジレポート
26+
poetry run task test_ci_xml
27+
28+
# poetryの環境内でcoverageを実行
29+
poetry run coverage report
30+
coverage_percentage=$(poetry run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
31+
echo "Current coverage: ${coverage_percentage}%"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# スクリプトの絶対パスを取得
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
6+
# プロジェクトのルートディレクトリを取得
7+
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
8+
9+
# テスト結果を保存するディレクトリ
10+
LOG_DIR="${PROJECT_ROOT}/.github/workflows/act/act_logs"
11+
mkdir -p "${LOG_DIR}"
12+
13+
# テストを実行する関数
14+
run_test() {
15+
local python_version="$1"
16+
local docker_image="python:${python_version}-slim"
17+
local log_file="${LOG_DIR}/act-wf-${python_version}.log"
18+
local workflow_file="${SCRIPT_DIR}/local-test.yml"
19+
20+
echo "Running tests for Python ${python_version}"
21+
echo "Using Docker image: ${docker_image}"
22+
echo "Logging to: ${log_file}"
23+
echo "Workflow file: ${workflow_file}"
24+
25+
# ワークフローファイルの存在を確認
26+
if [ ! -f "${workflow_file}" ]; then
27+
echo "❌ ワークフローファイルが見つかりません: ${workflow_file}"
28+
return 1
29+
fi
30+
31+
# actコマンドの実行
32+
act pull_request \
33+
-W "${workflow_file}" \
34+
-P ubuntu-latest="${docker_image}" \
35+
--verbose 2>&1 | tee "${log_file}"
36+
37+
local exit_code="${PIPESTATUS[0]}"
38+
if [ "$exit_code" -eq 0 ]; then
39+
echo "✅ テストに成功しました: Python ${python_version}"
40+
else
41+
echo "❌ テストに失敗しました: Python ${python_version}"
42+
fi
43+
echo "----------------------------------------"
44+
return "$exit_code"
45+
}
46+
47+
# 結果を保存する配列
48+
declare -A results
49+
50+
# 各バージョンでテストを実行
51+
python_versions=("3.10" "3.11" "3.12" "3.13-rc")
52+
failed_versions=()
53+
54+
for version in "${python_versions[@]}"; do
55+
if run_test "$version"; then
56+
results["$version"]="✅ 成功"
57+
else
58+
results["$version"]="❌ 失敗"
59+
failed_versions+=("$version")
60+
fi
61+
done
62+
63+
# 結果のサマリーを表示
64+
echo "テスト結果サマリー:"
65+
echo "===================="
66+
for version in "${python_versions[@]}"; do
67+
echo "Python ${version}: ${results["$version"]}"
68+
done
69+
70+
# 失敗したテストがあれば報告
71+
if [ "${#failed_versions[@]}" -ne 0 ]; then
72+
echo -e "\n失敗したテストのバージョン:"
73+
for version in "${failed_versions[@]}"; do
74+
echo "- Python ${version}"
75+
done
76+
exit 1
77+
fi
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"pull_request": {
3+
"title": "Test PR for Local Testing",
4+
"number": 1,
5+
"head": {
6+
"ref": "feature-branch"
7+
}
8+
},
9+
"sender": {
10+
"login": "testuser"
11+
},
12+
"repository": {
13+
"full_name": "yourusername/yourrepo"
14+
},
15+
"event_name": "pull_request",
16+
"ref": "refs/pull/1/merge",
17+
"github": {
18+
"actor": "testuser"
19+
}
20+
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
name: Dependabot PR Check
2+
3+
# ワークフローの処理の流れ:
4+
# 1. トリガー条件:
5+
# - mainブランチへのプルリクエスト時
6+
# - Dependabotによる実行であること
7+
# - コミットメッセージが"Bump version"で始まっていないこと
8+
# 2. ジョブの条件判定: Dependabot によるPRであることをチェック
9+
# 3. OS毎の環境設定 (macos-latest, ubuntu-latest, windows-latest)
10+
# 4. Python環境のセットアップ (3.11, 3.12)
11+
# 5. タイムゾーンの設定 (Asia/Tokyo)
12+
# 6. リポジトリのチェックアウト
13+
# 7. Poetry のインストール
14+
# 8. 依存関係のキャッシュ
15+
# 9. プロジェクト依存関係のインストール
16+
# 10. テストの実行とカバレッジの計算
17+
# 11. カバレッジが90%以上であることのチェック
18+
# 12. テスト結果とカバレッジレポートの生成
19+
# 13. テスト結果の確認と警告の表示
20+
# 14. ジョブサマリーの作成
21+
# 15. 全テストの結果確認
22+
# 16. Discord Webhookの送信
23+
24+
on:
25+
pull_request:
26+
branches:
27+
- main
28+
29+
jobs:
30+
set_variables:
31+
if: github.actor == 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
32+
runs-on: ubuntu-latest
33+
outputs:
34+
os: ${{ steps.json2vars.outputs.os }}
35+
versions_python: ${{ steps.json2vars.outputs.versions_python }}
36+
ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4.2.2
40+
with:
41+
fetch-depth: 0
42+
43+
- name: Set variables from JSON
44+
id: json2vars
45+
uses: 7rikazhexde/json2vars-setter@main
46+
with:
47+
json-file: .github/workflows/matrix.json
48+
49+
- name: Debug output values
50+
run: |
51+
echo "os: ${{ steps.json2vars.outputs.os }}"
52+
echo "versions_python: ${{ steps.json2vars.outputs.versions_python }}"
53+
echo "ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}"
54+
55+
test:
56+
needs: set_variables
57+
strategy:
58+
matrix:
59+
os: ${{ fromJson(needs.set_variables.outputs.os) }}
60+
python-version: ${{ fromJson(needs.set_variables.outputs.versions_python) }}
61+
runs-on: ${{ matrix.os }}
62+
env:
63+
TZ: 'Asia/Tokyo'
64+
permissions:
65+
contents: write
66+
pull-requests: write
67+
steps:
68+
- uses: actions/checkout@v4.2.2
69+
- name: Set up Python
70+
uses: actions/setup-python@v5.4.0
71+
with:
72+
python-version: ${{matrix.python-version}}
73+
- name: Set timezone
74+
uses: szenius/set-timezone@v2.0
75+
with:
76+
timezoneLinux: "Asia/Tokyo"
77+
timezoneMacos: "Asia/Tokyo"
78+
timezoneWindows: "Tokyo Standard Time"
79+
- name: Check timezone
80+
shell: bash
81+
run: |
82+
echo "System date: $(date)"
83+
echo "TZ environment variable: ${TZ}"
84+
python -c "import datetime, platform; print(f'Python timezone: {datetime.datetime.now().astimezone().tzinfo}'); print(f'OS: {platform.system()}')"
85+
- name: Install poetry
86+
run: pip install poetry
87+
- name: Cache dependencies
88+
uses: actions/cache@v4.2.0
89+
with:
90+
path: ~/.cache/pypoetry
91+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
92+
- name: Install dependencies
93+
shell: bash
94+
run: |
95+
rm -f poetry.lock
96+
poetry lock
97+
poetry install
98+
- name: Run test
99+
shell: bash
100+
id: pytest
101+
run: |
102+
poetry run task test_ci_xml
103+
coverage_percentage=$(poetry run coverage report | grep TOTAL | awk '{print $NF}' | sed 's/%//')
104+
echo "Current coverage: ${coverage_percentage}%"
105+
echo "COVERAGE=${coverage_percentage}" >> "$GITHUB_ENV"
106+
- name: Check coverage
107+
shell: bash
108+
run: |
109+
if [ "${COVERAGE}" -lt 90 ]; then
110+
echo "Test coverage is below 90%. Current coverage: ${COVERAGE}%"
111+
exit 1
112+
else
113+
echo "Test coverage is above or equal to 90%. Current coverage: ${COVERAGE}%"
114+
fi
115+
- name: Pytest coverage comment
116+
id: coverageComment
117+
uses: MishaKav/pytest-coverage-comment@v1.1.53
118+
with:
119+
pytest-coverage-path: ./pytest-coverage.txt
120+
pytest-xml-coverage-path: ./coverage.xml
121+
title: Coverage Report (${{ matrix.os }} / Python ${{ matrix.python-version }})
122+
badge-title: coverage
123+
hide-badge: false
124+
hide-report: false
125+
create-new-comment: true
126+
hide-comment: false
127+
report-only-changed-files: false
128+
remove-link-from-badge: false
129+
junitxml-path: ./pytest.xml
130+
junitxml-title: "Pytest Result Summary (os: ${{ matrix.os }} / python-version: ${{ matrix.python-version }})"
131+
github-token: ${{ secrets.PAT_FOR_PUSHES }}
132+
- name: Check test results
133+
if: steps.pytest.outcome == 'failure'
134+
run: |
135+
echo "Tests failed. This will be reported in the workflow summary."
136+
echo "::warning::Tests failed on ${{ matrix.os }} with Python ${{ matrix.python-version }}"
137+
- name: Write job summary
138+
id: check_status
139+
shell: bash
140+
run: |
141+
echo -e ${{ steps.coverageComment.outputs.summaryReport }} >> "$GITHUB_STEP_SUMMARY"
142+
143+
check_all_tests:
144+
needs: test
145+
runs-on: ubuntu-latest
146+
if: github.actor == 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
147+
steps:
148+
- name: Check test results
149+
if: contains(needs.test.result, 'failure')
150+
run: |
151+
echo "Some tests failed. Please check the test results and fix any issues before merging."
152+
exit 1
153+
154+
send_notification:
155+
needs: [test, check_all_tests]
156+
runs-on: ubuntu-latest
157+
if: github.actor == 'dependabot[bot]' && !startsWith(github.event.pull_request.title, 'Bump version')
158+
steps:
159+
- name: Send Discord Notification
160+
env:
161+
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
162+
PR_TITLE: ${{ github.event.pull_request.title }}
163+
WORKFLOW_ACTOR: ${{ github.actor }}
164+
run: |
165+
workflow_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
166+
status="${{ contains(needs.test.result, 'failure') && 'FAILED ❌' || 'SUCCESS ✅' }}"
167+
168+
message="## Dependabot PR Check Completed
169+
170+
### Workflow Information
171+
• **Name:** ${{ github.workflow }}
172+
• **Status:** ${status}
173+
• **Run:** [View Details]($workflow_url)
174+
• **PR Title:** ${PR_TITLE}
175+
• **Actor:** ${WORKFLOW_ACTOR}"
176+
177+
timestamp="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
178+
json_payload=$(jq -n \
179+
--arg title "${{ github.workflow }} - Dependabot Check Status" \
180+
--arg description "$message" \
181+
--argjson color "${{ contains(needs.test.result, 'failure') && '16711680' || '65280' }}" \
182+
--arg timestamp "$timestamp" \
183+
'{
184+
"embeds": [
185+
{
186+
"title": $title,
187+
"description": $description,
188+
"color": $color,
189+
"timestamp": $timestamp
190+
}
191+
]
192+
}')
193+
194+
curl -X POST -H "Content-Type: application/json" \
195+
-d "$json_payload" \
196+
"$DISCORD_WEBHOOK_URL"

.github/workflows/matrix.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"os": [
3+
"ubuntu-latest",
4+
"windows-latest",
5+
"macos-latest"
6+
],
7+
"versions": {
8+
"python": [
9+
"3.10",
10+
"3.11",
11+
"3.12",
12+
"3.13"
13+
]
14+
},
15+
"ghpages_branch": "ghpages"
16+
}

0 commit comments

Comments
 (0)