Skip to content

Commit 992ae38

Browse files
authored
Merge pull request #31 from Chisanan232/develop
🔧⚙️🔩 [Breaking Change] (config) Modify the processing about test coverage report processing.
2 parents 72c3a7c + 549b31f commit 992ae38

File tree

6 files changed

+58
-84
lines changed

6 files changed

+58
-84
lines changed

.coveragerc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
branch = True
33
parallel = True
44
source=./test_gh_workflow
5+
relative_files = True
56

67
omit =
78
*/__init__.py
8-
9-
[path]
10-
source=./test_gh_workflow

.github/workflows/organize_and_generate_test_cov_reports.yaml

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ on:
2222
inputs:
2323
test_type:
2424
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
25-
required: true
2625
type: string
26+
required: true
2727

2828

2929
jobs:
@@ -49,33 +49,22 @@ jobs:
4949
python3 -m pip install --upgrade pip
5050
pip3 install -U pip
5151
pip3 install coverage
52-
pip3 install codecov
53-
pip3 install coveralls
54-
55-
- name: Combine all testing code coverage result files with one specific test type
56-
if: ${{ inputs.test_type == 'unit-test' || inputs.test_type == 'integration-test' }}
57-
run: coverage combine --data-file=.coverage.${{ inputs.test_type }} .coverage.${{ inputs.test_type }}.*
5852
59-
- name: Combine all testing code coverage result files with all test types
60-
if: ${{ inputs.test_type == 'all-test' }}
61-
run: coverage combine --data-file=.coverage.${{ inputs.test_type }} .coverage.*
62-
63-
- name: Report testing coverage of project code
64-
run: coverage report -m --data-file=.coverage.${{ inputs.test_type }}
65-
66-
- name: General testing coverage report as XML format with ${{ inputs.test_type }}
67-
run: coverage xml --data-file=.coverage.${{ inputs.test_type }} -o coverage_${{ inputs.test_type }}.xml
53+
- name: Combine all testing coverage data files with test type and runtime OS, and convert to XML format file finally
54+
run: |
55+
curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/combine_coverage_reports.sh --output ./scripts/ci/combine_coverage_reports.sh
56+
bash ./scripts/ci/combine_coverage_reports.sh ${{ inputs.test_type }}
6857
6958
- name: Upload testing coverage report (.coverage)
7059
uses: actions/upload-artifact@v3
7160
with:
72-
name: test_coverage_report
73-
path: .coverage.${{ inputs.test_type }}
61+
name: test_coverage_data_file
62+
path: .coverage
7463
if-no-files-found: error
7564

7665
- name: Upload testing coverage report (.xml)
7766
uses: actions/upload-artifact@v3
7867
with:
7968
name: test_coverage_xml_report
80-
path: coverage_${{ inputs.test_type }}.xml
69+
path: coverage**xml
8170
if-no-files-found: error

.github/workflows/test_python_project_ci_multi-tests.yaml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,18 @@ jobs:
6969
debug_mode: true
7070

7171

72-
unit-test_codecov:
72+
all-test_codecov:
7373
# name: Organize and generate the testing report and upload it to Codecov
74-
needs: run_unit-test
74+
needs: [run_unit-test, run_integration-test]
7575
uses: ./.github/workflows/organize_and_generate_test_cov_reports.yaml
7676
with:
77-
test_type: unit-test
78-
79-
80-
integration-test_codecov:
81-
# name: Organize and generate the testing report and upload it to Codecov
82-
needs: run_integration-test
83-
uses: ./.github/workflows/organize_and_generate_test_cov_reports.yaml
84-
with:
85-
test_type: integration-test
77+
test_type: all-test
8678

8779

8880
codecov_finish:
8981
# name: Organize and generate the testing report and upload it to Codecov
9082
# if: github.ref_name == 'release' || github.ref_name == 'master'
91-
needs: [unit-test_codecov, integration-test_codecov]
83+
needs: [all-test_codecov]
9284
uses: ./.github/workflows/upload_test_cov_report.yaml
9385
secrets:
9486
codecov_token: ${{ secrets.CODECOV_TOKEN }}
@@ -102,7 +94,7 @@ jobs:
10294
coveralls_finish:
10395
# name: Organize and generate the testing report and upload it to Coveralls
10496
# if: github.ref_name == 'release' || github.ref_name == 'master'
105-
needs: [unit-test_codecov, integration-test_codecov]
97+
needs: [all-test_codecov]
10698
uses: ./.github/workflows/upload_test_cov_report.yaml
10799
secrets:
108100
coveralls_token: ${{ secrets.COVERALLS_TOKEN }}
@@ -113,7 +105,7 @@ jobs:
113105

114106
codacy_finish:
115107
# name: Upload test report to Codacy to analyse and record code quality
116-
needs: [unit-test_codecov, integration-test_codecov]
108+
needs: [all-test_codecov]
117109
uses: ./.github/workflows/upload_test_cov_report.yaml
118110
secrets:
119111
codacy_token: ${{ secrets.CODACY_PROJECT_TOKEN }}
@@ -136,7 +128,7 @@ jobs:
136128

137129
build_git-tag_and_create_github-release:
138130
# name: Build git tag and GitHub release if it needs
139-
needs: [coveralls_finish, codacy_finish]
131+
needs: [codecov_finish, coveralls_finish, codacy_finish]
140132
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
141133
with:
142134
project_type: python-package

.github/workflows/test_python_project_ci_one-test.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ jobs:
5353
test_type: unit-test
5454

5555

56-
# codecov_finish:
57-
## name: Organize and generate the testing report and upload it to Codecov
58-
## if: github.ref_name == 'release' || github.ref_name == 'master'
59-
# needs: [unit-test_codecov]
60-
# uses: ./.github/workflows/upload_test_cov_report.yaml
61-
# secrets:
62-
# codecov_token: ${{ secrets.CODECOV_TOKEN }}
63-
# with:
64-
# test_type: unit-test
65-
# upload-to-codecov: true
66-
# codecov_flags: unit # Required if 'upload-to-codecov' is true
67-
# codecov_name: gh_workflow_template # Required if 'upload-to-codecov' is true
56+
codecov_finish:
57+
# name: Organize and generate the testing report and upload it to Codecov
58+
# if: github.ref_name == 'release' || github.ref_name == 'master'
59+
needs: [unit-test_codecov]
60+
uses: ./.github/workflows/upload_test_cov_report.yaml
61+
secrets:
62+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
63+
with:
64+
test_type: unit-test
65+
upload-to-codecov: true
66+
codecov_flags: unit # Required if 'upload-to-codecov' is true
67+
codecov_name: gh_workflow_template # Required if 'upload-to-codecov' is true
6868

6969

7070
coveralls_finish:
@@ -105,7 +105,7 @@ jobs:
105105

106106
build_git-tag_and_create_github-release:
107107
# name: Build git tag and GitHub release if it needs
108-
needs: [coveralls_finish, codacy_finish]
108+
needs: [coveralls_finish, codecov_finish, codacy_finish]
109109
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
110110
with:
111111
project_type: python-package

.github/workflows/upload_test_cov_report.yaml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,12 @@ jobs:
9696
echo "Check the parameters of uploading report to Codacy ..."
9797
bash ./scripts/ci/check-input-params.sh ${{ inputs.upload-to-codacy }} ${{ secrets.codacy_token }}
9898
99-
# TODO: It's possible be better that open input parameter 'file_path' or 'download name' outside.
10099
- name: Download code coverage result files which has be handled by different test type process
101100
uses: actions/download-artifact@v3
102101
with:
103-
name: test_coverage_report
102+
name: test_coverage_data_file
104103
path: ${{ inputs.download_path }}
105104

106-
# TODO: It's possible be better that open input parameter 'file_path' or 'download name' outside.
107105
- name: Download code coverage result files which has be handled by different test type process
108106
uses: actions/download-artifact@v3
109107
with:
@@ -126,57 +124,32 @@ jobs:
126124
if: ${{ inputs.upload-to-codecov == true }}
127125
run: pip3 install codecov
128126

129-
- name: Upload coverage report to Codecov https://codecov.io (For Unit-Test or Integration-Test)
130-
if: ${{ inputs.upload-to-codecov == true && (inputs.test_type == 'unit-test' || inputs.test_type == 'integration-test') }}
127+
- name: Upload coverage report to Codecov https://codecov.io
128+
if: ${{ inputs.upload-to-codecov == true }}
131129
run: |
132130
codecov \
133131
-t ${{ secrets.codecov_token }} \
134132
--file coverage_${{ inputs.test_type }}.xml \
135133
--flags ${{ inputs.codecov_flags }} \
136134
--env OS,PYTHON \
137135
--name ${{ inputs.codecov_name }} \
138-
--verbose
139-
140-
- name: Upload coverage report to Codecov https://codecov.io (For all test types)
141-
if: ${{ inputs.upload-to-codecov == true && inputs.test_type == 'all-test' }}
142-
run: |
143-
codecov \
144-
-t ${{ secrets.codecov_token }} \
145-
--file coverage_unit-test.xml \
146-
--file coverage_integration-test.xml \
147-
--flags ${{ inputs.codecov_flags }} \
148-
--env OS,PYTHON \
149-
--name ${{ inputs.codecov_name }} \
136+
--required \
150137
--verbose
151138
152139
- name: Install Python dependencies about tool of Coveralls
153140
if: ${{ inputs.upload-to-coveralls == true }}
154-
run: |
155-
pip3 install coveralls
156-
pip3 install coverage
157-
158-
- name: Combine all testing code coverage result files with all test types
159-
if: ${{ inputs.upload-to-coveralls == true }}
160-
run: coverage combine .coverage.*
141+
run: pip3 install coveralls
161142

162143
- name: Upload coverage report to Coveralls https://coveralls.io
163144
if: ${{ inputs.upload-to-coveralls == true }}
164145
env:
165146
GITHUB_TOKEN: ${{ secrets.coveralls_token }}
166147
run: coveralls --verbose
167148

168-
- name: Upload testing report to Codacy https://app.codacy.com/ (For Unit-Test or Integration-Test)
169-
if: ${{ inputs.upload-to-codacy == true && (inputs.test_type == 'unit-test' || inputs.test_type == 'integration-test') }}
149+
- name: Upload testing report to Codacy https://app.codacy.com/
150+
if: ${{ inputs.upload-to-codacy == true }}
170151
uses: codacy/codacy-coverage-reporter-action@v1
171152
with:
172153
project-token: ${{ secrets.codacy_token }}
173154
coverage-reports: coverage_${{ inputs.test_type }}.xml
174155
# coverage-reports: cobertura.xml
175-
176-
- name: Upload testing report to Codacy https://app.codacy.com/ (For all test types)
177-
if: ${{ inputs.upload-to-codacy == true && inputs.test_type == 'all-test' }}
178-
uses: codacy/codacy-coverage-reporter-action@v1
179-
with:
180-
project-token: ${{ secrets.codacy_token }}
181-
coverage-reports: coverage_unit-test.xml,coverage_integration-test.xml
182-
# coverage-reports: cobertura.xml
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
test_type=$1
6+
7+
coveragedatafile=".coverage.$test_type"
8+
9+
if [ "$test_type" == "unit-test" ] || [ "$test_type" == "integration-test" ];
10+
then
11+
coverage combine --data-file="$coveragedatafile" .coverage."$test_type".*
12+
elif [ "$test_type" == "all-test" ];
13+
then
14+
coverage combine --data-file="$coveragedatafile" .coverage.*
15+
else
16+
echo "❌ It doesn't support $test_type currently. Please change to use options 'unit-test', 'integration-test' or 'all-test'." && exit 1
17+
fi
18+
19+
coverage report -m --data-file="$coveragedatafile"
20+
coverage xml --data-file="$coveragedatafile" -o coverage_"$test_type".xml
21+
cp "$coveragedatafile" .coverage
22+
echo "✅ All processing done." && exit 0

0 commit comments

Comments
 (0)