Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 92 additions & 29 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,101 @@
name: Build and upload python package to PyPI

on:
workflow_dispatch
workflow_dispatch:

permissions:
contents: read

jobs:
release-pypi:
build_wheels:
name: Build wheels (${{ matrix.label }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
runs-on: ${{ matrix.os }}
include:
- label: linux-x86_64
os: ubuntu-24.04
cibw_archs: x86_64
- label: linux-aarch64
os: ubuntu-24.04-arm
cibw_archs: aarch64
- label: macos-arm64
os: macos-14
cibw_archs: arm64
- label: windows-amd64
os: windows-latest
cibw_archs: AMD64

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build wheels
uses: pypa/cibuildwheel@v2.22.0
env:
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-*"
CIBW_SKIP: "*-musllinux_*"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_BEFORE_BUILD: "python -m pip install --upgrade pip"

- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.label }}
path: wheelhouse/*.whl

build_sdist:
name: Build sdist
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Build package and upload from docker (Linux)
if: runner.os == 'Linux'
run: |
docker run --rm -v "${PWD}:/opt/OpenCC" \
-e TWINE_USERNAME=__token__ \
-e TWINE_PASSWORD=${{ secrets.PYPI_TOKEN }} \
ubuntu:22.04 /bin/bash /opt/OpenCC/release-pypi-linux.sh

- name: Build package and upload (macOS)
if: runner.os == 'macOS'
run: bash release-pypi-macos.sh
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

- name: Build package and upload (Windows)
if: runner.os == 'Windows'
run: |
C:\Miniconda/condabin/conda.bat init powershell
./release-pypi-windows.cmd
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build sdist
run: |
python -m pip install --upgrade pip build
python -m build --sdist

- name: Upload sdist artifact
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz

publish_pypi:
name: Upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- name: Download wheel artifacts
uses: actions/download-artifact@v4
with:
pattern: wheels-*
path: dist
merge-multiple: true

- name: Download sdist artifact
uses: actions/download-artifact@v4
with:
name: sdist
path: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://upload.pypi.org/legacy/
packages-dir: dist
skip-existing: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[build-system]
requires = ["setuptools>=61", "wheel"]
requires = ["setuptools>=61", "wheel", "cmake"]
build-backend = "setuptools.build_meta"
54 changes: 0 additions & 54 deletions release-pypi-linux.sh

This file was deleted.

47 changes: 0 additions & 47 deletions release-pypi-macos.sh

This file was deleted.

41 changes: 0 additions & 41 deletions release-pypi-windows.cmd

This file was deleted.