From 1943c318fd8fd25225c209fc69b53a6c2ffb887c Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:25:05 +0000 Subject: [PATCH 1/2] Update Release Workflows --- .github/workflows/release-pypi.yml | 121 ++++++++++++++++++++++------- pyproject.toml | 2 +- release-pypi-linux.sh | 54 ------------- release-pypi-macos.sh | 47 ----------- release-pypi-windows.cmd | 41 ---------- 5 files changed, 93 insertions(+), 172 deletions(-) delete mode 100644 release-pypi-linux.sh delete mode 100644 release-pypi-macos.sh delete mode 100644 release-pypi-windows.cmd diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index c95894776..93458f49c 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -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_test_pypi: + name: Upload to TestPyPI + 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 TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + packages-dir: dist + skip-existing: true diff --git a/pyproject.toml b/pyproject.toml index 4a85092d5..9ec751f5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools>=61", "wheel"] +requires = ["setuptools>=61", "wheel", "cmake"] build-backend = "setuptools.build_meta" diff --git a/release-pypi-linux.sh b/release-pypi-linux.sh deleted file mode 100644 index 20714a533..000000000 --- a/release-pypi-linux.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -set -e - -# Different to release-pypi-win.cmd and release-pypi-osx.sh, -# this script has to be ran from a clean dockerfile - -# Random note: The reason why this script is being ran from within a container -# is to ensure glibc compatibility. From what I've seen so far, it appears -# that having multiple glibc versions is a somewhat convoluted process -# and I don't trust myself to be able to manage them well. - -# Download dependenciess -export DEBIAN_FRONTEND=noninteractive -apt update -apt upgrade -y -apt install -y g++ make curl - -cd /opt/OpenCC - -# Download and init conda -MINICONDA_FILENAME=Miniconda3-latest-Linux-x86_64.sh -curl -L -o $MINICONDA_FILENAME \ - "https://repo.continuum.io/miniconda/$MINICONDA_FILENAME" -bash ${MINICONDA_FILENAME} -b -f -p $HOME/miniconda3 -export PATH=$HOME/miniconda3/bin:$PATH -eval "$(conda shell.bash hook)" - -# Accept conda Terms of Service for required channels -conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main -conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r - -for VERSION in 3.8 3.9 3.10 3.11 3.12; do - # Create and activate environment - conda config --add channels conda-forge - conda config --set channel_priority strict - conda create -y -n py$VERSION python=$VERSION - conda activate py$VERSION - - # Build and package - pip install --no-cache-dir build - python -m build \ - -C--plat-name="manylinux2014_$(uname --machine)" - - # Cleanup - conda deactivate - rm -rf build OpenCC.egg-info -done - -if [ "$1" != "testonly" ]; then - # Upload to PyPI - conda activate py3.8 - python -m pip install twine - python -m twine upload dist/* -fi diff --git a/release-pypi-macos.sh b/release-pypi-macos.sh deleted file mode 100644 index b4a7fa1c6..000000000 --- a/release-pypi-macos.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -set -e - -# Different to release-pypi-win.cmd and release-pypi-osx.sh, -# this script has to be ran from a clean dockerfile - -# Download and init conda -# Detect architecture and set appropriate Miniconda filename -ARCH=$(uname -m) -if [ "$ARCH" = "arm64" ]; then - MINICONDA_FILENAME=Miniconda3-latest-MacOSX-arm64.sh -else - MINICONDA_FILENAME=Miniconda3-latest-MacOSX-x86_64.sh -fi - -curl -L -o $MINICONDA_FILENAME \ - "https://repo.continuum.io/miniconda/$MINICONDA_FILENAME" -bash ${MINICONDA_FILENAME} -b -f -p $HOME/miniconda3 -export PATH=$HOME/miniconda3/bin:$PATH -eval "$(conda shell.bash hook)" - -# Accept conda Terms of Service for required channels -conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main -conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r - -for VERSION in 3.8 3.9 3.10 3.11 3.12; do - # Create and activate environment - conda config --add channels conda-forge - conda config --set channel_priority strict - conda create -y -n py$VERSION python=$VERSION - conda activate py$VERSION - - # Build and package - pip install --no-cache-dir build - python -m build --wheel - - # Cleanup - conda deactivate - rm -rf build OpenCC.egg-info -done - -if [ "$1" != "testonly" ]; then - # Upload to PyPI - conda activate py3.8 - python -m pip install twine - python -m twine upload dist/* -fi diff --git a/release-pypi-windows.cmd b/release-pypi-windows.cmd deleted file mode 100644 index 635399f37..000000000 --- a/release-pypi-windows.cmd +++ /dev/null @@ -1,41 +0,0 @@ -@echo off -setlocal EnableDelayedExpansion - -SET VERSIONS=3.8 3.9 3.10 3.11 3.12 -SET SOURCEDIR=%cd% - -REM Accept conda Terms of Service for required channels -CALL C:\Miniconda/condabin/conda.bat tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main -CALL C:\Miniconda/condabin/conda.bat tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r - -REM Build packages -for %%v in (%VERSIONS%) do ( - SET ENV_NAME=py%%v - - REM Create and activate environment - cd %ROOT_DIR% - CALL C:\Miniconda/condabin/conda.bat config --add channels conda-forge - CALL C:\Miniconda/condabin/conda.bat config --set channel_priority strict - - CALL C:\Miniconda/condabin/conda.bat create -y -n py%%v python=%%v - if !ERRORLEVEL! NEQ 0 (EXIT !ERRORLEVEL!) - CALL C:\Miniconda/condabin/conda.bat activate py%%v - if !ERRORLEVEL! NEQ 0 (EXIT !ERRORLEVEL!) - pip install --no-cache-dir build - if !ERRORLEVEL! NEQ 0 (EXIT !ERRORLEVEL!) - - REM Build and package - python -m build --wheel - if !ERRORLEVEL! NEQ 0 (EXIT !ERRORLEVEL!) - - REM Cleanup - CALL C:\Miniconda/condabin/conda.bat deactivate - rmdir /S /Q build OpenCC.egg-info -) - -if NOT "%~1"=="testonly" ( - REM Upload to PyPI - C:\Miniconda/condabin/conda.bat activate py3.8 - python -m pip install twine - python -m twine upload dist/* -) From 489a3011e9aadc17da2e0955c467d87ce71774ca Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Wed, 18 Feb 2026 23:55:13 +0000 Subject: [PATCH 2/2] Change the upload endpoint from TestPyPI to PyPI --- .github/workflows/release-pypi.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index 93458f49c..66fdcf87f 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -72,8 +72,8 @@ jobs: name: sdist path: dist/*.tar.gz - publish_test_pypi: - name: Upload to TestPyPI + publish_pypi: + name: Upload to PyPI needs: [build_wheels, build_sdist] runs-on: ubuntu-latest permissions: @@ -93,9 +93,9 @@ jobs: name: sdist path: dist - - name: Publish to TestPyPI + - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - repository-url: https://test.pypi.org/legacy/ + repository-url: https://upload.pypi.org/legacy/ packages-dir: dist skip-existing: true