Skip to content

Commit dacf744

Browse files
committed
🧬 Extract the test running process into a single reusable workflow and let running test with multiple Python version with multiple runtime OS as another reusable workflow.
1 parent b65cfc9 commit dacf744

File tree

3 files changed

+151
-9
lines changed

3 files changed

+151
-9
lines changed

.github/workflows/rw_poetry_run_test.yaml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# coverage report (it would save reports by 'actions/upload-artifact@v3').
66
#
77
# Workflow input parameters:
8+
# * runtime_os: The OS to use for runtime environment. In default, it's 'ubuntu-latest'.
9+
# * python_version: The Python version to run the workflow. In default, it's Python version '3.11'.
810
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
911
# * all_test_items_paths: The target paths of test items under test.
1012
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
@@ -29,6 +31,16 @@ name: Run test items via PyTest
2931
on:
3032
workflow_call:
3133
inputs:
34+
runtime_os:
35+
description: "The OS to use for runtime environment. In default, it's 'ubuntu-latest'."
36+
required: false
37+
type: string
38+
default: ubuntu-latest
39+
python_version:
40+
description: "The Python version to run the workflow. In default, it's Python version '3.11'."
41+
required: false
42+
type: string
43+
default: 3.11
3244
test_type:
3345
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
3446
required: true
@@ -68,22 +80,19 @@ on:
6880

6981
jobs:
7082
run_test_items:
71-
runs-on: ${{ matrix.os }}
83+
runs-on: ${{ inputs.runtime_os }}
7284

7385
strategy:
7486
matrix:
75-
python-version: [3.8,3.9,'3.10','3.11']
76-
os: [ubuntu-20.04,ubuntu-latest,macos-latest]
7787
test-path: ${{fromJson(inputs.all_test_items_paths)}}
7888

79-
8089
steps:
8190
- uses: actions/checkout@v3
8291

83-
- name: Install Python ${{ matrix.python-version }}
92+
- name: Install Python ${{ inputs.python_version }}
8493
uses: actions/setup-python@v4
8594
with:
86-
python-version: ${{ matrix.python-version }}
95+
python-version: ${{ inputs.python_version }}
8796

8897
- name: Install Python dependencies
8998
run: |
@@ -111,11 +120,11 @@ jobs:
111120
continue-on-error: true
112121

113122
- name: Rename the code coverage result file
114-
run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
123+
run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
115124

116125
- name: Upload code coverage result file
117126
uses: actions/upload-artifact@v3
118127
with:
119128
name: coverage
120-
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
129+
path: .coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
121130
if-no-files-found: error
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#################################################################################################################################
2+
#
3+
# Workflow Description:
4+
# Use Poetry to 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+
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
11+
# * http_server_host: The host IPv4 address of HTTP server.
12+
# * http_server_port: The port number of HTTP server.
13+
# * http_server_app_module: The module path of HTTP server.
14+
# * http_server_enter_point: The object about the web application.
15+
#
16+
# Workflow running output:
17+
# No, but it would save the testing coverage reports to provide after-process to organize and record.
18+
#
19+
# * Upload-Artifact:
20+
# * coverage: The test coverage report which be generated by PyTest, and it's recorded after run test done.
21+
# The file name format would be .coverage.<test type>.<runtime os>-<python-version>
22+
#
23+
#################################################################################################################################
24+
25+
name: Run test items via PyTest
26+
27+
# TODO: Run Python package test via Poetry.
28+
29+
on:
30+
workflow_call:
31+
inputs:
32+
test_type:
33+
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
34+
required: true
35+
type: string
36+
all_test_items_paths:
37+
description: "The target paths of test items under test."
38+
required: true
39+
type: string
40+
setup_http_server:
41+
description: "If it's true, it would set up and run HTTP server for testing."
42+
type: boolean
43+
required: false
44+
default: false
45+
http_server_host:
46+
description: "The host IPv4 address of HTTP server."
47+
type: string
48+
required: false
49+
default: 0.0.0.0
50+
http_server_port:
51+
description: "The port number of HTTP server."
52+
type: string
53+
required: false
54+
default: 12345
55+
http_server_app_module:
56+
description: "The module path of HTTP server."
57+
type: string
58+
required: false
59+
default: app
60+
http_server_enter_point:
61+
description: "The object about the web application."
62+
type: string
63+
required: false
64+
default: app
65+
66+
# TODO: Add a reusable workflow about running test via Poetry
67+
# TODO: https://github.com/marketplace/actions/python-poetry-action
68+
69+
jobs:
70+
run_test_items:
71+
strategy:
72+
matrix:
73+
python-version: [3.8,3.9,'3.10','3.11']
74+
os: [ubuntu-20.04,ubuntu-latest,macos-latest]
75+
test-path: ${{fromJson(inputs.all_test_items_paths)}}
76+
77+
uses: ./.github/workflows/rw_poetry_run_test.yaml
78+
with:
79+
runtime_os: ${{ matrix.os }}
80+
python_version: ${{ matrix.python-version }}
81+
test_type: ${{ inputs.test_type }}
82+
all_test_items_paths: ${{ inputs.all_test_items_paths }}
83+
setup_http_server: ${{ inputs.setup_http_server }}
84+
http_server_host: ${{ inputs.http_server_host }}
85+
http_server_port: ${{ inputs.http_server_port }}
86+
http_server_app_module: ${{ inputs.http_server_app_module }}
87+
http_server_enter_point: ${{ inputs.http_server_enter_point }}
88+
89+
90+
# steps:
91+
# - uses: actions/checkout@v3
92+
#
93+
# - name: Install Python ${{ matrix.python-version }}
94+
# uses: actions/setup-python@v4
95+
# with:
96+
# python-version: ${{ matrix.python-version }}
97+
#
98+
# - name: Install Python dependencies
99+
# run: |
100+
# python -m pip install --upgrade pip
101+
# pip install -U pip
102+
# pip install -U flask
103+
# pip install -U gunicorn
104+
# pip install -U poetry
105+
#
106+
# - name: Build Python runtime environment by Poetry
107+
# run: |
108+
# poetry --version
109+
# poetry install
110+
#
111+
# - name: Setup and run HTTP server for testing
112+
# if: ${{ inputs.setup_http_server == true }}
113+
# run: gunicorn --bind ${{ inputs.http_server_host }}:${{ inputs.http_server_port }} '${{ inputs.http_server_app_module }}:${{ inputs.http_server_enter_point }}' --daemon
114+
#
115+
# - name: Test to send HTTP request to sample HTTP server
116+
# if: ${{ inputs.setup_http_server == true }}
117+
# run: curl "http://${{ inputs.http_server_host }}:${{ inputs.http_server_port }}/exchangeReport/STOCK_DAY?response=json&date=20170101&stockNo=2331"
118+
#
119+
# - name: Run tests with pytest
120+
# run: poetry run pytest ${{ matrix.test-path }}
121+
# continue-on-error: true
122+
#
123+
# - name: Rename the code coverage result file
124+
# run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
125+
#
126+
# - name: Upload code coverage result file
127+
# uses: actions/upload-artifact@v3
128+
# with:
129+
# name: coverage
130+
# path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
131+
# if-no-files-found: error

.github/workflows/test_pyproject_ci_multi-tests_by_poetry.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323
# The shell scripts or actions this workflow would use.
2424
- ".github/workflows/rw_get_tests.yaml"
2525
- ".github/workflows/rw_poetry_run_test.yaml"
26+
- ".github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml"
2627
- ".github/workflows/rw_organize_test_cov_reports.yaml"
2728
- "scripts/ci/combine_coverage_reports.sh"
2829
- ".github/workflows/rw_upload_test_cov_report.yaml"
@@ -55,6 +56,7 @@ on:
5556
# The shell scripts or actions this workflow would use.
5657
- ".github/workflows/rw_get_tests.yaml"
5758
- ".github/workflows/rw_poetry_run_test.yaml"
59+
- ".github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml"
5860
- ".github/workflows/rw_organize_test_cov_reports.yaml"
5961
- "scripts/ci/combine_coverage_reports.sh"
6062
- ".github/workflows/rw_upload_test_cov_report.yaml"
@@ -94,7 +96,7 @@ jobs:
9496
run_integration-test:
9597
# name: Run all integration test items. This testing would test the code with other resource or system to ensure the features work finely.
9698
needs: prep-testbed_integration-test
97-
uses: ./.github/workflows/rw_poetry_run_test.yaml
99+
uses: ./.github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml
98100
with:
99101
test_type: integration-test
100102
all_test_items_paths: ${{needs.prep-testbed_integration-test.outputs.all_test_items}}

0 commit comments

Comments
 (0)