From df2845651350c4f5d4333bd399f98b4b6d2e29ae Mon Sep 17 00:00:00 2001 From: Anton Melser Date: Sun, 15 Oct 2023 17:14:56 +0800 Subject: [PATCH] Add Python package build validation Signed-off-by: Anton Melser --- .github/workflows/python.yml | 33 +++++++++++++++++++++++++++++++++ release-pypi-linux.sh | 10 ++++++---- release-pypi-macos.sh | 10 ++++++---- release-pypi-windows.cmd | 10 ++++++---- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 439906862..ccf6e78e6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -35,3 +35,36 @@ jobs: run: python setup.py build_ext install - name: Test with pytest run: cd python && pytest + + test-pypi: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + + 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 testonly + + - name: Build package and upload (macOS) + if: runner.os == 'macOS' + run: bash release-pypi-macos.sh testonly + 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 testonly + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} diff --git a/release-pypi-linux.sh b/release-pypi-linux.sh index 8e5cb3c4f..b0a11bcf5 100644 --- a/release-pypi-linux.sh +++ b/release-pypi-linux.sh @@ -42,7 +42,9 @@ for VERSION in 3.8 3.9 3.10 3.11 3.12; do rm -rf build python/opencc/clib OpenCC.egg-info done -# Upload to PyPI -conda activate py3.8 -python -m pip install twine -python -m twine upload dist/* +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 index f2dffe9a3..7b3c632a2 100644 --- a/release-pypi-macos.sh +++ b/release-pypi-macos.sh @@ -28,7 +28,9 @@ for VERSION in 3.8 3.9 3.10 3.11 3.12; do rm -rf build python/opencc/clib OpenCC.egg-info done -# Upload to PyPI -conda activate py3.8 -python -m pip install twine -python -m twine upload dist/* +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 index 0cb08729b..21b9e96ee 100644 --- a/release-pypi-windows.cmd +++ b/release-pypi-windows.cmd @@ -29,7 +29,9 @@ for %%v in (%VERSIONS%) do ( rmdir /S /Q build python\opencc\clib OpenCC.egg-info ) -REM Upload to PyPI -C:\Miniconda/condabin/conda.bat activate py3.8 -python -m pip install twine -python -m twine upload dist/* +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/* +)