From c851c524f3fb6eb17729ad2eac9c8c1d85953850 Mon Sep 17 00:00:00 2001 From: Vinnam Kim Date: Tue, 28 Mar 2023 10:24:01 +0900 Subject: [PATCH] Change pypi_publish.yml to publish_sdist_to_pypi.yml (#895) - Add if-else branching according to tag name for publishing to PyPI or TestPyPI - Fix to publish source distribution only - Upload source distribution to Github Release page too Signed-off-by: Kim, Vinnam --- .github/workflows/publish_sdist_to_pypi.yml | 57 +++++++++++++++++++++ .github/workflows/pypi_publish.yml | 41 --------------- 2 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/publish_sdist_to_pypi.yml delete mode 100644 .github/workflows/pypi_publish.yml diff --git a/.github/workflows/publish_sdist_to_pypi.yml b/.github/workflows/publish_sdist_to_pypi.yml new file mode 100644 index 0000000000..245bb49fb2 --- /dev/null +++ b/.github/workflows/publish_sdist_to_pypi.yml @@ -0,0 +1,57 @@ +name: Publish Source Distribution to PyPI + +on: + release: + types: [published] + +jobs: + publish-sdist-to-pypi: + environment: pypi + name: Publish Source Distribution to PyPI + runs-on: ubuntu-latest + permissions: write-all + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install pypa/build + run: >- + python -m + pip install + build + --user + - name: Build a source tarball + run: >- + python -m + build + --sdist + --outdir dist/ + . + - name: Upload package distributions to github + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: dist/* + tag: ${{ github.ref }} + overwrite: true + file_glob: true + - name: Check tag to determine where to publish the source distribution to PyPI or TestPyPI + id: check-tag + uses: actions-ecosystem/action-regex-match@v2 + with: + text: ${{ github.ref }} + regex: '^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$' + - name: Publish package distributions to PyPI + if: ${{ steps.check-tag.outputs.match != '' }} + uses: pypa/gh-action-pypi-publish@v1.7.1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + - name: Publish package distributions to TestPyPI + if: ${{ steps.check-tag.outputs.match == '' }} + uses: pypa/gh-action-pypi-publish@v1.7.1 + with: + password: ${{ secrets.TESTPYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ diff --git a/.github/workflows/pypi_publish.yml b/.github/workflows/pypi_publish.yml deleted file mode 100644 index 9745b5d715..0000000000 --- a/.github/workflows/pypi_publish.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Publish to PyPI - -on: - release: - types: [published] - -jobs: - pypi-publish: - environment: pypi - name: Upload release to PyPI - runs-on: ubuntu-latest - steps: - - name: Test - env: - TEST_SECRET: ${{ secrets.PYPI_API_TOKEN }} - run: | - echo ${TEST_SECRET} - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Python 3.9 - uses: actions/setup-python@v3 - with: - python-version: "3.9" - - name: Install pypa/build - run: >- - python -m - pip install - build - --user - - name: Build a binary wheel and a source tarball - run: >- - python -m - build - --sdist - --wheel - --outdir dist/ - . - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@v1.7.1 - with: - password: ${{ secrets.PYPI_API_TOKEN }}