Skip to content

Optimize: add Cython extensions for is_thai_char, is_thai, count_thai (2.2x–11.0x) #1703

Optimize: add Cython extensions for is_thai_char, is_thai, count_thai (2.2x–11.0x)

Optimize: add Cython extensions for is_thai_char, is_thai, count_thai (2.2x–11.0x) #1703

Workflow file for this run

# SPDX-FileCopyrightText: 2016-2026 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: CC0-1.0
name: Build and publish to PyPI
on:
push: # Use together with "[cd build]" commit message
branches:
- dev
pull_request: # Use together with "[cd build]" commit message
branches:
- dev
release:
types: [published] # "Publish release" button
workflow_dispatch: # Manual trigger to test wheel build
# 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.
# Also applies to release (uses tag name) and workflow_dispatch (uses branch/tag name).
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:
echo_github_env:
name: Echo env variables
runs-on: ubuntu-latest
steps:
- run: |
echo "github.event.action : ${{ github.event.action }}"
echo "github.event_name : ${{ github.event_name }}"
echo "github.ref : ${{ github.ref }}"
echo "github.ref_type : ${{ github.ref_type }}"
echo "github.event.ref : ${{ github.event.ref }}"
# Check whether to build the wheels and the source tarball
check_build_trigger:
name: Check build trigger
runs-on: ubuntu-latest
# Not for forks
if: github.repository == 'pythainlp/pythainlp'
outputs:
build: ${{ steps.check_build_trigger.outputs.build }}
steps:
- name: Checkout source code
uses: actions/checkout@v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: check_build_trigger
name: Check build trigger
run: bash build_tools/github/check_build_trigger.sh
# To trigger the build steps, add "[cd build]" to commit message
build:
name: Build and check distributions
needs: [check_build_trigger]
if: needs.check_build_trigger.outputs.build
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
steps:
- name: Checkout
uses: actions/checkout@v7.0.1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6.2.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --upgrade build pip twine
- name: Build source distribution
run: python -m build --sdist # was: python -m build
- name: Check distributions
run: twine check dist/*
- name: Store distributions
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
with:
name: dist-sdist # explicit name for downstream retrieval
path: dist
build_wheels:
name: Build binary wheels (${{ matrix.os }})
needs: [check_build_trigger]
if: needs.check_build_trigger.outputs.build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest # → manylinux_2_17_x86_64
- windows-latest # → win_amd64
- macos-13 # → macosx_13_*_x86_64 (Intel)
- macos-14 # → macosx_14_*_arm64 (Apple Silicon)
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Build wheels
uses: pypa/cibuildwheel@fa04202e88ea28b84d5d4d20696ee8dfc0119436 # v2.23.0
# All config is read from [tool.cibuildwheel] in pyproject.toml:
# build/skip selectors, test command, per-platform archs
- name: Validate wheels
run: |
pip install twine
twine check ./wheelhouse/*.whl
- name: Upload wheel artifacts
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
with:
name: cibw-wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
publish_pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build, build_wheels] # was: needs: [build]
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- name: Retrieve distributions
uses: actions/download-artifact@v8
with:
name: dist-sdist # matches renamed artifact
path: dist
- name: Retrieve binary wheels
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9
with:
pattern: cibw-wheels-* # globs all 4 matrix artifacts
path: dist
merge-multiple: true # flatten: cibw-wheels-os1/a.whl → dist/a.whl
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
with:
skip-existing: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}