Skip to content

Commit d300baf

Browse files
authored
Merge pull request #32 from Chisanan232/develop
🎉🎊🍾 [New Feature] (config) Add new reusable workflow about pre-testing before building.
2 parents 992ae38 + 2a1c513 commit d300baf

File tree

6 files changed

+186
-23
lines changed

6 files changed

+186
-23
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
###################################################################################################################
2+
#
3+
# Workflow Description:
4+
# Test Python package by simple way, i.e., import modules, after running setup.py script to install package.
5+
#
6+
# Workflow input parameters:
7+
# * General arguments:
8+
# * python_package_name: The Python package name.
9+
# * test_import_package_code_1: Test for importing the Python package.
10+
# * test_import_package_code_2: Test for importing the Python package.
11+
# * test_import_package_code_3: Run a Python script for testing the Python package.
12+
# * test_python_script: Test for importing the Python package.
13+
#
14+
# Workflow running output:
15+
# No and do nothing.
16+
#
17+
###################################################################################################################
18+
19+
name: Running pre-testing before building with running setup.py script
20+
21+
on:
22+
workflow_call:
23+
inputs:
24+
python_package_name:
25+
description: "The Python package name."
26+
required: true
27+
type: string
28+
test_import_package_code_1:
29+
description: "Test for importing the Python package."
30+
required: true
31+
type: string
32+
test_import_package_code_2:
33+
description: "Test for importing the Python package."
34+
required: false
35+
type: string
36+
test_import_package_code_3:
37+
description: "Test for importing the Python package."
38+
required: false
39+
type: string
40+
test_python_script:
41+
description: "Run a Python script for testing the Python package."
42+
required: false
43+
type: string
44+
45+
46+
jobs:
47+
pre-building_check:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
53+
- name: Setup Python 3.10 in Ubuntu OS
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: '3.10'
57+
58+
- name: Install Python dependencies
59+
run: |
60+
python3 -m pip install --upgrade pip
61+
pip3 install -U pip
62+
pip3 install -U setuptools
63+
pip3 install wheel
64+
pip install -U -r ./requirements/requirements-test.txt
65+
66+
- name: Install Python package by setup.py
67+
run: python3 setup.py install --user || exit 1
68+
69+
- name: Show the Python package information
70+
run: pip3 show ${{ inputs.python_package_name }}
71+
72+
- name: Test to run script with package '${{ inputs.python_package_name }}' in command lines
73+
run: |
74+
${{ inputs.test_import_package_code_1 }}
75+
${{ inputs.test_import_package_code_2 }}
76+
${{ inputs.test_import_package_code_3 }}
77+
shell: python
78+
79+
- name: Test to run script with package '${{ inputs.python_package_name }}' with Python file
80+
run: python3 ${{ inputs.test_python_script }}
81+

.github/workflows/test_python_project_ci_multi-tests.yaml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,22 @@ jobs:
114114
upload-to-codacy: true
115115

116116

117-
# pre-building_check:
118-
## name: Check about it could work finely by installing the Python package with setup.py file
119-
# needs: [codecov_finish, codacy_finish]
120-
# uses: ./.github/workflows/pre-building_test_setup_package.yaml
121-
# with:
122-
# python_package_name: smoothcrawler
123-
# test_import_package_code_1: import smoothcrawler as mr
124-
# test_import_package_code_2: from smoothcrawler.crawler import SimpleCrawler
125-
# test_import_package_code_3: from smoothcrawler.components.data import BaseHTTPResponseParser, BaseDataHandler
126-
# test_python_script: ./scripts/test_crawler.py
117+
pre-building_test:
118+
# name: Check about it could work finely by installing the Python package with setup.py file
119+
if: github.event_name == 'push' && (github.ref_name == 'release' || github.ref_name == 'master')
120+
needs: [codecov_finish, coveralls_finish, codacy_finish]
121+
uses: ./.github/workflows/pre-building_test.yaml
122+
with:
123+
python_package_name: Test-GitHub-Action-workflow
124+
test_import_package_code_1: import test_gh_workflow
125+
test_import_package_code_2: from test_gh_workflow import sample
126+
test_import_package_code_3: sample.hello_python()
127+
test_python_script: ./scripts/ci/test/test_pgk_install.py
127128

128129

129130
build_git-tag_and_create_github-release:
130131
# name: Build git tag and GitHub release if it needs
131-
needs: [codecov_finish, coveralls_finish, codacy_finish]
132+
needs: pre-building_test
132133
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
133134
with:
134135
project_type: python-package

.github/workflows/test_python_project_ci_one-test.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,21 @@ jobs:
9090
upload-to-codacy: true
9191

9292

93-
# pre-building_check:
94-
## name: Check about it could work finely by installing the Python package with setup.py file
95-
# if: github.event_name == 'push' && (github.ref_name == 'release' || github.ref_name == 'master')
96-
# needs: [codecov_finish, codacy_finish]
97-
# uses: ./.github/workflows/pre-building_test_setup_package.yaml
98-
# with:
99-
# python_package_name: smoothcrawler
100-
# test_import_package_code_1: import smoothcrawler as mr
101-
# test_import_package_code_2: from smoothcrawler.crawler import SimpleCrawler
102-
# test_import_package_code_3: from smoothcrawler.components.data import BaseHTTPResponseParser, BaseDataHandler
103-
# test_python_script: ./scripts/test_crawler.py
93+
pre-building_test:
94+
# name: Check about it could work finely by installing the Python package with setup.py file
95+
needs: [codecov_finish, coveralls_finish, codacy_finish]
96+
uses: ./.github/workflows/pre-building_test.yaml
97+
with:
98+
python_package_name: Test-GitHub-Action-workflow
99+
test_import_package_code_1: import test_gh_workflow
100+
test_import_package_code_2: from test_gh_workflow import sample
101+
test_import_package_code_3: sample.hello_python()
102+
test_python_script: ./scripts/ci/test/test_pgk_install.py
104103

105104

106105
build_git-tag_and_create_github-release:
107106
# name: Build git tag and GitHub release if it needs
108-
needs: [coveralls_finish, codecov_finish, codacy_finish]
107+
needs: pre-building_test
109108
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
110109
with:
111110
project_type: python-package

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The usage of each workflow template.
3030
* [_run_test_items_via_pytest.yaml_](#run_test_items_via_pytestyaml)
3131
* [_organize_and_generate_test_cov_reports.yaml_](#organize_and_generate_test_cov_reportsyaml)
3232
* [_upload_test_cov_report.yaml_](#upload_test_cov_reportyaml)
33+
* [_pre-building_test.yaml_](#pre-building_testyaml)
3334
* [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml)
3435

3536
<hr>
@@ -255,6 +256,38 @@ Nothing.
255256
256257
<hr>
257258
259+
### _pre-building_test.yaml_
260+
261+
* Description: Test package by simple way after running setup.py script to install Python package
262+
* Options:
263+
264+
| option name | data type | optional or required | function content |
265+
|----------------------------|-----------|-------------------------------------------|-----------------------------------------------------|
266+
| python_package_name | string | Required | The Python package name. |
267+
| test_import_package_code_1 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
268+
| test_import_package_code_2 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
269+
| test_import_package_code_3 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
270+
| test_python_script | string | Optional, Default value is _empty string_ | Run a Python script for testing the Python package. |
271+
272+
* Output:
273+
274+
No, nothing at all.
275+
276+
* How to use it?
277+
278+
```yaml
279+
pre-building_test:
280+
# name: Check about it could work finely by installing the Python package with setup.py file
281+
uses: ./.github/workflows/pre-building_test.yaml
282+
with:
283+
python_package_name: Test-GitHub-Action-workflow
284+
test_import_package_code_1: from test_gh_workflow import sample
285+
test_import_package_code_2: sample.hello_python()
286+
test_python_script: ./scripts/ci/test/test_pgk_install.py
287+
```
288+
289+
<hr>
290+
258291
### _build_git-tag_and_create_github-release.yaml_
259292
260293
* Description: Build a git tag on a specific commit in every git branch. And create GitHub release if current git branch is 'master'.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from test_gh_workflow import sample
2+
3+
sample.hello_python()

setup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import setuptools
2+
import os
3+
4+
5+
here = os.path.abspath(os.path.dirname(__file__))
6+
7+
8+
about = {}
9+
with open(os.path.join(here, "test_gh_workflow", "__pkg_info__.py"), "r", encoding="utf-8") as f:
10+
exec(f.read(), about)
11+
12+
13+
with open("README.md", "r") as fh:
14+
readme = fh.read()
15+
16+
17+
setuptools.setup(
18+
name="Test GitHub Action workflow",
19+
version=about["__version__"],
20+
author="Bryant Liu",
21+
license="Apache License 2.0",
22+
description="This is a testing package of GitHub Action reusable workflow",
23+
long_description=readme,
24+
long_description_content_type="text/markdown",
25+
packages=setuptools.find_packages(exclude=("test",)),
26+
package_dir={"test_gh_workflow": "test_gh_workflow"},
27+
zip_safe=False,
28+
classifiers=[
29+
"Development Status :: 3 - Alpha",
30+
"Intended Audience :: Developers",
31+
"Topic :: Software Development :: Libraries :: Python Modules",
32+
"License :: OSI Approved :: Apache Software License",
33+
"Operating System :: OS Independent",
34+
"Programming Language :: Python :: 3",
35+
"Programming Language :: Python :: 3.6",
36+
"Programming Language :: Python :: 3.7",
37+
"Programming Language :: Python :: 3.8",
38+
"Programming Language :: Python :: 3.9",
39+
"Programming Language :: Python :: 3.10",
40+
"Programming Language :: Python :: 3.11",
41+
],
42+
python_requires='>=3.6',
43+
project_urls={
44+
"Source": "https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python",
45+
},
46+
)

0 commit comments

Comments
 (0)