Skip to content

Commit

Permalink
Change pypi_publish.yml to publish_sdist_to_pypi.yml (#895)
Browse files Browse the repository at this point in the history
- 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 <vinnam.kim@intel.com>
  • Loading branch information
vinnamkim authored Mar 28, 2023
1 parent ce23fca commit c851c52
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 41 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/publish_sdist_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -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/
41 changes: 0 additions & 41 deletions .github/workflows/pypi_publish.yml

This file was deleted.

0 comments on commit c851c52

Please sign in to comment.