Skip to content

Commit d1c1a5c

Browse files
authored
Merge pull request #110 from Chisanan232/develop
[CU-86evac2r1] Improve the GitHub PR template and add one new reusable workflow
2 parents 06e419f + 5c4755d commit d1c1a5c

File tree

5 files changed

+742
-2
lines changed

5 files changed

+742
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
* ### Task tickets:
1111

1212
* Task ID: N/A.
13-
* Relative task IDs: N/A.
13+
* Relative task IDs:
14+
* [ ] N/A.
15+
* Relative PRs:
16+
* N/A.
1417

1518
[//]: # (The key changes like demonstration, as-is & to-be, etc. for reviewers could be faster understand what it changes)
1619
* ### Key point change (optional):
@@ -21,7 +24,36 @@
2124
[//]: # (What's the scope in project it would affect with your modify? For example, would it affect CI workflow? Or any feature usage? Please list all the items which may be affected.)
2225
## _Effecting Scope_
2326

24-
* N/A.
27+
* Action Types:
28+
* [ ] ✨ Adding new something
29+
* [ ] 🟢 No breaking change
30+
* [ ] 🟠 Has breaking change
31+
* [ ] ✏️ Modifying existing something
32+
* [ ] 🟢 No breaking change
33+
* [ ] 🟠 Has breaking change
34+
* [ ] 🚮 Removing something
35+
* [ ] 🔧 Fixing bug
36+
* [ ] ♻️ Refactoring something
37+
* [ ] 🍀 Improving something (maybe performance, code quality, security, etc.)
38+
* [ ] 🚀 Release
39+
* Scopes:
40+
* [ ] ✍️ Command line interface
41+
* [ ] 💼 Core feature
42+
* [ ] ⚙️ Reusable workflow
43+
* [ ] 🐍 Scripts
44+
* [ ] 🗃️ Configuration
45+
* [ ] 🎨 UI/UX (maybe command line interface, etc.)
46+
* [ ] ⛑️ Error handling
47+
* [ ] 🧪 Testing
48+
* [ ] 🧪 Unit testing
49+
* [ ] 🧪 End-to-end testing
50+
* [ ] 📚 Documentation
51+
* [ ] 🚀 Building
52+
* [ ] 🤖 CI/CD
53+
* [ ] 🔗 Dependencies
54+
* [ ] 📦 Project configurations
55+
* Additional description:
56+
N/A.
2557

2658

2759
[//]: # (The brief of major changes what your modify. Please list it.)
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#################################################################################################################################
2+
#
3+
# Workflow Description:
4+
# Use UV 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').
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+
# * install_dependency_with_group: Install the dependency by UV configuration with dependency group setting. This parameter receive the dependency group naming.
11+
# * pre_test_script: Shell script or bash command to run before executing tests (optional).
12+
# * python-versions: JSON array of Python versions to test against. Default: '["3.13"]'
13+
# * operating-systems: JSON array of operating systems to test on. Default: '["ubuntu-latest", "ubuntu-22.04", "macos-latest", "macos-14"]'
14+
#
15+
# Workflow running output:
16+
# No, but it would save the testing coverage reports to provide after-process to organize and record.
17+
#
18+
# * Upload-Artifact:
19+
# * coverage: The test coverage report which be generated by PyTest, and it's recorded after run test done.
20+
# The file name format would be .coverage.<test type>.<runtime os>-<python-version>
21+
#
22+
#################################################################################################################################
23+
24+
name: Run test items via PyTest
25+
26+
on:
27+
workflow_call:
28+
inputs:
29+
test_type:
30+
description: "The testing type. In generally, it only has 2 options: 'unit-test' and 'integration-test'."
31+
required: true
32+
type: string
33+
test_working_directory:
34+
description: "The working directory for test running."
35+
required: false
36+
type: string
37+
default: './'
38+
test_folder:
39+
description: "The folder path for test code."
40+
required: false
41+
type: string
42+
default: './test'
43+
all_test_items_paths:
44+
description: "The target paths of test items under test."
45+
required: false
46+
type: string
47+
default: '["./test"]'
48+
install_dependency_with_group:
49+
description: "Install the dependency by UV configuration with dependency group setting. This parameter receive the dependency group naming. (multiple values allowed)"
50+
type: string
51+
required: false
52+
default: ''
53+
with-environment-variables:
54+
description: "Set the specific environment for the environment variables."
55+
type: string
56+
required: false
57+
default: ''
58+
pre_test_script:
59+
description: "Shell script or bash command to run before executing tests (e.g., 'curl -s https://slack.com/api/auth.test -H \"Authorization: Bearer $SLACK_BOT_TOKEN\"')."
60+
type: string
61+
required: false
62+
default: ''
63+
max-parallel:
64+
description: "Set the max-parallel jobs."
65+
type: number
66+
required: false
67+
default: 0
68+
python-versions:
69+
description: "JSON array of Python versions to test against."
70+
type: string
71+
required: false
72+
default: '["3.13"]'
73+
operating-systems:
74+
description: "JSON array of operating systems to test on."
75+
type: string
76+
required: false
77+
default: '["ubuntu-latest", "ubuntu-22.04", "macos-latest", "macos-14"]'
78+
secrets:
79+
e2e_test_api_token:
80+
description: "Set the API token for end-to-end test if it needs."
81+
required: false
82+
83+
jobs:
84+
run_test_items:
85+
strategy:
86+
max-parallel: ${{ inputs.max-parallel }}
87+
matrix:
88+
python-version: ${{fromJson(inputs.python-versions)}}
89+
os: ${{fromJson(inputs.operating-systems)}}
90+
test-path: ${{fromJson(inputs.all_test_items_paths)}}
91+
fail-fast: false # Fix issue in GitHub Action: FailFast: cancelling since parallel instance has failed
92+
93+
runs-on: ${{ matrix.os }}
94+
steps:
95+
- uses: actions/checkout@v5
96+
97+
- name: Install uv
98+
uses: astral-sh/setup-uv@v7
99+
with:
100+
python-version: ${{ matrix.python-version }}
101+
102+
- name: Activate the uv virtual environment
103+
run: |
104+
uv venv
105+
. .venv/bin/activate
106+
107+
- name: Install all the project dependencies
108+
if: ${{ inputs.install_dependency_with_group == '' }}
109+
run: uv sync --locked --all-extras --dev
110+
111+
- name: Build Python runtime environment by UV with dependency group *${{ inputs.install_dependency_with_group }}*
112+
if: ${{ inputs.install_dependency_with_group != '' }}
113+
working-directory: ${{ inputs.test_working_directory }}
114+
run: |
115+
uv pip install --group=${{ inputs.install_dependency_with_group }}
116+
117+
- name: Run pre-test script
118+
if: ${{ inputs.pre_test_script != '' }}
119+
working-directory: ${{ inputs.test_working_directory }}
120+
run: |
121+
${{ inputs.pre_test_script }}
122+
123+
- name: Run the specific tests with pytest
124+
if: ${{ inputs.test_type == '' }}
125+
working-directory: ${{ inputs.test_working_directory }}
126+
run: |
127+
# Export additional environment variables if provided
128+
if [ -n "${{ inputs.with-environment-variables }}" ]; then
129+
export ${{ inputs.with-environment-variables }}
130+
fi
131+
E2E_TEST_API_TOKEN=${{ secrets.e2e_test_api_token }} uv run pytest ${{ matrix.test-path }}
132+
continue-on-error: ${{ inputs.keep_run_if_test_fail }}
133+
env:
134+
E2E_TEST_API_TOKEN: ${{ secrets.e2e_test_api_token }}
135+
136+
- name: Run ${{ inputs.test_type }} tests with pytest
137+
if: ${{ inputs.test_type != '' }}
138+
working-directory: ${{ inputs.test_working_directory }}
139+
run: |
140+
# Export additional environment variables if provided
141+
if [ -n "${{ inputs.with-environment-variables }}" ]; then
142+
export ${{ inputs.with-environment-variables }}
143+
fi
144+
E2E_TEST_API_TOKEN=${{ secrets.e2e_test_api_token }} uv run pytest ${{ inputs.test_folder }}
145+
continue-on-error: ${{ inputs.keep_run_if_test_fail }}
146+
env:
147+
E2E_TEST_API_TOKEN: ${{ secrets.e2e_test_api_token }}
148+
149+
- name: Rename the code coverage result file
150+
working-directory: ${{ inputs.test_working_directory }}
151+
run: |
152+
mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
153+
154+
- name: Upload code coverage result file
155+
uses: actions/upload-artifact@v4
156+
with:
157+
name: coverage_${{ inputs.test_type }}_${{ matrix.os }}_${{ matrix.python-version }}
158+
path: ${{ inputs.test_working_directory }}.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
159+
if-no-files-found: error
160+
include-hidden-files: true

docs/contents/document/sidebars.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ const sidebars: SidebarsConfig = {
7878
id: 'workflows/test/rw_run_test',
7979
label: 'Run Test',
8080
},
81+
{
82+
type: 'doc',
83+
id: 'workflows/test/rw_uv_run_test',
84+
label: 'UV Run Test',
85+
},
8186
{
8287
type: 'doc',
8388
id: 'workflows/test/rw_poetry_run_test',

docs/contents/document/workflows/index.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ All workflow source code is available in the [GitHub repository](https://github.
1919
[![View Source](https://img.shields.io/badge/View-Source-blue?logo=github)](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_get_tests.yaml)
2020
- **[rw_run_test](./test/rw_run_test.mdx)** - Run tests with single Python version<br/>
2121
[![View Source](https://img.shields.io/badge/View-Source-blue?logo=github)](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_run_test.yaml)
22+
- **[rw_uv_run_test](./test/rw_uv_run_test.mdx)** - Run tests using UV (ultra-fast Python package manager)<br/>
23+
[![View Source](https://img.shields.io/badge/View-Source-blue?logo=github)](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_uv_run_test.yaml)
2224
- **[rw_poetry_run_test](./test/rw_poetry_run_test.mdx)** - Run tests using Poetry<br/>
2325
[![View Source](https://img.shields.io/badge/View-Source-blue?logo=github)](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_poetry_run_test.yaml)
2426
- **[rw_run_test_with_multi_py_versions](./test/rw_run_test_with_multi_py_versions.mdx)** - Run tests with multiple Python versions<br/>
@@ -181,6 +183,7 @@ Below is a complete list of all available reusable workflows with direct links t
181183
|------------------------------------------------------|---------------|---------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
182184
| `rw_get_tests.yaml` | Testing | Discover test items | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_get_tests.yaml) |
183185
| `rw_run_test.yaml` | Testing | Run tests (single Python version) | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_run_test.yaml) |
186+
| `rw_uv_run_test.yaml` | Testing | Run tests with UV (ultra-fast) | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_uv_run_test.yaml) |
184187
| `rw_poetry_run_test.yaml` | Testing | Run tests with Poetry | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_poetry_run_test.yaml) |
185188
| `rw_run_test_with_multi_py_versions.yaml` | Testing | Run tests (multiple Python versions) | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_run_test_with_multi_py_versions.yaml) |
186189
| `rw_poetry_run_test_with_multi_py_versions.yaml` | Testing | Run tests with Poetry (multi-version) | [View](https://github.com/Chisanan232/GitHub-Action_Reusable_Workflows-Python/blob/master/.github/workflows/rw_poetry_run_test_with_multi_py_versions.yaml) |

0 commit comments

Comments
 (0)