diff --git a/.github/workflows/pre-building_test.yaml b/.github/workflows/pre-building_test.yaml new file mode 100644 index 00000000..65642d96 --- /dev/null +++ b/.github/workflows/pre-building_test.yaml @@ -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 }} + 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 diff --git a/README.md b/README.md index 2df6bf5f..48bad357 100644 --- a/README.md +++ b/README.md @@ -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)