Skip to content

Commit 8ce5155

Browse files
authored
Merge pull request #4 from Chisanan232/release
🎉🎊🍾 [New Feature] (config) Add reusable configurations for CI tool GitHub Action.
2 parents 07e2afa + 0d5c30e commit 8ce5155

File tree

5 files changed

+332
-0
lines changed

5 files changed

+332
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
############################################################################
2+
#
3+
# Workflow Description:
4+
# Organize all the testing coverage reports. (it would save reports by 'actions/upload-artifact@v3').
5+
#
6+
# Workflow input parameters:
7+
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
8+
#
9+
# Workflow running output:
10+
# No, but it would save the testing coverage reports (coverage.xml) to provide after-process to organize and record.
11+
#
12+
############################################################################
13+
14+
name: Upload test report to Codecov
15+
16+
on:
17+
workflow_call:
18+
inputs:
19+
test_type:
20+
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
21+
required: true
22+
type: string
23+
24+
25+
jobs:
26+
organize_and_generate_test_report:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v2
31+
32+
- name: Download code coverage result file
33+
uses: actions/download-artifact@v3
34+
with:
35+
name: coverage
36+
path: .coverage.${{ inputs.test_type }}*
37+
38+
- name: Setup Python 3.10 in Ubuntu OS
39+
uses: actions/setup-python@v2
40+
with:
41+
python-version: '3.10'
42+
43+
- name: Install Python tool 'coverage'
44+
run: |
45+
python3 -m pip install --upgrade pip
46+
pip3 install -U pip
47+
pip3 install coverage
48+
49+
- name: Combine all code coverage result files
50+
run: coverage combine .coverage.*
51+
52+
- name: Report testing coverage of project code
53+
run: coverage report -m
54+
55+
- name: Generate testing report for Codacy
56+
run: coverage xml
57+
58+
- name: Upload testing coverage report
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: project_coverage_report
62+
path: coverage.xml
63+
if-no-files-found: error
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
############################################################################
2+
#
3+
# Workflow Description:
4+
# Run a specific shell script to get all test items.
5+
#
6+
# Workflow input parameters:
7+
# * shell_path: The file path of shell script which gets all the test items.
8+
# * shell_arg: The arguments of the shell script which gets all the test items.
9+
#
10+
# Workflow running output:
11+
# Yes, it has running result output. The output is the paths of all test items.
12+
#
13+
############################################################################
14+
15+
name: Prepare test items
16+
17+
on:
18+
workflow_call:
19+
inputs:
20+
shell_path:
21+
description: "The file path of shell script which gets all the test items."
22+
required: true
23+
type: string
24+
shell_arg:
25+
description: "The arguments of the shell script which gets all the test items."
26+
required: true
27+
type: string
28+
outputs:
29+
all_test_items:
30+
description: "The output string about all test items it needs to run."
31+
value: ${{ jobs.prep-testbed_get_test_items.outputs.matrix }}
32+
33+
34+
jobs:
35+
prep-testbed_get_test_items:
36+
name: Prepare all test items
37+
runs-on: ubuntu-latest
38+
# Map the job outputs to step outputs
39+
outputs:
40+
matrix: ${{ steps.set-matrix.outputs.all_test_items }}
41+
steps:
42+
- uses: actions/checkout@v3
43+
- id: set-matrix
44+
run: |
45+
sudo apt-get install jq
46+
echo "::set-output name=all_test_items::$(bash ${{ inputs.shell_path }} ${{ inputs.shell_arg }})"
47+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
############################################################################
2+
#
3+
# Workflow Description:
4+
# Run testing by specific type with all test items via PyTest and generate its testing
5+
# coverage report (it would save reports by 'actions/upload-artifact@v3').
6+
#
7+
# Workflow input parameters:
8+
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
9+
# * all_test_items_paths: The target paths of test items under test.
10+
#
11+
# Workflow running output:
12+
# No, but it would save the testing coverage reports to provide after-process to organize and record.
13+
#
14+
############################################################################
15+
16+
name: Run test items via PyTest
17+
18+
on:
19+
workflow_call:
20+
inputs:
21+
test_type:
22+
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
23+
required: true
24+
type: string
25+
all_test_items_paths:
26+
description: "The target paths of test items under test."
27+
required: true
28+
type: string
29+
30+
31+
jobs:
32+
run_test_items:
33+
runs-on: ${{ matrix.os }}
34+
35+
strategy:
36+
matrix:
37+
python-version: [3.6,3.7,3.8,3.9,'3.10']
38+
os: [ubuntu-18.04,ubuntu-20.04,ubuntu-22.04, macos-10.15,macos-11,macos-12]
39+
exclude:
40+
- os: ubuntu-18.04
41+
python-version: 3.6
42+
- os: ubuntu-18.04
43+
python-version: 3.9
44+
- os: ubuntu-18.04
45+
python-version: '3.10'
46+
- os: ubuntu-20.04
47+
python-version: 3.8
48+
- os: ubuntu-20.04
49+
python-version: 3.9
50+
- os: ubuntu-22.04
51+
python-version: 3.6
52+
- os: macos-10.15
53+
python-version: 3.6
54+
- os: macos-10.15
55+
python-version: 3.8
56+
- os: macos-11
57+
python-version: 3.6
58+
- os: macos-11
59+
python-version: 3.9
60+
- os: macos-12
61+
python-version: 3.6
62+
test-path: ${{fromJson(inputs.all_test_items_paths)}}
63+
64+
steps:
65+
- uses: actions/checkout@v2
66+
67+
- name: Install Python ${{ matrix.python-version }}
68+
uses: actions/setup-python@v2
69+
with:
70+
python-version: ${{ matrix.python-version }}
71+
72+
# - name: Install dependencies by cloning from GitHub MultiRunnable
73+
# run: |
74+
# git clone https://github.com/Chisanan232/multirunnable.git -b master ./multirunnable
75+
# sudo python ./multirunnable/setup.py install
76+
# pip install -r ./multirunnable/dev-requirements.txt
77+
78+
- name: Install Python dependencies
79+
run: |
80+
python -m pip install --upgrade pip
81+
pip install -U pip
82+
pip install -U -r ./requirements/requirements.txt
83+
pip install -U -r ./requirements/requirements-test.txt
84+
85+
- name: Run tests with pytest
86+
run: pytest ${{ matrix.test-path }}
87+
continue-on-error: true
88+
89+
- name: Rename the code coverage result file
90+
run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
91+
92+
- name: Upload code coverage result file
93+
uses: actions/upload-artifact@v3
94+
with:
95+
name: coverage
96+
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
97+
if-no-files-found: error
98+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
############################################################################
2+
#
3+
# Workflow Description:
4+
# Upload the testing coverage reports to Codacy.
5+
#
6+
# Workflow input parameters:
7+
# * General arguments:
8+
# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'.
9+
#
10+
# * Secret arguments:
11+
# * codacy_token: The API token for uploading testing coverage report to Codacy.
12+
#
13+
# Workflow running output:
14+
# No and do nothing.
15+
#
16+
############################################################################
17+
18+
name: Upload code detail report to Codacy
19+
20+
on:
21+
workflow_call:
22+
inputs:
23+
download_path:
24+
description: "The path to download testing coverage reports via 'actions/download-artifact@v3'."
25+
required: true
26+
type: string
27+
28+
secrets:
29+
codacy_token:
30+
description: "The API token for uploading testing coverage report to Codacy."
31+
required: true
32+
33+
34+
jobs:
35+
upload_code_to_codacy_check_quality:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Download testing coverage report
39+
uses: actions/download-artifact@v3
40+
with:
41+
name: project_coverage_report
42+
path: ${{ inputs.download_path }}
43+
44+
- name: Generate testing report for Codacy
45+
run: mv ./coverage.xml ./cobertura.xml
46+
47+
- name: Upload testing report to Codacy
48+
uses: codacy/codacy-coverage-reporter-action@v1
49+
with:
50+
project-token: ${{ secrets.codacy_token }}
51+
coverage-reports: cobertura.xml
52+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
############################################################################
2+
#
3+
# Workflow Description:
4+
# Upload the testing coverage reports to Codecov.
5+
#
6+
# Workflow input parameters:
7+
# * General arguments:
8+
# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'.
9+
# * codecov_flags: The flags of the testing coverage report for Codecov.
10+
# * codecov_name: The name of the testing coverage report for Codecov.
11+
#
12+
# * Secret arguments:
13+
# * codecov_token: The API token for uploading testing coverage report to Codecov.
14+
#
15+
# Workflow running output:
16+
# No and do nothing.
17+
#
18+
############################################################################
19+
20+
name: Upload test report to Codecov
21+
22+
on:
23+
workflow_call:
24+
inputs:
25+
download_path:
26+
description: "The path to download testing coverage reports via 'actions/download-artifact@v3'."
27+
required: true
28+
type: string
29+
codecov_flags:
30+
description: "The flags of the testing coverage report for Codecov."
31+
required: true
32+
type: string
33+
codecov_name:
34+
description: "The name of the testing coverage report for Codecov."
35+
required: true
36+
type: string
37+
38+
secrets:
39+
codecov_token:
40+
description: "The API token for uploading testing coverage report to Codecov."
41+
required: true
42+
43+
44+
jobs:
45+
upload_report_to_codecov:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v2
50+
51+
- name: Download code coverage result file
52+
uses: actions/download-artifact@v3
53+
with:
54+
name: project_coverage_report
55+
path: ${{ inputs.download_path }}
56+
57+
- name: Upload coverage report to platform Codecov
58+
uses: codecov/codecov-action@v3
59+
with:
60+
token: ${{ secrets.codecov_token }} # not required for public repos
61+
files: coverage.xml # optional
62+
flags: ${{ inputs.codecov_flags }} # optional
63+
name: ${{ inputs.codecov_name }} # optional
64+
fail_ci_if_error: true # optional (default = false)
65+
verbose: true # optional (default = false)
66+
67+
- name: Upload testing coverage report
68+
uses: actions/upload-artifact@v3
69+
with:
70+
name: project_coverage_report
71+
path: coverage.xml
72+
if-no-files-found: error

0 commit comments

Comments
 (0)