fix #18
This file contains 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 Publish | |
on: | |
push: | |
branches: [ "main" ] | |
tags: | |
- 'v*' | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build-and-test: | |
name: Build and 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.x" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
# 安装 pytest-cov & codecov | |
pip install pytest-cov codecov | |
# ★ 安装本地包 | |
pip install -e . | |
- name: Run tests with coverage | |
run: | | |
# 生成 coverage.xml 和终端报告 | |
pytest --cov=pysmatch --cov-report xml --cov-report term | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: coverage.xml | |
flags: unittests | |
name: codecov-coverage | |
build-and-publish: | |
name: Build and publish to PyPI and create GitHub release | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: [ build-and-test ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Extract tag name and strip 'v' prefix | |
run: echo "PACKAGE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV | |
- name: Install build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel twine | |
# 同样,这里如果需要本地包依赖也可以再加上: | |
# pip install -e . | |
- name: Build package | |
run: | | |
python setup.py sdist bdist_wheel | |
- name: Publish package to PyPI | |
uses: pypa/gh-action-pypi-publish@v1.4.2 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
repository_url: https://upload.pypi.org/legacy/ | |
- name: Create GitHub Release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: "Release ${{ github.ref_name }}" | |
body: "Release of version ${{ github.ref_name }} to PyPI." | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |