Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/pre-building_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
###################################################################################################################
#
# Workflow Description:
# Test Python package by simple way, i.e., import modules, after running setup.py script to install package.
#
# Workflow input parameters:
# * General arguments:
# * python_package_name: The Python package name.
# * test_import_package_code_1: Test for importing the Python package.
# * test_import_package_code_2: Test for importing the Python package.
# * test_import_package_code_3: Run a Python script for testing the Python package.
# * test_python_script: Test for importing the Python package.
#
# Workflow running output:
# No and do nothing.
#
###################################################################################################################

name: Running pre-testing before building with running setup.py script

on:
workflow_call:
inputs:
python_package_name:
description: "The Python package name."
required: true
type: string
test_import_package_code_1:
description: "Test for importing the Python package."
required: true
type: string
test_import_package_code_2:
description: "Test for importing the Python package."
required: false
type: string
test_import_package_code_3:
description: "Test for importing the Python package."
required: false
type: string
test_python_script:
description: "Run a Python script for testing the Python package."
required: false
type: string


jobs:
pre-building_check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python 3.10 in Ubuntu OS
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -U pip
pip3 install -U setuptools
pip3 install wheel
pip install -U -r ./requirements/requirements-test.txt

- name: Install Python package by setup.py
run: python3 setup.py install --user || exit 1

- name: Show the Python package information
run: pip3 show ${{ inputs.python_package_name }}

- name: Test to run script with package '${{ inputs.python_package_name }}' in command lines
run: |
${{ inputs.test_import_package_code_1 }}
${{ inputs.test_import_package_code_2 }}
${{ inputs.test_import_package_code_3 }}
shell: python

- name: Test to run script with package '${{ inputs.python_package_name }}' with Python file
run: python3 ${{ inputs.test_python_script }}

23 changes: 12 additions & 11 deletions .github/workflows/test_python_project_ci_multi-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,22 @@ jobs:
upload-to-codacy: true


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


build_git-tag_and_create_github-release:
# name: Build git tag and GitHub release if it needs
needs: [codecov_finish, coveralls_finish, codacy_finish]
needs: pre-building_test
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
with:
project_type: python-package
Expand Down
23 changes: 11 additions & 12 deletions .github/workflows/test_python_project_ci_one-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,21 @@ jobs:
upload-to-codacy: true


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


build_git-tag_and_create_github-release:
# name: Build git tag and GitHub release if it needs
needs: [coveralls_finish, codecov_finish, codacy_finish]
needs: pre-building_test
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
with:
project_type: python-package
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The usage of each workflow template.
* [_run_test_items_via_pytest.yaml_](#run_test_items_via_pytestyaml)
* [_organize_and_generate_test_cov_reports.yaml_](#organize_and_generate_test_cov_reportsyaml)
* [_upload_test_cov_report.yaml_](#upload_test_cov_reportyaml)
* [_pre-building_test.yaml_](#pre-building_testyaml)
* [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml)

<hr>
Expand Down Expand Up @@ -255,6 +256,38 @@ Nothing.

<hr>

### _pre-building_test.yaml_

* Description: Test package by simple way after running setup.py script to install Python package
* Options:

| option name | data type | optional or required | function content |
|----------------------------|-----------|-------------------------------------------|-----------------------------------------------------|
| python_package_name | string | Required | The Python package name. |
| test_import_package_code_1 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
| test_import_package_code_2 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
| test_import_package_code_3 | string | Optional, Default value is _empty string_ | Test for importing the Python package. |
| test_python_script | string | Optional, Default value is _empty string_ | Run a Python script for testing the Python package. |

* Output:

No, nothing at all.

* How to use it?

```yaml
pre-building_test:
# name: Check about it could work finely by installing the Python package with setup.py file
uses: ./.github/workflows/pre-building_test.yaml
with:
python_package_name: Test-GitHub-Action-workflow
test_import_package_code_1: from test_gh_workflow import sample
test_import_package_code_2: sample.hello_python()
test_python_script: ./scripts/ci/test/test_pgk_install.py
```

<hr>

### _build_git-tag_and_create_github-release.yaml_

* Description: Build a git tag on a specific commit in every git branch. And create GitHub release if current git branch is 'master'.
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci/test/test_pgk_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from test_gh_workflow import sample

sample.hello_python()
46 changes: 46 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import setuptools
import os


here = os.path.abspath(os.path.dirname(__file__))


about = {}
with open(os.path.join(here, "test_gh_workflow", "__pkg_info__.py"), "r", encoding="utf-8") as f:
exec(f.read(), about)


with open("README.md", "r") as fh:
readme = fh.read()


setuptools.setup(
name="Test GitHub Action workflow",
version=about["__version__"],
author="Bryant Liu",
license="Apache License 2.0",
description="This is a testing package of GitHub Action reusable workflow",
long_description=readme,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(exclude=("test",)),
package_dir={"test_gh_workflow": "test_gh_workflow"},
zip_safe=False,
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
],
python_requires='>=3.6',
project_urls={
"Source": "https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python",
},
)