Skip to content

Commit e36ef57

Browse files
authored
Merge pull request #86 from Chisanan232/develop
[CU-86et1kvnd] Add end-to-end test for the working directory feature
2 parents cc6572d + 3725126 commit e36ef57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1527
-4
lines changed

.github/workflows/rw_get_tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656

5757
- name: Download shell script for getting path of all test modules
5858
if: ${{ inputs.use_customized_shell != true }}
59+
working-directory: ${{ inputs.test_working_directory }}
5960
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/get-all-tests.sh --output ${{ inputs.shell_path }}
6061

6162
- id: set-matrix

.github/workflows/rw_organize_test_cov_reports.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66
# Workflow input parameters:
77
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
8+
# * test_working_directory: The working directory for test running.
89
#
910
# Workflow running output:
1011
# No, but it would save the testing coverage reports (coverage.xml) to provide after-process to organize and record.
@@ -24,6 +25,11 @@ on:
2425
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
2526
type: string
2627
required: true
28+
test_working_directory:
29+
description: "The working directory for test running."
30+
required: false
31+
type: string
32+
default: './'
2733

2834

2935
jobs:
@@ -37,7 +43,7 @@ jobs:
3743
uses: actions/download-artifact@v4
3844
with:
3945
pattern: coverage*
40-
path: ./
46+
path: ${{ inputs.test_working_directory }}
4147
merge-multiple: true
4248

4349
- name: Setup Python 3.10 in Ubuntu OS
@@ -46,6 +52,7 @@ jobs:
4652
python-version: '3.10'
4753

4854
- name: Install Python tool 'coverage'
55+
working-directory: ${{ inputs.test_working_directory }}
4956
run: |
5057
python3 -m pip install --upgrade pip
5158
pip3 install -U pip
@@ -54,6 +61,7 @@ jobs:
5461
ls -la
5562
5663
- name: Combine all testing coverage data files with test type and runtime OS, and convert to XML format file finally
64+
working-directory: ${{ inputs.test_working_directory }}
5765
run: |
5866
curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/develop/scripts/ci/combine_coverage_reports.sh --output ./scripts/ci/combine_coverage_reports.sh
5967
bash ./scripts/ci/combine_coverage_reports.sh ${{ inputs.test_type }} .coverage.
@@ -62,14 +70,14 @@ jobs:
6270
uses: actions/upload-artifact@v4
6371
with:
6472
name: ${{ inputs.test_type }}_coverage_data_file
65-
path: .coverage
73+
path: ${{ inputs.test_working_directory }}.coverage
6674
if-no-files-found: error
6775
include-hidden-files: true
6876

6977
- name: Upload testing coverage report (.xml)
7078
uses: actions/upload-artifact@v4
7179
with:
7280
name: ${{ inputs.test_type }}_coverage_xml_report
73-
path: coverage**xml
81+
path: ${{ inputs.test_working_directory }}coverage**xml
7482
if-no-files-found: error
7583
include-hidden-files: true

.github/workflows/rw_poetry_run_test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ jobs:
149149
150150
- name: Setup and run HTTP server for testing
151151
if: ${{ inputs.setup_http_server == true }}
152+
working-directory: ${{ inputs.test_working_directory }}
152153
run: gunicorn --bind ${{ inputs.http_server_host }}:${{ inputs.http_server_port }} '${{ inputs.http_server_app_module }}:${{ inputs.http_server_enter_point }}' --daemon
153154

154155
- name: Test to send HTTP request to sample HTTP server
@@ -169,6 +170,6 @@ jobs:
169170
uses: actions/upload-artifact@v4
170171
with:
171172
name: coverage_${{ inputs.test_type }}_${{ inputs.runtime_os }}_${{ inputs.python_version }}
172-
path: .coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
173+
path: ${{ inputs.test_working_directory }}.coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
173174
if-no-files-found: error
174175
include-hidden-files: true

.github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#
77
# Workflow input parameters:
88
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
9+
# * test_working_directory: The working directory for test running.
910
# * install_dependency_with_group: Install the dependency by Poetry configuration with dependency group setting. This parameter receive the dependency group naming.
1011
# * all_test_items_paths: The target paths of test items under test.
1112
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
@@ -34,6 +35,11 @@ on:
3435
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
3536
required: true
3637
type: string
38+
test_working_directory:
39+
description: "The working directory for test running."
40+
required: false
41+
type: string
42+
default: './'
3743
install_dependency_with_group:
3844
description: "Install the dependency by Poetry configuration with dependency group setting. This parameter receive the dependency group naming."
3945
type: string
@@ -86,6 +92,7 @@ jobs:
8692
runtime_os: ${{ matrix.os }}
8793
python_version: ${{ matrix.python-version }}
8894
test_type: ${{ inputs.test_type }}
95+
test_working_directory: ${{ inputs.test_working_directory }}
8996
install_dependency_with_group: ${{ inputs.install_dependency_with_group }}
9097
all_test_items_paths: ${{ inputs.all_test_items_paths }}
9198
setup_http_server: ${{ inputs.setup_http_server }}

.github/workflows/rw_upload_test_cov_report.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# * General arguments:
88
# * download_path: The path to download testing coverage reports via 'actions/download-artifact@v3'.
99
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
10+
# * test_working_directory: The working directory for test running.
1011
# * upload-to-codecov: If it's true, it would upload testing coverage report for Codecov (https://codecov.io).
1112
# * codecov_flags: The flags of the testing coverage report for Codecov. This option would be required if 'upload-to-codecov' is true.
1213
# * codecov_name: The name of the testing coverage report for Codecov. This option would be required if 'upload-to-codecov' is true.
@@ -37,6 +38,11 @@ on:
3738
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
3839
required: true
3940
type: string
41+
test_working_directory:
42+
description: "The working directory for test running."
43+
required: false
44+
type: string
45+
default: './'
4046
upload-to-codecov:
4147
description: "If it's true, it would upload testing coverage report for Codecov (https://codecov.io)."
4248
type: boolean
@@ -156,6 +162,7 @@ jobs:
156162

157163
- name: Upload coverage report to Coveralls https://coveralls.io
158164
if: ${{ inputs.upload-to-coveralls == true }}
165+
working-directory: ${{ inputs.test_working_directory }}
159166
env:
160167
GITHUB_TOKEN: ${{ secrets.coveralls_token }}
161168
run: coveralls --verbose
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: Nested Python project with Poetry CI Test (multi-tests)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "develop**"
7+
- "master"
8+
paths:
9+
# The workflow self.
10+
- ".github/workflows/test_nested_pyproject_ci_multi-tests_by_poetry.yaml"
11+
# The shell script only be used by this workflow.
12+
- "nested_poetry_project/scripts/ci/check_getting_output.sh"
13+
# The sample Python code.
14+
- "nested_poetry_project/.coveragerc"
15+
- "nested_poetry_project/pyproject.toml"
16+
- "nested_poetry_project/poetry.lock"
17+
- "nested_poetry_project/pytest.ini"
18+
- "nested_poetry_project/nested_python_src/**"
19+
- "nested_poetry_project/test/**"
20+
# The shell scripts or actions this workflow would use.
21+
- ".github/workflows/rw_get_tests.yaml"
22+
- ".github/workflows/rw_poetry_run_test.yaml"
23+
- ".github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml"
24+
- ".github/workflows/rw_organize_test_cov_reports.yaml"
25+
- "nested_poetry_project/scripts/ci/combine_coverage_reports.sh"
26+
- ".github/workflows/rw_upload_test_cov_report.yaml"
27+
- "nested_poetry_project/scripts/ci/check-input-params.sh"
28+
- ".github/workflows/rw_sonarqube_scan.yaml"
29+
- ".github/workflows/rw_pre-building_test.yaml"
30+
- ".github/workflows/rw_build_git-tag_and_create_github-release.yaml"
31+
- "nested_poetry_project/scripts/ci/build_git-tag_or_create_github-release.sh"
32+
- "nested_poetry_project/scripts/ci/deployment_new_version_workflow.sh"
33+
34+
jobs:
35+
prep-testbed_unit-test:
36+
# name: Prepare all unit test items
37+
uses: ./.github/workflows/rw_get_tests.yaml
38+
with:
39+
test_working_directory: './nested_poetry_project/'
40+
shell_arg: test/unit_test/
41+
42+
43+
prep-testbed_integration-test:
44+
# name: Prepare all integration test items
45+
uses: ./.github/workflows/rw_get_tests.yaml
46+
with:
47+
shell_path: ./scripts/ci/test/get-integration-test-paths.sh
48+
shell_arg: unix
49+
test_working_directory: './nested_poetry_project/'
50+
use_customized_shell: true
51+
52+
53+
run_unit-test:
54+
# name: Run all unit test items
55+
needs: prep-testbed_unit-test
56+
uses: ./.github/workflows/rw_poetry_run_test.yaml
57+
with:
58+
test_type: unit-test
59+
test_working_directory: './nested_poetry_project/'
60+
install_dependency_with_group: github-action
61+
all_test_items_paths: ${{needs.prep-testbed_unit-test.outputs.all_test_items}}
62+
63+
64+
run_integration-test:
65+
# name: Run all integration test items. This testing would test the code with other resource or system to ensure the features work finely.
66+
needs: prep-testbed_integration-test
67+
uses: ./.github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml
68+
with:
69+
test_type: integration-test
70+
test_working_directory: './nested_poetry_project/'
71+
install_dependency_with_group: github-action
72+
all_test_items_paths: ${{needs.prep-testbed_integration-test.outputs.all_test_items}}
73+
setup_http_server: true
74+
http_server_host: 0.0.0.0
75+
http_server_port: 30303
76+
http_server_app_module: test._http_server.app
77+
http_server_enter_point: app
78+
79+
80+
all-test_codecov:
81+
# name: Organize and generate the testing report and upload it to Codecov
82+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependencies') }}
83+
needs: [run_unit-test, run_integration-test]
84+
uses: ./.github/workflows/rw_organize_test_cov_reports.yaml
85+
with:
86+
test_type: all-test
87+
test_working_directory: './nested_poetry_project/'
88+
89+
90+
codecov_finish:
91+
# name: Organize and generate the testing report and upload it to Codecov
92+
# if: github.ref_name == 'release' || github.ref_name == 'master'
93+
needs: [all-test_codecov]
94+
uses: ./.github/workflows/rw_upload_test_cov_report.yaml
95+
secrets:
96+
codecov_token: ${{ secrets.CODECOV_TOKEN }}
97+
with:
98+
test_type: all-test
99+
upload-to-codecov: true
100+
codecov_flags: unit,integration # Required if 'upload-to-codecov' is true
101+
codecov_name: gh_workflow_template # Required if 'upload-to-codecov' is true
102+
103+
104+
coveralls_finish:
105+
# name: Organize and generate the testing report and upload it to Coveralls
106+
# if: github.ref_name == 'release' || github.ref_name == 'master'
107+
needs: [all-test_codecov]
108+
uses: ./.github/workflows/rw_upload_test_cov_report.yaml
109+
secrets:
110+
coveralls_token: ${{ secrets.COVERALLS_TOKEN }}
111+
with:
112+
test_type: all-test
113+
test_working_directory: './nested_poetry_project/'
114+
upload-to-coveralls: true
115+
116+
117+
codacy_finish:
118+
# name: Upload test report to Codacy to analyse and record code quality
119+
needs: [all-test_codecov]
120+
uses: ./.github/workflows/rw_upload_test_cov_report.yaml
121+
secrets:
122+
codacy_token: ${{ secrets.CODACY_PROJECT_TOKEN }}
123+
with:
124+
test_type: all-test
125+
upload-to-codacy: true
126+
127+
128+
sonarqube_finish:
129+
# name: Trigger SoarQube service to scan and analyse project
130+
needs: [all-test_codecov]
131+
uses: ./.github/workflows/rw_sonarqube_scan.yaml
132+
secrets:
133+
sonar_token: ${{ secrets.SONAR_TOKEN }}
134+
with:
135+
test_type: all-test
136+
# download_path: ${{ inputs.download_path }}

nested_poetry_project/.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
parallel = True
3+
relative_files = True
4+
include=./test_gh_workflow
5+
6+
omit =
7+
*/__init__.py

nested_poetry_project/nested_python_src/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.2.0-alpha1.post1"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def hello_python() -> str:
3+
return "Hello Python"

0 commit comments

Comments
 (0)