From 74fc462e7cb75eb9ada673c6fb1ac82156b38b9c Mon Sep 17 00:00:00 2001 From: hankcs Date: Mon, 13 Jan 2025 18:16:05 -0800 Subject: [PATCH] Add `.github` action for unit tests --- .github/pull_request_template.md | 38 ++++++++++++++ .github/workflows/unit-tests.yml | 85 ++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..c5e94a0 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,38 @@ + + +# 您的 Pull Request 标题 + +## 描述 + +请包含对此更改的简要概述以及修复的具体问题。还请包含相关的动机和背景说明。列出此更改所需的任何依赖项。 + +修复 #(issue) + +## 更改类型 + +请勾选所有相关选项并删除其他选项。 + +- [ ] Bug 修复(修复不会导致现有功能出问题的非破坏性更改) +- [ ] 破坏性更改(修复或功能会导致现有功能无法按预期工作) +- [ ] 新功能(添加不会破坏现有功能的新功能) +- [ ] 此更改需要更新文档 + +## 测试方式 + +请描述您运行的测试,以验证更改是否有效。提供步骤以便我们复现测试。还请列出测试配置中的相关细节。 + +## 检查清单 + +请检查所有适用项。 + +- [ ] ⚠️更改 **必须** 基于 `dev` 分支,而非 `master` +- [ ] 我已添加测试,证明我的修复是有效的或功能可以正常运行 +- [ ] 新的和现有的单元测试在本地运行通过 +- [ ] 我的代码符合该项目的样式规范 +- [ ] 我在代码中添加了注释,特别是在难以理解的部分 +- [ ] 我已对文档进行了相应更改 +- [ ] 我的更改未产生新的警告 +- [ ] 我已检查代码并纠正了任何拼写错误 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..268ab3e --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,85 @@ +name: Unit Tests + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +permissions: read-all + +jobs: + build: + + runs-on: ${{ matrix.os }} + env: + HANLP_STATIC_ROOT: ${{ github.workspace }}/data + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10', 3.11, 3.12, 3.13 ] + exclude: + # GHA doesn't list 3.6 for ubuntu-22.04 + - os: ubuntu-latest + python-version: "3.6" + + # MacOS 14.4.1 for arm64 doesn't support Python < 3.8 + - os: macos-latest + python-version: "3.6" + - os: macos-latest + python-version: "3.7" + + include: + # GHA doesn't list 3.6 for ubuntu-22 + - os: ubuntu-20.04 + python-version: "3.6" + + # MacOS 13 required for Python < 3.8 + - os: macos-13 + python-version: "3.6" + - os: macos-13 + python-version: "3.7" + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + shell: bash + run: | + python -m pip install -e . + python -m pip install pytest + + - name: Cache data + uses: actions/cache@v4 + with: + path: ${{ env.HANLP_STATIC_ROOT }} + key: hanlp-data + + - name: Test with pytest + shell: bash + run: | + pytest tests + deploy: + needs: build + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + python -m pip install setuptools wheel twine + - name: Deploy to PyPI + run: | + python setup.py sdist bdist_wheel + python -m twine upload dist/* + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + TWINE_REPOSITORY: pypi