From 3618edb8d4583b40745c3103f071397daeeb8102 Mon Sep 17 00:00:00 2001 From: Ryuichi Yamamoto Date: Wed, 22 Jan 2025 12:34:34 +0900 Subject: [PATCH] WIP: pypi upload by github actions --- .github/workflows/ci.yaml | 81 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b46d59b..6ea4e13 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,12 +6,13 @@ name: Python package on: push: branches: [ master ] + tags: + - 'v*' pull_request: branches: [ master ] jobs: - build: - + test: runs-on: ${{ matrix.os }} strategy: matrix: @@ -49,3 +50,79 @@ jobs: run: | pip install pytest pytest + + build-for-publish: + name: Build distribution 📦 + runs-on: ubuntu-latest + # if: "startsWith(github.ref, 'refs/tags')" + needs: test + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: true + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade build + + - name: Build a source tarball and wheel + run: python -m build . + + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build-for-publish + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/pyopenjtalk + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + + publish-to-testpypi: + name: Publish Python 🐍 distribution 📦 to TestPyPI + needs: + - build-for-publish + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/pyopenjtalk + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + verbose: true