-
Notifications
You must be signed in to change notification settings - Fork 290
155 lines (140 loc) · 6.16 KB
/
unittest.yml
File metadata and controls
155 lines (140 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-License-Identifier: Apache-2.0
name: Unit test
on:
push:
paths:
- ".github/workflows/unittest.yml"
- "bin/**"
- "build_tools/**"
- "pythainlp/**"
- "tests/**"
- "Makefile"
- "MANIFEST.in"
- "pyproject.toml"
pull_request:
branches:
- dev
paths:
- ".github/workflows/unittest.yml"
- "bin/**"
- "build_tools/**"
- "pythainlp/**"
- "tests/**"
- "Makefile"
- "MANIFEST.in"
- "pyproject.toml"
# Avoid duplicate runs for the same source branch and repository.
# For pull_request events, uses the source repo name from
# github.event.pull_request.head.repo.full_name; otherwise uses github.repository.
# For push events, uses the branch name from github.ref_name.
# For pull_request events, uses the source branch name from github.head_ref.
# This ensures events for the same repo and branch share the same group,
# and avoids cross-fork collisions when branch names are reused.
concurrency:
group: >-
${{ github.workflow }}-${{
github.event.pull_request.head.repo.full_name || github.repository
}}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
jobs:
unittest:
strategy:
fail-fast: false
matrix:
# To optimize CI/CD resource utilization and manage dependency overhead,
# tests are categorized into four tiers based on their resource requirements
# and dependency complexity: "core", "compact", "extra", and "noauto".
# Test cases in "noauto" will not be included here.
# See details of test matrix in:
# https://github.com/PyThaiNLP/pythainlp/blob/dev/tests/README.md
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.14", "3.9"] # Latest and earliest
include:
# Test the rest of Python versions only on Ubuntu
- os: "ubuntu-latest"
python-version: "3.13"
- os: "ubuntu-latest"
python-version: "3.12"
- os: "ubuntu-latest"
python-version: "3.11"
- os: "ubuntu-latest"
python-version: "3.10"
runs-on: ${{ matrix.os }}
env:
PYICU_WIN_VER: 2.15 # 2.15 is the last version that supports Python 3.9
INSTALL_FULL_DEPS: false
PYTHON_VERSION_LATEST: "3.14"
PYTHON_VERSION_LATEST_2: "3.13" # Second-latest supported version
PYTHON_VERSION_EARLIEST: "3.9"
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install build tools
run: |
pip install --upgrade "pip<24.1" "setuptools>=69.0.0,<=73.0.1"
pip install coverage coveralls
# pip<24.1 because https://github.com/omry/omegaconf/pull/1195
# setuptools>=65.0.2 because https://github.com/pypa/setuptools/commit/d03da04e024ad4289342077eef6de40013630a44#diff-9ea6e1e3dde6d4a7e08c7c88eceed69ca745d0d2c779f8f85219b22266efff7fR1
# setuptools<=73.0.1 because https://github.com/pypa/setuptools/issues/4620
- name: Install ICU (macOS)
if: startsWith(matrix.os, 'macos-')
run: |
brew install icu4c
PKG_CONFIG_PATH=$(brew --prefix)/opt/icu4c/lib/pkgconfig
echo "PKG_CONFIG_PATH=${PKG_CONFIG_PATH}" >> "${GITHUB_ENV}"
ICU_VER=$(pkg-config --modversion icu-i18n)
echo "ICU_VER=${ICU_VER}"
echo "ICU_VER=${ICU_VER}" >> "${GITHUB_ENV}"
- name: Install PyICU (Windows)
if: startsWith(matrix.os, 'windows-') && (matrix.python-version == env.PYTHON_VERSION_LATEST_2 || matrix.python-version == env.PYTHON_VERSION_EARLIEST)
shell: powershell
# Get the wheel URL from https://github.com/cgohlke/pyicu-build/releases
run: |
$PYTHON_WIN_VER = "${{ matrix.python-version }}"
$CP_VER = "cp" + $PYTHON_WIN_VER.Replace(".", "")
$WHEEL_URL = "https://github.com/cgohlke/pyicu-build/releases/download/v${{ env.PYICU_WIN_VER }}/PyICU-${{ env.PYICU_WIN_VER }}-${CP_VER}-${CP_VER}-win_amd64.whl"
pip install "$WHEEL_URL"
- name: Install PyThaiNLP + full testing dependencies
if: env.INSTALL_FULL_DEPS == 'true'
env:
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL: True
run: pip install ".[full]"
- name: Test (core)
if: ${{ (matrix.os == 'ubuntu-latest' && matrix.python-version != env.PYTHON_VERSION_LATEST_2 && matrix.python-version != env.PYTHON_VERSION_EARLIEST) || (matrix.os != 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION_LATEST) }}
env:
PYTHONIOENCODING: utf-8
run: |
pip install .
python -m unittest tests.core
# Use 'unittest <test_module>' instead of 'unittest discover' to avoid
# loading tests with dependencies more than expected.
# Test cases loaded is defined in __init__.py in the tests directory.
# See also tests/README.md
- name: Test (compact + core)
if: ${{ ((matrix.python-version == env.PYTHON_VERSION_LATEST_2) || (matrix.python-version == env.PYTHON_VERSION_EARLIEST)) && !(matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION_LATEST_2) }}
env:
PYTHONIOENCODING: utf-8
run: |
pip install ".[compact]"
python -m unittest tests.core tests.compact
- name: Test (extra + compact + core)
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION_LATEST_2
env:
PYTHONIOENCODING: utf-8
run: |
pip install ".[compact,extra]"
coverage run -m unittest tests.core tests.compact tests.extra
# Only submit a report from the "extra" run, to get maximum coverage
- name: Coverage report
if: matrix.os == 'ubuntu-latest' && matrix.python-version == env.PYTHON_VERSION_LATEST_2
env:
COVERALLS_SERVICE_NAME: github
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYTHONIOENCODING: utf-8
run: coveralls