Skip to content

[AI: Windsurf] refactor: 分離したバックエンドとフロントエンドの開発環境を設定 #6

[AI: Windsurf] refactor: 分離したバックエンドとフロントエンドの開発環境を設定

[AI: Windsurf] refactor: 分離したバックエンドとフロントエンドの開発環境を設定 #6

Workflow file for this run

name: Test and Coverage
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
- cron: '0 0 * * 1' # 毎週月曜日
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.9, "3.10", 3.11]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install pytest pytest-cov pytest-asyncio
- name: Run tests and generate coverage report
run: |
if [ "$RUNNER_OS" == "Linux" ] || [ "$RUNNER_OS" == "macOS" ]; then
export TESTING=True
export DATABASE_URL=sqlite+aiosqlite:///:memory:
export PYTHONPATH=src
elif [ "$RUNNER_OS" == "Windows" ]; then
echo "TESTING=True" >> $GITHUB_ENV
echo "DATABASE_URL=sqlite+aiosqlite:///:memory:" >> $GITHUB_ENV
echo "PYTHONPATH=src" >> $GITHUB_ENV
fi
python -m pytest tests/ -v --import-mode=importlib
python -m pytest tests/ -v --cov=src --cov-report=xml:coverage.xml --cov-report=term-missing --cov-report=html
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: true
- name: Upload coverage report artifact
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
htmlcov/
coverage.xml
retention-days: 5
deploy-coverage:
needs: test
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: ./coverage-report
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./coverage-report/htmlcov
publish_branch: gh-pages
force_orphan: true
keep_files: true
comment-pr:
needs: test
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: ./coverage-report
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; print(ET.parse('coverage-report/coverage.xml').getroot().attrib['line-rate'])")
COVERAGE_PERCENT=$(python -c "print(round($COVERAGE * 100, 2))")
echo "coverage=${COVERAGE_PERCENT}%" >> $GITHUB_OUTPUT
echo "coverage_number=${COVERAGE}" >> $GITHUB_OUTPUT
- name: Create PR comment
uses: actions/github-script@v7
with:
script: |
const coverage = `${{ steps.coverage.outputs.coverage }}`;
const coverageNumber = parseFloat(`${{ steps.coverage.outputs.coverage_number }}`);
let message = '## 📊 Test Coverage Report\n\n';
message += `- **Coverage**: ${coverage}\n`;
if (coverageNumber < 0.7) {
message += '❌ **WARNING**: Coverage is below the minimum threshold of 70%\n';
} else if (coverageNumber < 0.8) {
message += '⚠️ **NOTE**: Coverage is below the recommended threshold of 80%\n';
} else {
message += '✅ Great job! Coverage meets the recommended threshold\n';
}
message += '\n[View detailed coverage report]';
message += `(https://${context.repo.owner}.github.io/${context.repo.repo}/)`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});