Skip to content

Commit 79c5629

Browse files
authored
Merge pull request #33 from Chisanan232/develop
🎉🎊🍾 [New Feature] (code + config) Add GitHub Action reusable workflow about pushing Python package to PyPI.
2 parents d300baf + c3fe3ba commit 79c5629

File tree

7 files changed

+140
-46
lines changed

7 files changed

+140
-46
lines changed

.github/workflows/build_git-tag_and_create_github-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
uses: actions/checkout@v3
7676

7777
- name: Download shell script for checking input parameters
78-
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/build_git-tag_or_create_github-release.sh --output ./scripts/ci/build_git-tag_or_create_github-release.sh
78+
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/build_git-tag_or_create_github-release.sh --output ./scripts/ci/build_git-tag_or_create_github-release.sh
7979

8080
# This flow for the project type is Python project
8181
- name: Build git tag and create GitHub release for Python project

.github/workflows/organize_and_generate_test_cov_reports.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
5353
- name: Combine all testing coverage data files with test type and runtime OS, and convert to XML format file finally
5454
run: |
55-
curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/combine_coverage_reports.sh --output ./scripts/ci/combine_coverage_reports.sh
55+
curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/combine_coverage_reports.sh --output ./scripts/ci/combine_coverage_reports.sh
5656
bash ./scripts/ci/combine_coverage_reports.sh ${{ inputs.test_type }}
5757
5858
- name: Upload testing coverage report (.coverage)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 }}

.github/workflows/test_python_project_ci_one-test.yaml

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,47 +113,15 @@ jobs:
113113
debug_mode: true
114114

115115

116-
fake_build_pkg_and_push_to_pypi:
117-
# name: Check about it could work finely by installing the Python package with setup.py file
116+
push_python_pkg_to_pypi:
117+
# name: Upload the Python package files which has been compiled to PyPi
118+
if: github.event_name == 'push' && github.ref_name == 'release'
118119
needs: build_git-tag_and_create_github-release
119-
if: github.event_name == 'push'
120-
runs-on: ubuntu-latest
121-
env:
122-
RELEASE_TYPE: ${{ needs.build_git-tag_and_create_github-release.outputs.python_release_version }}
123-
steps:
124-
- name: Checkout
125-
uses: actions/checkout@v3
126-
127-
- name: Check it whether get the output of previous one job which has version info or not
128-
run: bash scripts/ci/check_getting_output.sh
129-
# run: |
130-
# release_version=$(echo $RELEASE_TYPE)
131-
# if [ "$release_version" != "" ]; then
132-
# echo "📬🎉🍻 It gets data which is release version info!"
133-
# exit 0
134-
# else
135-
# echo "📭🙈 It doesn't get any data which is release version info."
136-
# exit 1
137-
# fi
138-
139-
- name: For testing about getting the software version info
140-
run: |
141-
echo "Release version: $RELEASE_TYPE"
142-
143-
144-
# compile_and_build_python_pkg:
145-
## name: Compile the Python source code and build it as Python package files
146-
# if: github.event_name == 'push' && github.ref_name == 'master'
147-
# needs: pre-building_check
148-
# uses: ./.github/workflows/build_package.yaml
149-
150-
151-
# push_python_pkg_to_pypi:
152-
## name: Upload the Python package files which has been compiled to PyPi
153-
# if: github.event_name == 'push' && github.ref_name == 'master'
154-
# needs: compile_and_build_python_pkg
155-
# uses: ./.github/workflows/push_pkg_to_pypi.yaml
156-
# secrets:
157-
# pypi_user: ${{ secrets.PYPI_USERNAME }}
158-
# pypi_token: ${{ secrets.PYPI_PASSWORD }}
120+
uses: ./.github/workflows/push_pkg_to_pypi.yaml
121+
with:
122+
release-type: ${{ needs.build_git-tag_and_create_github-release.outputs.python_release_version }}
123+
push-to-PyPI: test
124+
secrets:
125+
pypi_user: ${{ secrets.PYPI_USERNAME }}
126+
pypi_token: ${{ secrets.PYPI_PASSWORD }}
159127

.github/workflows/upload_test_cov_report.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
uses: actions/checkout@v3
8484

8585
- name: Download shell script for checking input parameters
86-
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/check-input-params.sh --output ./scripts/ci/check-input-params.sh
86+
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/check-input-params.sh --output ./scripts/ci/check-input-params.sh
8787

8888
- name: Check the workflow input parameter
8989
run: |

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The usage of each workflow template.
3232
* [_upload_test_cov_report.yaml_](#upload_test_cov_reportyaml)
3333
* [_pre-building_test.yaml_](#pre-building_testyaml)
3434
* [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml)
35+
* [_push_pkg_to_pypi.yaml_](#push_pkg_to_pypiyaml)
3536

3637
<hr>
3738

@@ -341,3 +342,44 @@ The badge it generates:
341342
342343
[![Release](https://img.shields.io/github/release/Chisanan232/GitHub-Action-Template-Python.svg?label=Release&logo=github)](https://github.com/Chisanan232/GitHub-Action-Template-Python/releases)
343344
345+
<hr>
346+
347+
### _push_pkg_to_pypi.yaml_
348+
349+
* Description: Compile source code and push the Python package to PyPI. (Official release the Python package)
350+
* Options:
351+
352+
It has 2 different types option could use:
353+
354+
_General option_:
355+
356+
| option name | data type | optional or required | function content |
357+
|--------------|-----------|-------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
358+
| release-type | string | Required | The type of release processing. It has 2 type options: 'Official-Release' or 'Pre-Release'. It won't push the package to PyPI if it's 'Pre-Release'. |
359+
| push-to-PyPI | string | Optional, Default value is _empty string_ | Push Python package to official PyPI or test PyPI. It has 2 type options: 'official' or 'test'. |
360+
361+
_Secret option_:
362+
363+
| option name | option is optional or required | function content |
364+
|-------------|--------------------------------|-----------------------------|
365+
| PyPI_user | Required | The username of PyPI. |
366+
| PyPI_token | Required | The password token of PyPI. |
367+
368+
* Output:
369+
370+
No, nothing at all.
371+
372+
* How to use it?
373+
374+
```yaml
375+
push_python_pkg_to_pypi:
376+
# name: Upload the Python package files which has been compiled to PyPi
377+
uses: ./.github/workflows/push_pkg_to_pypi.yaml
378+
with:
379+
release-type: 'Official-Release'
380+
push-to-PyPI: test
381+
secrets:
382+
pypi_user: ${{ secrets.PYPI_USERNAME }}
383+
pypi_token: ${{ secrets.PYPI_PASSWORD }}
384+
```
385+

test_gh_workflow/__pkg_info__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.0-alpha1.post1"
1+
__version__ = "0.2.0"

0 commit comments

Comments
 (0)