Skip to content

Commit 630b355

Browse files
authored
Merge pull request #994 from bact/build-using-cibuildwheel
Use "build" instead of setup.py + add "[cd build]" build trigger word
2 parents 3b26823 + f3190e1 commit 630b355

File tree

3 files changed

+84
-10
lines changed

3 files changed

+84
-10
lines changed

.github/workflows/pypi-publish.yml

+70-9
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,95 @@
11
# SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project
22
# SPDX-License-Identifier: CC0-1.0
33

4-
name: Upload package to PyPI
4+
name: Build and publish to PyPI
55

66
on:
7+
push:
8+
branches:
9+
- dev
10+
pull_request:
11+
branches:
12+
- dev
713
release:
8-
types: [created]
14+
types: [published]
915

1016
jobs:
11-
pypi-publish:
17+
echo_github_env:
18+
name: Echo env variables
19+
runs-on: ubuntu-latest
20+
steps:
21+
- run: |
22+
echo "github.event.action : ${{ github.event.action }}"
23+
echo "github.event_name : ${{ github.event_name }}"
24+
echo "github.ref : ${{ github.ref }}"
25+
echo "github.ref_type : ${{ github.ref_type }}"
26+
echo "github.event.ref : ${{ github.event.ref }}"
1227
13-
runs-on: ubuntu-24.04
28+
# Check whether to build the wheels and the source tarball
29+
check_build_trigger:
30+
name: Check build trigger
31+
runs-on: ubuntu-latest
32+
# Not for forks
33+
if: github.repository == 'pythainlp/pythainlp'
34+
outputs:
35+
build: ${{ steps.check_build_trigger.outputs.build }}
36+
steps:
37+
- name: Checkout source code
38+
uses: actions/checkout@v4
39+
with:
40+
ref: ${{ github.event.pull_request.head.sha }}
41+
- id: check_build_trigger
42+
name: Check build trigger
43+
run: bash build_tools/github/check_build_trigger.sh
44+
# To trigger the build steps, add "[cd build]" to commit message
45+
46+
build:
47+
name: Build and check distributions
48+
needs: [check_build_trigger]
49+
runs-on: ubuntu-latest
1450
strategy:
1551
matrix:
16-
python-version: ["3.10"]
52+
python-version: ["3.12"]
1753

1854
steps:
1955
- name: Checkout
2056
uses: actions/checkout@v4
57+
2158
- name: Set up Python ${{ matrix.python-version }}
2259
uses: actions/setup-python@v5
2360
with:
2461
python-version: ${{ matrix.python-version }}
62+
2563
- name: Install dependencies
2664
run: |
27-
python -m pip install --upgrade "pip<24.1" setuptools twine wheel
28-
python setup.py sdist bdist_wheel
29-
# "python setup.py" is no longer recommended.
30-
- name: Publish a Python distribution to PyPI
65+
pip install --upgrade build pip twine
66+
67+
- name: Build source distribution and wheels
68+
run: python -m build
69+
70+
- name: Check distributions
71+
run: twine check dist/*
72+
73+
- name: Store distributions
74+
uses: actions/upload-artifact@v3
75+
with:
76+
path: pythainlp/dist/*
77+
78+
publish_pypi:
79+
name: Publish to PyPI
80+
runs-on: ubuntu-latest
81+
needs: [build]
82+
if: github.event_name == 'release' && github.event.action == 'published'
83+
steps:
84+
- name: Retrieve distributions
85+
uses: actions/download-artifact@v3
86+
with:
87+
name: artifact
88+
path: dist
89+
- name: Publish to PyPI
3190
uses: pypa/gh-action-pypi-publish@release/v1
91+
if: github.event_name == 'release' && github.event.action == 'published'
3292
with:
93+
skip-existing: true
3394
user: __token__
3495
password: ${{ secrets.PYPI_API_TOKEN }}

.python-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.10
1+
3.12
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
COMMIT_MSG=$(git log --no-merges -1 --oneline)
7+
8+
# The commit marker "[cd build]" will trigger the build when required
9+
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ||
10+
"$GITHUB_EVENT_NAME" == "release" ||
11+
"$COMMIT_MSG" =~ "[cd build]" ]]; then
12+
echo "build=true" >> $GITHUB_OUTPUT
13+
fi

0 commit comments

Comments
 (0)