|
| 1 | +######################################################################################################################### |
| 2 | +# |
| 3 | +# Workflow Description: |
| 4 | +# Push the Python package to PyPI. (Official release the Python package) |
| 5 | +# |
| 6 | +# Workflow input parameters: |
| 7 | +# * General arguments: |
| 8 | +# * release-type: The type of release processing. It has 2 type options: 'Official-Release' or 'Pre-Release'. |
| 9 | +# It won't push the package to PyPI if it's 'Pre-Release'. |
| 10 | +# * push-to-PyPI: Push Python package to official PyPI or test PyPI. It has 2 type options: 'official' or 'test'. |
| 11 | +# |
| 12 | +# * Secret arguments: |
| 13 | +# * PyPI_user: The username of PyPI. |
| 14 | +# * PyPI_token: The password token of PyPI. |
| 15 | +# |
| 16 | +# Workflow running output: |
| 17 | +# No and do nothing. |
| 18 | +# |
| 19 | +######################################################################################################################### |
| 20 | + |
| 21 | +name: Push the Python package to PyPI |
| 22 | + |
| 23 | +on: |
| 24 | + workflow_call: |
| 25 | + inputs: |
| 26 | + release-type: |
| 27 | + description: "The type of release processing. It has 2 type options: 'Official-Release' or 'Pre-Release'. It won't |
| 28 | + push the package to PyPI if it's 'Pre-Release'." |
| 29 | + type: string |
| 30 | + required: true |
| 31 | + push-to-PyPI: |
| 32 | + description: "Push Python package to official PyPI or test PyPI. It has 2 type options: 'official' or 'test'." |
| 33 | + type: string |
| 34 | + required: false |
| 35 | + default: 'test' |
| 36 | + |
| 37 | + secrets: |
| 38 | + PyPI_user: |
| 39 | + description: "The username of PyPI." |
| 40 | + required: true |
| 41 | + PyPI_token: |
| 42 | + description: "The password token of PyPI." |
| 43 | + required: true |
| 44 | + |
| 45 | + |
| 46 | +jobs: |
| 47 | + push_to_PyPI: |
| 48 | + if: ${{ inputs.release-type == 'Official-Release' }} |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Download shell script for checking input parameters |
| 52 | + run: | |
| 53 | + curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/check_getting_output.sh --output ./scripts/ci/check_getting_output.sh |
| 54 | + bash ./scripts/ci/check_getting_output.sh |
| 55 | +
|
| 56 | + - name: Setup Python 3.10 in Ubuntu OS |
| 57 | + uses: actions/setup-python@v4 |
| 58 | + with: |
| 59 | + python-version: '3.10' |
| 60 | + |
| 61 | + - name: Install Python dependencies |
| 62 | + run: | |
| 63 | + python3 -m pip install --upgrade pip |
| 64 | + pip3 install -U pip |
| 65 | + pip3 install -U setuptools |
| 66 | + pip3 install wheel |
| 67 | + pip3 install twine |
| 68 | +
|
| 69 | + - name: Compile and package the code as Python package formatter |
| 70 | + run: python3 setup.py sdist bdist_wheel |
| 71 | + |
| 72 | + - name: Push Python package to test PyPI |
| 73 | + if: ${{ inputs.push-to-PyPI == 'test' }} |
| 74 | + run: python3 -m twine upload --repository testpypi ./dist/* |
| 75 | + env: |
| 76 | + TWINE_USERNAME: ${{ secrets.PyPI_user }} |
| 77 | + TWINE_PASSWORD: ${{ secrets.PyPI_token }} |
| 78 | + |
| 79 | + - name: Push Python package to official PyPI |
| 80 | + if: ${{ inputs.push-to-PyPI == 'official' }} |
| 81 | + run: python3 -m twine upload ./dist/* |
| 82 | + env: |
| 83 | + TWINE_USERNAME: ${{ secrets.PyPI_user }} |
| 84 | + TWINE_PASSWORD: ${{ secrets.PyPI_token }} |
0 commit comments