This commit is contained in:
parent
0819ec4d7d
commit
a8b6eff343
32
.github/workflows/pytest.yml
vendored
32
.github/workflows/pytest.yml
vendored
@ -5,7 +5,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
# - develop
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'tests/**'
|
||||
@ -37,6 +37,7 @@ jobs:
|
||||
|
||||
- name: Coverage Report
|
||||
id: CoverageReport
|
||||
if: success() # テスト成功時のみ実行
|
||||
run: |
|
||||
coverage-badge -o coverage.svg
|
||||
python - <<EOF
|
||||
@ -45,6 +46,17 @@ jobs:
|
||||
generate_coverage.save_table()
|
||||
EOF
|
||||
|
||||
- name: Generate coverage-report Branch AND README.md
|
||||
id: generateCoverageReportBranch
|
||||
if: success() # テスト成功時のみ実行
|
||||
run: |
|
||||
# coverage-report ブランチが存在しない場合は作成 あればチェックアウト
|
||||
if ! git ls-remote --exit-code origin coverage-report; then
|
||||
git checkout --orphan coverage-report
|
||||
else
|
||||
git checkout coverage-report
|
||||
fi
|
||||
|
||||
- name: Update Readme
|
||||
id: updateReadme
|
||||
run: |
|
||||
@ -56,13 +68,15 @@ jobs:
|
||||
cat README.md
|
||||
|
||||
- name: Check files before upload
|
||||
id: checkFiles
|
||||
run: ls -l README.md coverage.svg
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ret-artifact
|
||||
path: |
|
||||
README.md
|
||||
coverage.svg
|
||||
|
||||
- name: Commit Test Report To coverage-report Branch
|
||||
id: commitTestReport
|
||||
if: success() # テスト成功時のみ実行
|
||||
run: |
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add README.md coverage.svg table.md
|
||||
git commit -m "Update coverage report"
|
||||
git push https://actions-bot:${{ secrets.CICD_GITEA_TOKEN }}@${{ gitea.server_url }}/${{ gitea.repository }} HEAD:coverage-report --force
|
||||
|
||||
@ -2,7 +2,9 @@ import re
|
||||
|
||||
|
||||
class GenerateCoverage:
|
||||
def __init__(self, coverage_file="pytest-coverage.txt", output_file="coverage_table.md"):
|
||||
def __init__(self,
|
||||
coverage_file="pytest-coverage.txt",
|
||||
output_file="coverage_table.md"):
|
||||
"""
|
||||
初期化
|
||||
|
||||
@ -26,12 +28,14 @@ class GenerateCoverage:
|
||||
|
||||
for line in lines:
|
||||
# Coverage セクションの始まりを検出
|
||||
if "---------- coverage" in line:
|
||||
if "Name" in line and "Stmts" in line and "Miss" in line:
|
||||
in_coverage_section = True
|
||||
continue
|
||||
# Coverage セクションの終わりを検出
|
||||
if in_coverage_section and line.strip() == "":
|
||||
# Coverage セクションが終了したと判断
|
||||
# セパレーター行をスキップ
|
||||
if in_coverage_section and line.strip().startswith("---"):
|
||||
continue
|
||||
# Coverage セクションの終わりを検出(TOTAL行の次の空行)
|
||||
if in_coverage_section and (line.strip().startswith("TOTAL") or line.strip().startswith("=")):
|
||||
break
|
||||
# Coverage データを抽出
|
||||
if in_coverage_section:
|
||||
@ -60,6 +64,7 @@ class GenerateCoverage:
|
||||
"""
|
||||
if not self.coverage_data:
|
||||
self.parse_coverage()
|
||||
print("Parsed coverage data.")
|
||||
|
||||
# Markdown テーブルヘッダー
|
||||
table_header = "| File | Statements | Missed | Coverage | Missing Lines |\n"
|
||||
@ -67,7 +72,9 @@ class GenerateCoverage:
|
||||
|
||||
# テーブル行を生成
|
||||
table_rows = [
|
||||
f"| {data['filename']} | {data['statements']} | {data['missed']} | {data['coverage']} | {data['missing_lines']} |"
|
||||
(f"| {data['filename']} | {data['statements']} | "
|
||||
f"{data['missed']} | {data['coverage']} | "
|
||||
f"{data['missing_lines']} |")
|
||||
for data in self.coverage_data
|
||||
]
|
||||
|
||||
@ -91,3 +98,9 @@ class GenerateCoverage:
|
||||
with open(self.output_file, "w", encoding="utf-8") as f:
|
||||
print(f"Markdown table has been saved to {self.output_file}")
|
||||
f.write(self.markdown_table)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generator = GenerateCoverage()
|
||||
generator.generate_table()
|
||||
generator.save_table()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user