ci:add CD #7
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: Python Package CI/CD | |
| on: | |
| push: | |
| branches: ["main"] | |
| # 关键:当推送符合 v*.*.* 格式的标签时触发 | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: ["main"] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 # 使用官方 Action 更简洁 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python ${{ matrix.python-version }} | |
| run: uv python install ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| uv sync --all-groups | |
| - name: Test with pytest | |
| run: | | |
| uv run python -m pytest --cov=testpack --cov-report=html --cov-report=term | |
| - name: Upload HTML report | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report-${{ github.sha }} | |
| path: htmlcov/ | |
| release: | |
| if: startsWith(github.ref, 'refs/tags/') | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v5 | |
| - name: Build package | |
| run: uv build | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: dist/* | |
| generate_release_notes: true |