Fix codecov #107
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| branches: | |
| - master | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| test: | |
| name: Python ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| version: | |
| - "3.12" | |
| os: | |
| - ubuntu-latest | |
| arch: | |
| - x64 | |
| - x86 | |
| steps: | |
| # Updated to v4 | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install coverage | |
| pip install pytest pytest-cov | |
| pip install -r requirements.txt | |
| - name: Configure Coverage Parallel Mode | |
| run: | | |
| echo '[run]' > .coveragerc | |
| echo 'parallel = True' >> .coveragerc | |
| - name: Run tests (Parallel Data Collection) | |
| run: | | |
| export RANK=0 | |
| export LOCAL_RANK=0 | |
| export WORLD_SIZE=1 | |
| export MASTER_ADDR=localhost | |
| export MASTER_PORT=12345 | |
| export PYTHONPATH=MCintegration | |
| # 使用 coverage run 运行 pytest 以确保多进程/多核测试数据的收集 | |
| coverage run -m pytest --ignore=examples | |
| # 【调试步骤】列出所有 .coverage 文件,检查文件是否被正确生成 | |
| - name: Debug Coverage Files | |
| run: ls -F .coverage* | |
| # Updated to v4 | |
| - name: Upload coverage data artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-data-${{ matrix.os }}-${{ matrix.arch }} | |
| # 修复:同时上传 .coverage (单进程默认) 和 .coverage.* (多进程并行) 文件 | |
| path: | | |
| .coverage | |
| .coverage.* | |
| codecov: | |
| name: Codecov Merge & Upload | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| # Updated to v4 | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.12' | |
| - name: Install coverage (for combining) | |
| run: pip install coverage | |
| # Updated to v4 | |
| - name: Download all coverage data artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: coverage-artifacts | |
| # 合并所有数据文件并生成最终 XML 报告 | |
| - name: Combine and Report | |
| run: | | |
| # 移动所有数据文件到根目录,以便 coverage combine 找到 | |
| # find 命令现在可以安全运行,因为 download-artifact 应该已创建目录 | |
| find coverage-artifacts -name ".coverage*" -exec mv {} . \; | |
| # 合并所有 .coverage.* 文件,解决跨 Job 和多进程数据丢失问题 | |
| coverage combine | |
| # 生成最终的 XML 报告 | |
| coverage xml | |
| # 上传最终的合并报告 | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage.xml | |
| docs: | |
| name: Documentation | |
| runs-on: ubuntu-latest | |
| needs: codecov | |
| steps: | |
| # Updated to v4 | |
| - uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install sphinx | |
| pip install -r requirements.txt | |
| - name: Build documentation | |
| run: | | |
| cd docs | |
| sphinx-apidoc -o source ../MCintegration ../MCintegration/*_test.py | |
| python ../clean_MCintegration_rst.py | |
| make html | |
| python ../clean_html_sidebar.py | |
| - name: Deploy documentation to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: docs/build/html |