From a296b8865bfb2fc992cded5830dd50df847ca26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Tue, 29 Nov 2022 10:06:58 +0800 Subject: [PATCH 01/10] [Breaking Change] (config) Add option 'if-no-files-found' of action 'download-artifact'. --- .github/workflows/organize_and_generate_test_cov_reports.yaml | 1 + .github/workflows/upload_test_cov_report.yaml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.github/workflows/organize_and_generate_test_cov_reports.yaml b/.github/workflows/organize_and_generate_test_cov_reports.yaml index 264f7b9a..b959589c 100644 --- a/.github/workflows/organize_and_generate_test_cov_reports.yaml +++ b/.github/workflows/organize_and_generate_test_cov_reports.yaml @@ -38,6 +38,7 @@ jobs: with: name: coverage path: ./ + if-no-files-found: error - name: Setup Python 3.10 in Ubuntu OS uses: actions/setup-python@v4 diff --git a/.github/workflows/upload_test_cov_report.yaml b/.github/workflows/upload_test_cov_report.yaml index 92ee62b5..552c2c97 100644 --- a/.github/workflows/upload_test_cov_report.yaml +++ b/.github/workflows/upload_test_cov_report.yaml @@ -101,12 +101,14 @@ jobs: with: name: test_coverage_data_file path: ${{ inputs.download_path }} + if-no-files-found: error - name: Download code coverage result files which has be handled by different test type process uses: actions/download-artifact@v3 with: name: test_coverage_xml_report path: ${{ inputs.download_path }} + if-no-files-found: error - name: Install Python 3.10 if: ${{ inputs.upload-to-codecov == true || inputs.upload-to-coveralls == true }} From ff6f9a00fb73df6424b8bb957f3440a864ea8add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:30:49 +0800 Subject: [PATCH 02/10] [Test] (code) Add setup.py for testing. --- setup.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..0e166029 --- /dev/null +++ b/setup.py @@ -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", + }, +) From 512633887c92145d05cb3e66ec3ad375f0f9191d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:31:18 +0800 Subject: [PATCH 03/10] [Test] (script) Add Python script for testing. --- scripts/ci/test/test_pgk_install.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 scripts/ci/test/test_pgk_install.py diff --git a/scripts/ci/test/test_pgk_install.py b/scripts/ci/test/test_pgk_install.py new file mode 100644 index 00000000..3c2a4ca1 --- /dev/null +++ b/scripts/ci/test/test_pgk_install.py @@ -0,0 +1,3 @@ +from test_gh_workflow import sample + +sample.hello_python() From 5b326cfa024f7b23ffcc117ab7cd64aac17bb5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:32:05 +0800 Subject: [PATCH 04/10] [New Feature] (config) Add new GitHub Action reusable workflow about pre-test before building package. --- .github/workflows/pre-building_test.yaml | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/pre-building_test.yaml diff --git a/.github/workflows/pre-building_test.yaml b/.github/workflows/pre-building_test.yaml new file mode 100644 index 00000000..86dc3054 --- /dev/null +++ b/.github/workflows/pre-building_test.yaml @@ -0,0 +1,78 @@ +############################################################################################## +# +# Workflow Description: +# Build the Python source code to be Python package. +# +# Workflow input parameters: +# * General arguments: +# * upload_artifact_name: The option 'name' of reusable action 'actions/upload-artifact@v3'. +# * upload_artifact_path: The option 'path' of reusable action 'actions/upload-artifact@v3'. +# +# Workflow running output: +# No and do nothing. +# +############################################################################################## + +name: Build and compile the code to be Python package + +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 SmoothCrawler with 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 }} + From 8089354af6e4969266d52226ff15c4c0fb054efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:32:38 +0800 Subject: [PATCH 05/10] [New Feature] (config) Import new reusable workflow setting. --- .../test_python_project_ci_multi-tests.yaml | 23 ++++++++++--------- .../test_python_project_ci_one-test.yaml | 23 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test_python_project_ci_multi-tests.yaml b/.github/workflows/test_python_project_ci_multi-tests.yaml index a072934a..d3712acc 100644 --- a/.github/workflows/test_python_project_ci_multi-tests.yaml +++ b/.github/workflows/test_python_project_ci_multi-tests.yaml @@ -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 diff --git a/.github/workflows/test_python_project_ci_one-test.yaml b/.github/workflows/test_python_project_ci_one-test.yaml index 5c074569..0aa29973 100644 --- a/.github/workflows/test_python_project_ci_one-test.yaml +++ b/.github/workflows/test_python_project_ci_one-test.yaml @@ -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 From 5bee5e6e87ac05f20208d20c153dd54ffdea6c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:40:09 +0800 Subject: [PATCH 06/10] [Bug Fix] (config) Remove invalid argument of action. --- .github/workflows/organize_and_generate_test_cov_reports.yaml | 1 - .github/workflows/upload_test_cov_report.yaml | 2 -- 2 files changed, 3 deletions(-) diff --git a/.github/workflows/organize_and_generate_test_cov_reports.yaml b/.github/workflows/organize_and_generate_test_cov_reports.yaml index b959589c..264f7b9a 100644 --- a/.github/workflows/organize_and_generate_test_cov_reports.yaml +++ b/.github/workflows/organize_and_generate_test_cov_reports.yaml @@ -38,7 +38,6 @@ jobs: with: name: coverage path: ./ - if-no-files-found: error - name: Setup Python 3.10 in Ubuntu OS uses: actions/setup-python@v4 diff --git a/.github/workflows/upload_test_cov_report.yaml b/.github/workflows/upload_test_cov_report.yaml index 552c2c97..92ee62b5 100644 --- a/.github/workflows/upload_test_cov_report.yaml +++ b/.github/workflows/upload_test_cov_report.yaml @@ -101,14 +101,12 @@ jobs: with: name: test_coverage_data_file path: ${{ inputs.download_path }} - if-no-files-found: error - name: Download code coverage result files which has be handled by different test type process uses: actions/download-artifact@v3 with: name: test_coverage_xml_report path: ${{ inputs.download_path }} - if-no-files-found: error - name: Install Python 3.10 if: ${{ inputs.upload-to-codecov == true || inputs.upload-to-coveralls == true }} From 5bd43f6d8bc48f70a8cccb95b39435ed29326eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:42:05 +0800 Subject: [PATCH 07/10] [Breaking Change] (config) Add usage description and modify step name. --- .github/workflows/pre-building_test.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-building_test.yaml b/.github/workflows/pre-building_test.yaml index 86dc3054..16958708 100644 --- a/.github/workflows/pre-building_test.yaml +++ b/.github/workflows/pre-building_test.yaml @@ -5,8 +5,11 @@ # # Workflow input parameters: # * General arguments: -# * upload_artifact_name: The option 'name' of reusable action 'actions/upload-artifact@v3'. -# * upload_artifact_path: The option 'path' of reusable action 'actions/upload-artifact@v3'. +# * 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. @@ -60,7 +63,7 @@ jobs: pip3 install wheel pip install -U -r ./requirements/requirements-test.txt - - name: Install SmoothCrawler with by setup.py + - name: Install Python package by setup.py run: python3 setup.py install --user || exit 1 - name: Show the Python package information From cddd995e76115194424dbdfabc7ad8f493ef72fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:56:36 +0800 Subject: [PATCH 08/10] [Docs] (docs) Add section of new reusable workflow 'pre-building_test.yaml'. --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 2df6bf5f..e6c86089 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ The usage of each workflow template. * [_organize_and_generate_test_cov_reports.yaml_](#organize_and_generate_test_cov_reportsyaml) * [_upload_test_cov_report.yaml_](#upload_test_cov_reportyaml) * [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml) +* [_pre-building_test.yaml_](#pre-building_testyaml)
@@ -255,6 +256,38 @@ Nothing.
+### _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 +``` + +
+ ### _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'. From 185439ee0ad44abbfd0062484af435a653cfe614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 09:58:10 +0800 Subject: [PATCH 09/10] [Docs] (docs) Modify the order of reusable workflows agenda. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6c86089..48bad357 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ 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) -* [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml) * [_pre-building_test.yaml_](#pre-building_testyaml) +* [_build_git-tag_and_create_github-release.yaml_](#build_git-tag_and_create_github-releaseyaml)
From 2a1c513f5fd20a5f063c365b25320de3892a0580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChisanan232=E2=80=9D?= Date: Wed, 30 Nov 2022 10:25:09 +0800 Subject: [PATCH 10/10] [Breaking Change] (config) Modify the workflow description. --- .github/workflows/pre-building_test.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pre-building_test.yaml b/.github/workflows/pre-building_test.yaml index 16958708..65642d96 100644 --- a/.github/workflows/pre-building_test.yaml +++ b/.github/workflows/pre-building_test.yaml @@ -1,7 +1,7 @@ -############################################################################################## +################################################################################################################### # # Workflow Description: -# Build the Python source code to be Python package. +# Test Python package by simple way, i.e., import modules, after running setup.py script to install package. # # Workflow input parameters: # * General arguments: @@ -14,9 +14,9 @@ # Workflow running output: # No and do nothing. # -############################################################################################## +################################################################################################################### -name: Build and compile the code to be Python package +name: Running pre-testing before building with running setup.py script on: workflow_call: