From 3cc02dfc18c8114f66ab009c3287bae4c43d02cc Mon Sep 17 00:00:00 2001 From: zjowowen Date: Thu, 31 Oct 2024 17:37:46 +0800 Subject: [PATCH] Add release workflow. --- .github/workflows/release.yml | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e471193 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +name: Publish to PyPI + +on: + # Trigger this workflow when a new tag is pushed + push: + tags: + - '*' + +jobs: + build-and-publish: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + # Step 1: Check out the repository + - name: Check out code + uses: actions/checkout@v3 + + # Step 2: Set up Python environment with matrix + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + # Step 3: Install build dependencies + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + + # Step 4: Build the package (wheel and source distribution) + - name: Build the package + run: | + python setup.py sdist bdist_wheel + + # Step 5: Publish the package to PyPI (only run once for one version) + - name: Publish to PyPI + if: matrix.python-version == '3.9' # Publish only once, on Python 3.9 + env: + PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} # Use the PyPI token stored in GitHub Secrets + run: | + python -m twine upload dist/* + + # Step 6: Clean up the build artifacts + - name: Remove build artifacts + if: matrix.python-version == '3.9' # Clean up once after publishing + run: rm -rf dist build *.egg-info