ry.yamafuji a630929226
All checks were successful
Python Test / python-test (push) Successful in 9s
テストコードを実行する
2025-12-04 04:19:07 +09:00

84 lines
2.6 KiB
YAML

name: Python Test
on:
workflow_dispatch:
push:
branches:
- main
# - develop
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/pytest.yml'
- 'requirements.txt'
- 'requirements-dev.txt'
jobs:
python-test:
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 Python Test
id: runPyTest
run: |
pytest --junitxml=pytest.xml --cov-report term-missing --cov=src tests/ | tee pytest-coverage.txt
- name: Coverage Report
id: CoverageReport
if: success() # テスト成功時のみ実行
run: |
coverage-badge -o coverage.svg
python - <<EOF
from scripts.generate_coverage import GenerateCoverage
generate_coverage = GenerateCoverage()
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
git rm -rf . # すべてのファイルを削除
else
git checkout coverage-report
fi
- name: Update Readme
id: updateReadme
run: |
echo "# Pytest Report" > README.md
echo "" >> README.md
echo "![test](coverage.svg)" >> README.md
echo "" >> README.md
cat coverage_table.md >> README.md
cat README.md
- name: Check files before upload
id: checkFiles
run: ls -l 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
git commit -m "Update coverage report"
git push https://actions-bot:${{ secrets.GITEA_TOKEN }}@gitea.pglikers.com/data-science/cloud-run-job-base.git coverage-report --force