Skip to content
Merged
63 changes: 63 additions & 0 deletions .github/workflows/organize_and_generate_testing_report.yaml
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions .github/workflows/prepare_test_items.yaml
Original file line number Diff line number Diff line change
@@ -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 }})"

98 changes: 98 additions & 0 deletions .github/workflows/run_test_items_via_pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
############################################################################
#
# Workflow Description:
# 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:
# * 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

52 changes: 52 additions & 0 deletions .github/workflows/upload_code_report_to_codacy.yaml
Original file line number Diff line number Diff line change
@@ -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

72 changes: 72 additions & 0 deletions .github/workflows/upload_test_report_to_codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
############################################################################
#
# Workflow Description:
# Upload the testing coverage reports to Codecov.
#
# Workflow input parameters:
# * 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.
#
############################################################################

name: Upload test report to Codecov

on:
workflow_call:
inputs:
download_path:
description: "The path to download testing coverage reports via 'actions/download-artifact@v3'."
required: true
type: string
codecov_flags:
description: "The flags of the testing coverage report for Codecov."
required: true
type: string
codecov_name:
description: "The name of the testing coverage report for Codecov."
required: true
type: string

secrets:
codecov_token:
description: "The API token for uploading testing coverage report to Codecov."
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