|
1 | 1 | # SPDX-FileCopyrightText: 2016-2024 PyThaiNLP Project
|
2 | 2 | # SPDX-License-Identifier: CC0-1.0
|
3 | 3 |
|
4 |
| -name: Upload package to PyPI |
| 4 | +name: Build and publish to PyPI |
5 | 5 |
|
6 | 6 | on:
|
| 7 | + push: |
| 8 | + branches: |
| 9 | + - dev |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - dev |
7 | 13 | release:
|
8 |
| - types: [created] |
| 14 | + types: [published] |
9 | 15 |
|
10 | 16 | 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 }}" |
12 | 27 |
|
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 |
14 | 50 | strategy:
|
15 | 51 | matrix:
|
16 |
| - python-version: ["3.10"] |
| 52 | + python-version: ["3.12"] |
17 | 53 |
|
18 | 54 | steps:
|
19 | 55 | - name: Checkout
|
20 | 56 | uses: actions/checkout@v4
|
| 57 | + |
21 | 58 | - name: Set up Python ${{ matrix.python-version }}
|
22 | 59 | uses: actions/setup-python@v5
|
23 | 60 | with:
|
24 | 61 | python-version: ${{ matrix.python-version }}
|
| 62 | + |
25 | 63 | - name: Install dependencies
|
26 | 64 | 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 |
31 | 90 | uses: pypa/gh-action-pypi-publish@release/v1
|
| 91 | + if: github.event_name == 'release' && github.event.action == 'published' |
32 | 92 | with:
|
| 93 | + skip-existing: true |
33 | 94 | user: __token__
|
34 | 95 | password: ${{ secrets.PYPI_API_TOKEN }}
|
0 commit comments