Skip to content

Commit c50f540

Browse files
authored
Merge pull request #8 from Chisanan232/develop
🎉🎊🍾 [New Feature] (config) Add sample code and configurations for testing workflows to ensure its functions.
2 parents 7a13a35 + 756b48e commit c50f540

19 files changed

+370
-13
lines changed

.coveragerc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# # This test directory for testing to simulate a Python library project structure.
2+
3+
[run]
4+
parallel = True
5+
relative_files = True
6+
source=./test_gh_workflow
7+
8+
omit =
9+
*/__init__.py
10+
11+
#ignore_errors = True

.github/workflows/organize_all_testing_coverage_reports_with_different_os_and_py_version.yaml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ on:
2424
type: string
2525
generate_xml_report_finally:
2626
description: "Something, it only has 1 test type currently. So it could let this option to be 'true' than it would generate XML report finally to let uploading process to use it directly."
27-
required: true
2827
type: boolean
28+
required: false
29+
default: false
2930

3031

3132
jobs:
32-
organize_and_generate_test_report:
33+
organize_test_reports:
3334
runs-on: ubuntu-latest
3435
steps:
3536
- name: Checkout
@@ -39,7 +40,7 @@ jobs:
3940
uses: actions/download-artifact@v3
4041
with:
4142
name: coverage
42-
path: .coverage.${{ inputs.test_type }}*
43+
path: ./
4344

4445
- name: Setup Python 3.10 in Ubuntu OS
4546
uses: actions/setup-python@v2
@@ -58,26 +59,53 @@ jobs:
5859
- name: Report testing coverage of project code
5960
run: coverage report -m
6061

62+
- name: Upload testing coverage report
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: project_testing_coverage_report_${{ inputs.test_type }}
66+
path: .coverage
67+
if-no-files-found: error
68+
69+
generate_final_test_report:
70+
if: ${{ inputs.generate_xml_report_finally == true }}
71+
# if: inputs.generate_xml_report_finally == 'true'
72+
needs: organize_test_reports
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Download code coverage result file
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: project_testing_coverage_report_${{ inputs.test_type }}
79+
path: ./
80+
6181
- name: General testing coverage report as XML format
62-
if: ${{ inputs.generate_xml_report_finally }} == 'true'
6382
run: coverage xml
6483

65-
- name: Rename the testing coverage report with test type
66-
if: ${{ inputs.generate_xml_report_finally }} == 'false'
67-
run: mv .coverage .coverage-${{ inputs.test_type }}
68-
6984
- name: Upload testing coverage report
70-
if: ${{ inputs.generate_xml_report_finally }} == 'true'
7185
uses: actions/upload-artifact@v3
7286
with:
7387
name: final_project_testing_coverage_report
7488
path: coverage.xml
7589
if-no-files-found: error
7690

91+
generate_test_type_report:
92+
if: ${{ inputs.generate_xml_report_finally == false }}
93+
# if: inputs.generate_xml_report_finally == 'false'
94+
needs: organize_test_reports
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Download code coverage result file
98+
uses: actions/download-artifact@v3
99+
with:
100+
name: project_testing_coverage_report_${{ inputs.test_type }}
101+
path: ./
102+
103+
- name: Rename the testing coverage report with test type
104+
run: mv .coverage .coverage-${{ inputs.test_type }}
105+
77106
- name: Upload testing coverage report
78-
if: ${{ inputs.generate_xml_report_finally }} == 'false'
79107
uses: actions/upload-artifact@v3
80108
with:
81-
name: project_testing_coverage_report
109+
name: new_project_testing_coverage_report_${{ inputs.test_type }}
82110
path: .coverage-${{ inputs.test_type }}
83111
if-no-files-found: error

.github/workflows/organize_all_testing_reports_with_different_test_type.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ jobs:
2727
- name: Download code coverage result file
2828
uses: actions/download-artifact@v3
2929
with:
30-
name: project_testing_coverage_report
31-
path: .coverage-*
30+
name: new_project_testing_coverage_report_unit-test
31+
path: ./
32+
33+
- name: Download code coverage result file
34+
uses: actions/download-artifact@v3
35+
with:
36+
name: new_project_testing_coverage_report_integration-test
37+
path: ./
3238

3339
- name: Setup Python 3.10 in Ubuntu OS
3440
uses: actions/setup-python@v2
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: github-action reusable workflows test
2+
on:
3+
push:
4+
branches:
5+
- "develop"
6+
- "release"
7+
- "release-**"
8+
- "release/**"
9+
- "master"
10+
paths-ignore:
11+
- ".gitcommitrules"
12+
- ".gitignore"
13+
- "LICENSE"
14+
- "README.md"
15+
pull_request:
16+
branches:
17+
- "develop"
18+
- "release"
19+
- "release-**"
20+
- "release/**"
21+
paths-ignore:
22+
- ".gitcommitrules"
23+
- ".gitignore"
24+
- "LICENSE"
25+
- "README.md"
26+
27+
jobs:
28+
29+
prep-testbed_unit-test:
30+
# name: Prepare all unit test items
31+
uses: ./.github/workflows/prepare_test_items.yaml
32+
with:
33+
shell_path: scripts/ci/get-unit-test-paths.sh
34+
shell_arg: unix
35+
36+
37+
prep-testbed_integration-test:
38+
# name: Prepare all integration test items
39+
uses: ./.github/workflows/prepare_test_items.yaml
40+
with:
41+
shell_path: scripts/ci/get-integration-test-paths.sh
42+
shell_arg: unix
43+
44+
45+
run_unit-test:
46+
# name: Run all unit test items
47+
needs: prep-testbed_unit-test
48+
uses: ./.github/workflows/run_test_items_via_pytest.yaml
49+
with:
50+
test_type: unit-test
51+
all_test_items_paths: ${{needs.prep-testbed_unit-test.outputs.all_test_items}}
52+
53+
54+
run_integration-test:
55+
# name: Run all integration test items. This testing would test the code with other resource or system to ensure the features work finely.
56+
needs: prep-testbed_integration-test
57+
uses: ./.github/workflows/run_test_items_via_pytest.yaml
58+
with:
59+
test_type: integration-test
60+
all_test_items_paths: ${{needs.prep-testbed_integration-test.outputs.all_test_items}}
61+
62+
63+
unit-test_codecov:
64+
# name: Organize and generate the testing report and upload it to Codecov
65+
needs: run_unit-test
66+
uses: ./.github/workflows/organize_all_testing_coverage_reports_with_different_os_and_py_version.yaml
67+
with:
68+
test_type: unit-test
69+
generate_xml_report_finally: false
70+
71+
72+
integration-test_codecov:
73+
# name: Organize and generate the testing report and upload it to Codecov
74+
needs: run_integration-test
75+
uses: ./.github/workflows/organize_all_testing_coverage_reports_with_different_os_and_py_version.yaml
76+
with:
77+
test_type: integration-test
78+
generate_xml_report_finally: false
79+
80+
81+
organize_all-test_codecov_and_generate_report:
82+
# name: Organize and generate the testing report and upload it to Codecov
83+
needs: [unit-test_codecov, integration-test_codecov]
84+
uses: ./.github/workflows/organize_all_testing_reports_with_different_test_type.yaml
85+
86+
87+
codecov_finish:
88+
# name: Organize and generate the testing report and upload it to Codecov
89+
if: github.ref_name == 'release' || github.ref_name == 'master'
90+
needs: organize_all-test_codecov_and_generate_report
91+
uses: ./.github/workflows/upload_test_report_to_codecov.yaml
92+
secrets:
93+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
94+
with:
95+
download_path: ./
96+
codecov_flags: unit-test, integration-test
97+
codecov_name: smoothcrawler-appintegration_github-actions_test # optional
98+
99+
100+
codacy_finish:
101+
# name: Upload test report to Codacy to analyse and record code quality
102+
needs: [codecov_finish]
103+
uses: ./.github/workflows/upload_code_report_to_codacy.yaml
104+
secrets:
105+
codacy_token: ${{ secrets.CODACY_PROJECT_TOKEN }}
106+
with:
107+
download_path: ./
108+
109+
110+
# pre-building_check:
111+
## name: Check about it could work finely by installing the Python package with setup.py file
112+
# needs: [codecov_finish, codacy_finish]
113+
# uses: Chisanan232/GitHub-Action-Template-Python/.github/workflows/upload_code_report_to_codacy.yaml
114+
# with:
115+
# python_package_name: smoothcrawler
116+
# test_import_package_code_1: import smoothcrawler as mr
117+
# test_import_package_code_2: from smoothcrawler.crawler import SimpleCrawler
118+
# test_import_package_code_3: from smoothcrawler.components.data import BaseHTTPResponseParser, BaseDataHandler
119+
# test_python_script: ./scripts/test_crawler.py
120+

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# # This test directory for testing to simulate a Python library project structure.
2+
3+
.DS_Store
4+
__pycache__
5+
.coverage
6+
.coverage.*
7+
.pypirc
8+
.pytest_cache/
9+
.python-version
10+
code_source/
11+
coverage.xml

codecov.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# # This test directory for testing to simulate a Python library project structure.
2+
3+
codecov:
4+
token: $CODECOV_TOKEN

pytest.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# # This test directory for testing to simulate a Python library project structure.
2+
3+
# pytest.ini
4+
[pytest]
5+
minversion = 0.1.0
6+
7+
addopts =
8+
--cov=./test_gh_workflow
9+
--cov-config=./.coveragerc
10+
-r a
11+
-v
12+
--reruns 3
13+
14+
testpaths =

requirements/requirements-test.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
###### SmoothCrawler-AppIntegration Development (or Testing) Dependencies Requirements ######
2+
## For running pytest ##
3+
pytest >= 7.0.0
4+
pytest-cov >= 3.0.0
5+
pytest-html >= 3.1.1
6+
pytest-rerunfailures >= 10.2
7+
8+
## For calculating code coverage ##
9+
coverage >= 6.2 # In Python 3.6, its latest version supported is 6.2. But it supports 6.4 version in Python 3.10.
10+
codecov >= 2.1.12
11+
coveralls >= 3.3.1

requirements/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
###### SmoothCrawler-AppIntegration Dependencies Requirements ######
2+
## Code - Basic ##
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
runtime_os=$1
5+
6+
declare -a base_tests
7+
8+
getalltests() {
9+
declare -a testpatharray=( $(ls -F "$1" | grep -v '/$' | grep -v '__init__.py' | grep -v 'test_config.py' | grep -v -E '^_[a-z_]{1,64}.py' | grep -v '__pycache__'))
10+
11+
declare -a alltestpaths
12+
for (( i = 0; i < ${#testpatharray[@]}; i++ )) ; do
13+
alltestpaths[$i]=$1${testpatharray[$i]}
14+
done
15+
16+
base_tests=("${alltestpaths[@]}")
17+
}
18+
19+
base_path=test/integration_test/
20+
21+
getalltests $base_path
22+
23+
dest=( "${base_tests[@]}" )
24+
25+
26+
if echo "$runtime_os" | grep -q "windows";
27+
then
28+
printf '%s\n' "${dest[@]}" | jq -R .
29+
elif echo "$runtime_os" | grep -q "unix";
30+
then
31+
printf '%s\n' "${dest[@]}" | jq -R . | jq -cs .
32+
else
33+
printf 'error' | jq -R .
34+
fi

0 commit comments

Comments
 (0)