From e02afb16806535ca0ea6c6067874585545c93930 Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:22:58 +0800 Subject: [PATCH 1/8] [New Feature] (config) Add configuration of reusable workflow about getting all test items for GitHub Action. --- .github/workflows/prepare_test_items.yaml | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/prepare_test_items.yaml diff --git a/.github/workflows/prepare_test_items.yaml b/.github/workflows/prepare_test_items.yaml new file mode 100644 index 00000000..3e3d43d5 --- /dev/null +++ b/.github/workflows/prepare_test_items.yaml @@ -0,0 +1,47 @@ +############################################################################ +# +# Workflow Description: +# Run a specific shell script to get all test items. +# +# Workflow input parameters: +# * shell_path: The file path of shell script which gets all the test items. +# * shell_arg: The arguments of the shell script which gets all the test items. +# +# Workflow running output: +# Yes, it has running result output. The output is the paths of all test items. +# +############################################################################ + +name: Prepare test items + +on: + workflow_call: + inputs: + shell_path: + description: "The file path of shell script which gets all the test items." + required: true + type: string + shell_arg: + description: "The arguments of the shell script which gets all the test items." + required: true + type: string + outputs: + all_test_items: + description: "The output string about all test items it needs to run." + value: ${{ jobs.prep-testbed_get_test_items.outputs.matrix }} + + +jobs: + prep-testbed_get_test_items: + name: Prepare all test items + runs-on: ubuntu-latest + # Map the job outputs to step outputs + outputs: + matrix: ${{ steps.set-matrix.outputs.all_test_items }} + steps: + - uses: actions/checkout@v3 + - id: set-matrix + run: | + sudo apt-get install jq + echo "::set-output name=all_test_items::$(bash ${{ inputs.shell_path }} ${{ inputs.shell_arg }})" + From 9e19365b37dbb36eb80f01abc6af81d99efcf372 Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:34:57 +0800 Subject: [PATCH 2/8] [New Feature] (config) Add configuration of reusable workflow about run test with test items via PyTest for GitHub Action. --- .../workflows/run_test_items_via_pytest.yaml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/run_test_items_via_pytest.yaml diff --git a/.github/workflows/run_test_items_via_pytest.yaml b/.github/workflows/run_test_items_via_pytest.yaml new file mode 100644 index 00000000..1afb4fca --- /dev/null +++ b/.github/workflows/run_test_items_via_pytest.yaml @@ -0,0 +1,98 @@ +############################################################################ +# +# Workflow Description: +# Run testing by specific type with all test items and generate its testing +# coverage report (it would save reports by 'actions/upload-artifact@v3'). +# +# Workflow input parameters: +# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'. +# * all_test_items_paths: The target paths of test items under test. +# +# Workflow running output: +# No, but it would save the testing coverage reports to provide after-process to organize and record. +# +############################################################################ + +name: Run test items via PyTest + +on: + workflow_call: + inputs: + test_type: + description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + required: true + type: string + all_test_items_paths: + description: "The target paths of test items under test." + required: true + type: string + + +jobs: + run_test_items: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + python-version: [3.6,3.7,3.8,3.9,'3.10'] + os: [ubuntu-18.04,ubuntu-20.04,ubuntu-22.04, macos-10.15,macos-11,macos-12] + exclude: + - os: ubuntu-18.04 + python-version: 3.6 + - os: ubuntu-18.04 + python-version: 3.9 + - os: ubuntu-18.04 + python-version: '3.10' + - os: ubuntu-20.04 + python-version: 3.8 + - os: ubuntu-20.04 + python-version: 3.9 + - os: ubuntu-22.04 + python-version: 3.6 + - os: macos-10.15 + python-version: 3.6 + - os: macos-10.15 + python-version: 3.8 + - os: macos-11 + python-version: 3.6 + - os: macos-11 + python-version: 3.9 + - os: macos-12 + python-version: 3.6 + test-path: ${{fromJson(inputs.all_test_items_paths)}} + + steps: + - uses: actions/checkout@v2 + + - name: Install Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + +# - name: Install dependencies by cloning from GitHub MultiRunnable +# run: | +# git clone https://github.com/Chisanan232/multirunnable.git -b master ./multirunnable +# sudo python ./multirunnable/setup.py install +# pip install -r ./multirunnable/dev-requirements.txt + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install -U pip + pip install -U -r ./requirements/requirements.txt + pip install -U -r ./requirements/requirements-test.txt + + - name: Run tests with pytest + run: pytest ${{ matrix.test-path }} + continue-on-error: true + + - name: Rename the code coverage result file + run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }} + + - name: Upload code coverage result file + uses: actions/upload-artifact@v3 + with: + name: coverage + path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }} + if-no-files-found: error + From f78b91b144cf171908a16f6fbd08d86e9f8bda6f Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:36:03 +0800 Subject: [PATCH 3/8] [Breaking Change] (config) Modify the workflow description info. --- .github/workflows/run_test_items_via_pytest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_test_items_via_pytest.yaml b/.github/workflows/run_test_items_via_pytest.yaml index 1afb4fca..6d640385 100644 --- a/.github/workflows/run_test_items_via_pytest.yaml +++ b/.github/workflows/run_test_items_via_pytest.yaml @@ -1,7 +1,7 @@ ############################################################################ # # Workflow Description: -# Run testing by specific type with all test items and generate its testing +# Run testing by specific type with all test items via PyTest and generate its testing # coverage report (it would save reports by 'actions/upload-artifact@v3'). # # Workflow input parameters: From 476240689519547867a91cf6c7b3a5c63036ef6f Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:38:49 +0800 Subject: [PATCH 4/8] [New Feature] (config) Add configuration of reusable workflow about organizing and generate testing coverage report for GitHub Action. --- .../organize_and_generate_testing_report.yaml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/organize_and_generate_testing_report.yaml diff --git a/.github/workflows/organize_and_generate_testing_report.yaml b/.github/workflows/organize_and_generate_testing_report.yaml new file mode 100644 index 00000000..87fc7fd7 --- /dev/null +++ b/.github/workflows/organize_and_generate_testing_report.yaml @@ -0,0 +1,63 @@ +############################################################################ +# +# Workflow Description: +# Organize all the testing coverage reports. (it would save reports by 'actions/upload-artifact@v3'). +# +# Workflow input parameters: +# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'. +# +# Workflow running output: +# No, but it would save the testing coverage reports (coverage.xml) to provide after-process to organize and record. +# +############################################################################ + +name: Upload test report to Codecov + +on: + workflow_call: + inputs: + test_type: + description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + required: true + type: string + + +jobs: + organize_and_generate_test_report: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Download code coverage result file + uses: actions/download-artifact@v3 + with: + name: coverage + path: .coverage.${{ inputs.test_type }}* + + - name: Setup Python 3.10 in Ubuntu OS + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Install Python tool 'coverage' + run: | + python3 -m pip install --upgrade pip + pip3 install -U pip + pip3 install coverage + + - name: Combine all code coverage result files + run: coverage combine .coverage.* + + - name: Report testing coverage of project code + run: coverage report -m + + - name: Generate testing report for Codacy + run: coverage xml + + - name: Upload testing coverage report + uses: actions/upload-artifact@v3 + with: + name: project_coverage_report + path: coverage.xml + if-no-files-found: error From ba9816d36dfb6dc635854b1466d1f4db12fc4877 Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:43:13 +0800 Subject: [PATCH 5/8] [New Feature] (config) Add configuration of reusable workflow about uploading testing coverage report to Codecov for GitHub Action. --- .../upload_test_report_to_codecov.yaml | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/upload_test_report_to_codecov.yaml diff --git a/.github/workflows/upload_test_report_to_codecov.yaml b/.github/workflows/upload_test_report_to_codecov.yaml new file mode 100644 index 00000000..40b5c2b3 --- /dev/null +++ b/.github/workflows/upload_test_report_to_codecov.yaml @@ -0,0 +1,67 @@ +############################################################################ +# +# Workflow Description: +# Upload the testing coverage reports to Codecov. +# +# Workflow input parameters: +# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'. +# * codecov_flags: The flags of the testing coverage report for Codecov. +# * codecov_name: The name of the testing coverage report for Codecov. +# +# Workflow running output: +# No and do nothing. +# +############################################################################ + +name: Upload test report to Codecov + +on: + workflow_call: + inputs: + download_path: + description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + required: true + type: string + codecov_flags: + description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + required: true + type: string + codecov_name: + description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + required: true + type: string + + secrets: + codecov_token: + required: true + + +jobs: + upload_report_to_codecov: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Download code coverage result file + uses: actions/download-artifact@v3 + with: + name: project_coverage_report + path: ${{ inputs.download_path }} + + - name: Upload coverage report to platform Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.codecov_token }} # not required for public repos + files: coverage.xml # optional + flags: ${{ inputs.codecov_flags }} # optional + name: ${{ inputs.codecov_name }} # optional + fail_ci_if_error: true # optional (default = false) + verbose: true # optional (default = false) + + - name: Upload testing coverage report + uses: actions/upload-artifact@v3 + with: + name: project_coverage_report + path: coverage.xml + if-no-files-found: error From f996875db1444e14302b780e7df3d6e44e8a0705 Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:44:13 +0800 Subject: [PATCH 6/8] [Bug Fix] (config) Modify the description of input parameters. --- .github/workflows/upload_test_report_to_codecov.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upload_test_report_to_codecov.yaml b/.github/workflows/upload_test_report_to_codecov.yaml index 40b5c2b3..c89d1a8f 100644 --- a/.github/workflows/upload_test_report_to_codecov.yaml +++ b/.github/workflows/upload_test_report_to_codecov.yaml @@ -19,15 +19,15 @@ on: workflow_call: inputs: download_path: - description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + description: "The path to download testing coverage reports via 'actions/download-artifact@v3'." required: true type: string codecov_flags: - description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + description: "The flags of the testing coverage report for Codecov." required: true type: string codecov_name: - description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'." + description: "The name of the testing coverage report for Codecov." required: true type: string From 2a7f945bf4dddc5aee1d16b6da5dece9e5e4a39d Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:48:15 +0800 Subject: [PATCH 7/8] [Breaking Change] (config) Add input parameter description for option 'secrets.codecov_token'. --- .github/workflows/upload_test_report_to_codecov.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upload_test_report_to_codecov.yaml b/.github/workflows/upload_test_report_to_codecov.yaml index c89d1a8f..d3498de7 100644 --- a/.github/workflows/upload_test_report_to_codecov.yaml +++ b/.github/workflows/upload_test_report_to_codecov.yaml @@ -4,9 +4,13 @@ # Upload the testing coverage reports to Codecov. # # Workflow input parameters: -# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'. -# * codecov_flags: The flags of the testing coverage report for Codecov. -# * codecov_name: The name of the testing coverage report for Codecov. +# * General arguments: +# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'. +# * codecov_flags: The flags of the testing coverage report for Codecov. +# * codecov_name: The name of the testing coverage report for Codecov. +# +# * Secret arguments: +# * codecov_token: The API token for uploading testing coverage report to Codecov. # # Workflow running output: # No and do nothing. @@ -33,6 +37,7 @@ on: secrets: codecov_token: + description: "The API token for uploading testing coverage report to Codecov." required: true From 6f8b7120f6db52b78cae19a93a66383acba9343d Mon Sep 17 00:00:00 2001 From: Chisanan232 Date: Wed, 17 Aug 2022 09:48:47 +0800 Subject: [PATCH 8/8] [New Feature] (config) Add configuration of reusable workflow about uploading testing coverage report to Codacy for GitHub Action. --- .../upload_code_report_to_codacy.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/upload_code_report_to_codacy.yaml diff --git a/.github/workflows/upload_code_report_to_codacy.yaml b/.github/workflows/upload_code_report_to_codacy.yaml new file mode 100644 index 00000000..90b1185b --- /dev/null +++ b/.github/workflows/upload_code_report_to_codacy.yaml @@ -0,0 +1,52 @@ +############################################################################ +# +# Workflow Description: +# Upload the testing coverage reports to Codacy. +# +# Workflow input parameters: +# * General arguments: +# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'. +# +# * Secret arguments: +# * codacy_token: The API token for uploading testing coverage report to Codacy. +# +# Workflow running output: +# No and do nothing. +# +############################################################################ + +name: Upload code detail report to Codacy + +on: + workflow_call: + inputs: + download_path: + description: "The path to download testing coverage reports via 'actions/download-artifact@v3'." + required: true + type: string + + secrets: + codacy_token: + description: "The API token for uploading testing coverage report to Codacy." + required: true + + +jobs: + upload_code_to_codacy_check_quality: + runs-on: ubuntu-latest + steps: + - name: Download testing coverage report + uses: actions/download-artifact@v3 + with: + name: project_coverage_report + path: ${{ inputs.download_path }} + + - name: Generate testing report for Codacy + run: mv ./coverage.xml ./cobertura.xml + + - name: Upload testing report to Codacy + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.codacy_token }} + coverage-reports: cobertura.xml +