Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions .github/workflows/rw_poetry_run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# coverage report (it would save reports by 'actions/upload-artifact@v3').
#
# Workflow input parameters:
# * runtime_os: The OS to use for runtime environment. In default, it's 'ubuntu-latest'.
# * python_version: The Python version to run the workflow. In default, it's Python version '3.11'.
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
# * all_test_items_paths: The target paths of test items under test.
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
Expand All @@ -29,6 +31,16 @@ name: Run test items via PyTest
on:
workflow_call:
inputs:
runtime_os:
description: "The OS to use for runtime environment. In default, it's 'ubuntu-latest'."
required: false
type: string
default: ubuntu-latest
python_version:
description: "The Python version to run the workflow. In default, it's Python version '3.11'."
required: false
type: string
default: 3.11
test_type:
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
required: true
Expand Down Expand Up @@ -68,23 +80,19 @@ on:

jobs:
run_test_items:
if: ${{ inputs.debug_mode == false }}
runs-on: ${{ matrix.os }}
runs-on: ${{ inputs.runtime_os }}

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


steps:
- uses: actions/checkout@v4

- name: Install Python ${{ matrix.python-version }}
- name: Install Python ${{ inputs.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ inputs.python_version }}

- name: Install Python dependencies
run: |
Expand Down Expand Up @@ -112,11 +120,11 @@ jobs:
continue-on-error: true

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

- name: Upload code coverage result file
uses: actions/upload-artifact@v3
with:
name: coverage
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
if-no-files-found: error
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#################################################################################################################################
#
# Workflow Description:
# Use Poetry to run testing by specific type with all test items via PyTest and generate its testing
# coverage report (it would save reports by 'actions/upload-artifact@v3').
#
# Workflow input parameters:
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
# * all_test_items_paths: The target paths of test items under test.
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
# * http_server_host: The host IPv4 address of HTTP server.
# * http_server_port: The port number of HTTP server.
# * http_server_app_module: The module path of HTTP server.
# * http_server_enter_point: The object about the web application.
#
# Workflow running output:
# No, but it would save the testing coverage reports to provide after-process to organize and record.
#
# * Upload-Artifact:
# * coverage: The test coverage report which be generated by PyTest, and it's recorded after run test done.
# The file name format would be .coverage.<test type>.<runtime os>-<python-version>
#
#################################################################################################################################

name: Run test items via PyTest

# TODO: Run Python package test via Poetry.

on:
workflow_call:
inputs:
test_type:
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
required: true
type: string
all_test_items_paths:
description: "The target paths of test items under test."
required: true
type: string
setup_http_server:
description: "If it's true, it would set up and run HTTP server for testing."
type: boolean
required: false
default: false
http_server_host:
description: "The host IPv4 address of HTTP server."
type: string
required: false
default: 0.0.0.0
http_server_port:
description: "The port number of HTTP server."
type: string
required: false
default: 12345
http_server_app_module:
description: "The module path of HTTP server."
type: string
required: false
default: app
http_server_enter_point:
description: "The object about the web application."
type: string
required: false
default: app

# TODO: Add a reusable workflow about running test via Poetry
# TODO: https://github.com/marketplace/actions/python-poetry-action

jobs:
run_test_items:
strategy:
matrix:
python-version: [3.8,3.9,'3.10','3.11']
os: [ubuntu-20.04,ubuntu-latest,macos-latest]
test-path: ${{fromJson(inputs.all_test_items_paths)}}

uses: ./.github/workflows/rw_poetry_run_test.yaml
with:
runtime_os: ${{ matrix.os }}
python_version: ${{ matrix.python-version }}
test_type: ${{ inputs.test_type }}
all_test_items_paths: ${{ inputs.all_test_items_paths }}
setup_http_server: ${{ inputs.setup_http_server }}
http_server_host: ${{ inputs.http_server_host }}
http_server_port: ${{ inputs.http_server_port }}
http_server_app_module: ${{ inputs.http_server_app_module }}
http_server_enter_point: ${{ inputs.http_server_enter_point }}
93 changes: 17 additions & 76 deletions .github/workflows/rw_run_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
# coverage report (it would save reports by 'actions/upload-artifact@v3').
#
# Workflow input parameters:
# * runtime_os: The OS to use for runtime environment. In default, it's 'ubuntu-latest'.
# * python_version: The Python version to run the workflow. In default, it's Python version '3.11'.
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
# * all_test_items_paths: The target paths of test items under test.
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
# * http_server_host: The host IPv4 address of HTTP server.
# * http_server_port: The port number of HTTP server.
# * http_server_app_module: The module path of HTTP server.
# * http_server_enter_point: The object about the web application.
# * debug_mode: For debug, so it's matrix would one has os: ubuntu-22.04 & python-version: '3.10'.
#
# Workflow running output:
# No, but it would save the testing coverage reports to provide after-process to organize and record.
Expand All @@ -28,6 +29,16 @@ name: Run test items via PyTest
on:
workflow_call:
inputs:
runtime_os:
description: "The OS to use for runtime environment. In default, it's 'ubuntu-latest'."
required: false
type: string
default: ubuntu-latest
python_version:
description: "The Python version to run the workflow. In default, it's Python version '3.11'."
required: false
type: string
default: 3.11
test_type:
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
required: true
Expand Down Expand Up @@ -61,93 +72,23 @@ on:
type: string
required: false
default: app
debug_mode:
description: "For debug, so it's matrix would one has os: ubuntu-22.04 & python-version: '3.10'."
type: boolean
required: false
default: false


jobs:
run_test_items:
if: ${{ inputs.debug_mode == false }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
python-version: [3.6,3.7,3.8,3.9,'3.10','3.11']
os: [ubuntu-20.04,ubuntu-latest,macos-latest]
exclude:
- os: ubuntu-latest
python-version: 3.6
- os: ubuntu-20.04
python-version: 3.7
- os: ubuntu-20.04
python-version: 3.8
- os: ubuntu-20.04
python-version: 3.9
- os: ubuntu-20.04
python-version: '3.10'
- os: ubuntu-20.04
python-version: 3.11
test-path: ${{fromJson(inputs.all_test_items_paths)}}


steps:
- uses: actions/checkout@v4

- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -U pip
pip install -U -r ./requirements/requirements.txt
pip install -U -r ./requirements/requirements-test.txt

- name: Setup and run HTTP server for testing
if: ${{ inputs.setup_http_server == true }}
run: gunicorn --bind ${{ inputs.http_server_host }}:${{ inputs.http_server_port }} '${{ inputs.http_server_app_module }}:${{ inputs.http_server_enter_point }}' --daemon

- name: Test to send HTTP request to sample HTTP server
if: ${{ inputs.setup_http_server == true }}
run: curl "http://${{ inputs.http_server_host }}:${{ inputs.http_server_port }}/exchangeReport/STOCK_DAY?response=json&date=20170101&stockNo=2331"

- name: Run tests with pytest
run: pytest ${{ matrix.test-path }}
continue-on-error: true

- name: Rename the code coverage result file
run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}

- name: Upload code coverage result file
uses: actions/upload-artifact@v3
with:
name: coverage
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
if-no-files-found: error


run_test_items_with_debug_mode:
if: ${{ inputs.debug_mode == true }}
runs-on: ${{ matrix.os }}
runs-on: ${{ inputs.runtime_os }}

strategy:
matrix:
python-version: ['3.10']
os: [ubuntu-22.04]
test-path: ${{fromJson(inputs.all_test_items_paths)}}

steps:
- uses: actions/checkout@v4

- name: Install Python ${{ matrix.python-version }}
- name: Install Python ${{ inputs.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ inputs.python_version }}

- name: Install Python dependencies
run: |
Expand All @@ -169,11 +110,11 @@ jobs:
continue-on-error: true

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

- name: Upload code coverage result file
uses: actions/upload-artifact@v3
with:
name: coverage
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage.${{ inputs.test_type }}.${{ inputs.runtime_os }}-${{ inputs.python_version }}
if-no-files-found: error
96 changes: 96 additions & 0 deletions .github/workflows/rw_run_test_with_multi_py_versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#################################################################################################################################
#
# Workflow Description:
# Run testing by specific type with all test items via PyTest and generate its testing
# coverage report (it would save reports by 'actions/upload-artifact@v3').
#
# Workflow input parameters:
# * test_type: The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'.
# * all_test_items_paths: The target paths of test items under test.
# * setup_http_server: If it's true, it would set up and run HTTP server for testing.
# * http_server_host: The host IPv4 address of HTTP server.
# * http_server_port: The port number of HTTP server.
# * http_server_app_module: The module path of HTTP server.
# * http_server_enter_point: The object about the web application.
#
# Workflow running output:
# No, but it would save the testing coverage reports to provide after-process to organize and record.
#
# * Upload-Artifact:
# * coverage: The test coverage report which be generated by PyTest, and it's recorded after run test done.
# The file name format would be .coverage.<test type>.<runtime os>-<python-version>
#
#################################################################################################################################

name: Run test items via PyTest

on:
workflow_call:
inputs:
test_type:
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
required: true
type: string
all_test_items_paths:
description: "The target paths of test items under test."
required: true
type: string
setup_http_server:
description: "If it's true, it would set up and run HTTP server for testing."
type: boolean
required: false
default: false
http_server_host:
description: "The host IPv4 address of HTTP server."
type: string
required: false
default: 0.0.0.0
http_server_port:
description: "The port number of HTTP server."
type: string
required: false
default: 12345
http_server_app_module:
description: "The module path of HTTP server."
type: string
required: false
default: app
http_server_enter_point:
description: "The object about the web application."
type: string
required: false
default: app


jobs:
run_test_items:
strategy:
matrix:
python-version: [3.6,3.7,3.8,3.9,'3.10','3.11']
os: [ubuntu-20.04,ubuntu-latest,macos-latest]
exclude:
- os: ubuntu-latest
python-version: 3.6
- os: ubuntu-20.04
python-version: 3.7
- os: ubuntu-20.04
python-version: 3.8
- os: ubuntu-20.04
python-version: 3.9
- os: ubuntu-20.04
python-version: '3.10'
- os: ubuntu-20.04
python-version: 3.11
test-path: ${{fromJson(inputs.all_test_items_paths)}}

uses: ./.github/workflows/rw_run_test.yaml
with:
runtime_os: ${{ matrix.os }}
python_version: ${{ matrix.python-version }}
test_type: ${{ inputs.test_type }}
all_test_items_paths: ${{ inputs.all_test_items_paths }}
setup_http_server: ${{ inputs.setup_http_server }}
http_server_host: ${{ inputs.http_server_host }}
http_server_port: ${{ inputs.http_server_port }}
http_server_app_module: ${{ inputs.http_server_app_module }}
http_server_enter_point: ${{ inputs.http_server_enter_point }}
Loading