Skip to content

Commit bd48f3c

Browse files
authored
Merge pull request #16 from Chisanan232/develop
🎉🎊🍾 [New Feature + Breaking Change + Refactor] (config + docs) Add new feature, integrate organizing reports features and update document.
2 parents 0281b99 + 1ac1b52 commit bd48f3c

24 files changed

+1237
-291
lines changed

.coveragerc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
# # This test directory for testing to simulate a Python library project structure.
2-
31
[run]
2+
branch = True
43
parallel = True
5-
relative_files = True
64
source=./test_gh_workflow
75

86
omit =
97
*/__init__.py
10-
11-
#ignore_errors = True

.github/release-auto-flag.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true

.github/release-notes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### 🎉🎊🍾 New feature
2+
<hr>
3+
4+
1. Add new options about set up and run a sample HTTP server for testing if it needs in some testing scenario (_run_test_items_via_pytest.yaml_).
5+
6+
### 🛠⚙️🔩 **Breaking Change**
7+
<hr>
8+
9+
1. Integrate the feature about organizing and generating testing coverage reports into a reusable workflow. So workflow could be shorter and clear (_organize_and_generate_test_cov_reports.yaml_).
10+
2. Integrate all the uploading test coverage report features into a reusable workflow (_upload_test_cov_report.yaml_).
11+
3. Update document README.
12+
4. Move the PR template to **_.github_** directory (for working finely).
13+
14+
### ⚒⚒💣 **Bug Fix**
15+
<hr>
16+
17+
1. Fix the issue about uploading test coverage report cannot work at all.

.github/release-title.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v2.0.0 - More short and clear <0001f9f9>🍻
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
##############################################################################################
2+
#
3+
# Workflow Description:
4+
# Build a git tag on a specific commit in every git branch. And create GitHub release if current git branch is 'master'.
5+
#
6+
# Workflow input parameters:
7+
# * General arguments:
8+
# * project_type: Different project type would get the software version info in different way.
9+
# * debug_mode: It would run the tasks as log message, doesn't essentially run feature if this option is true.
10+
# * project_name: The project name.
11+
# * software_version_format: The format of software version.
12+
#
13+
# Workflow running output:
14+
# Yes, it has running result output. The output is the release version.
15+
#
16+
# * Workflow output:
17+
# It would output the version which would be build as git tag and create GitHub release version title.
18+
# * python_release_version: Python project release version info.
19+
# * github-action_reusable_workflow_release_version: GitHub Action reusable workflow project release version info.
20+
#
21+
##############################################################################################
22+
23+
name: Build git tag and create GitHub release with software version
24+
25+
on:
26+
workflow_call:
27+
inputs:
28+
project_type:
29+
description: "Different project type would get the software version info in different way."
30+
required: true
31+
type: string # Option: python, github-action_reusable-workflow
32+
# activate_git_event:
33+
# description: "Which git event should activate the workflow."
34+
# type: string
35+
# required: false
36+
# default: push
37+
debug_mode:
38+
description: "It would run the tasks as log message, doesn't essentially run feature if this option is true."
39+
type: boolean
40+
required: false
41+
default: false
42+
project_name:
43+
description: "The project name."
44+
type: string
45+
required: false
46+
software_version_format:
47+
description: "The format of software version."
48+
type: string
49+
required: false
50+
51+
outputs:
52+
python_release_version:
53+
description: "The version which would be build as git tag and create GitHub release version title."
54+
value: ${{ jobs.build_git-tag_and_create_github-release.outputs.matrix_python }}
55+
github-action_reusable_workflow_release_version:
56+
description: "The version which would be build as git tag and create GitHub release version title."
57+
value: ${{ jobs.build_git-tag_and_create_github-release.outputs.matrix_github_action_reusable_workflow }}
58+
59+
60+
jobs:
61+
build_git-tag_and_create_github-release:
62+
# name: Build git tag and GitHub release if it needs
63+
if: github.event_name == 'push'
64+
runs-on: ubuntu-latest
65+
outputs:
66+
matrix_python: ${{ steps.python_release.outputs.release_type }}
67+
matrix_github_action_reusable_workflow: ${{ steps.github_action_reusable_workflow_release.outputs.release_version }}
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v2
71+
72+
- name: Download shell script for checking input parameters
73+
run: curl https://raw.githubusercontent.com/Chisanan232/GitHub-Action_Workflow-Template-Python/develop/scripts/ci/build_git-tag_or_create_github-release.sh --output ./scripts/ci/build_git-tag_or_create_github-release.sh
74+
75+
# This flow for the project type is Python project
76+
- name: Build git tag and create GitHub release for Python project
77+
if: ${{ inputs.project_type == 'python-package' }}
78+
id: python_release
79+
run: |
80+
release=$(bash ./scripts/ci/build_git-tag_or_create_github-release.sh ${{ inputs.project_type }} ${{ inputs.debug_mode }} ${{ inputs.project_name }} ${{ inputs.software_version_format }})
81+
echo "📄 Release log: $release"
82+
83+
release_type=$(echo "$release" | grep -E "\[Python\] \[Final Running Result\] ((Official\-Release)|(Pre\-Release))" | grep -E -o "((Official\-Release)|(Pre\-Release))")
84+
echo "🐍 Release Type: $release_type"
85+
86+
echo "::set-output name=release_type::$(echo $release_type)"
87+
88+
# This flow for the project type is GitHub Action reusable workflow
89+
- name: Build git tag and create GitHub release for GitHub Action reusable workflow project
90+
if: ${{ inputs.project_type == 'github-action-reusable-workflow' }}
91+
id: github_action_reusable_workflow_release
92+
run: |
93+
release=$(bash ./scripts/ci/build_git-tag_or_create_github-release.sh ${{ inputs.project_type }} ${{ inputs.debug_mode }})
94+
echo "📄 Release log: $release"
95+
96+
release_version=$(echo "$release" | grep -E "\[GitHub Action - Reusable workflow\] \[Final Running Result\] Official-Release and version: ([0-9]{1,})" | grep -E -o "([0-9]{1,})")
97+
echo "🤖 Release Version: $release_version"
98+
99+
echo "::set-output name=release_version::$(echo $release_version)"
100+

.github/workflows/ci-cd.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: GitHub Action reusable workflow build
2+
3+
on:
4+
push:
5+
branches:
6+
- "develop"
7+
- "release"
8+
- "master"
9+
paths-ignore:
10+
- ".gitcommitrules"
11+
- ".gitignore"
12+
- "LICENSE"
13+
- "README.md"
14+
15+
pull_request:
16+
branches:
17+
- "develop"
18+
- "release"
19+
paths-ignore:
20+
- ".gitcommitrules"
21+
- ".gitignore"
22+
- "LICENSE"
23+
- "README.md"
24+
25+
jobs:
26+
test_build_git-tag_and_create_github-release:
27+
# name: Build git tag and GitHub release if it needs
28+
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
29+
with:
30+
project_type: github-action-reusable-workflow
31+
debug_mode: false
32+
33+
34+
test_deploy_as_new_branch:
35+
# name: Create new git branch by the tagged commit
36+
needs: test_build_git-tag_and_create_github-release
37+
if: ${{ github.ref_name == 'master' &&
38+
github.event_name == 'push' &&
39+
needs.test_build_git-tag_and_create_github-release.outputs.github-action_reusable_workflow_release_version != 'Pre' }}
40+
runs-on: ubuntu-latest
41+
env:
42+
RELEASE_TYPE: ${{ needs.test_build_git-tag_and_create_github-release.outputs.github-action_reusable_workflow_release_version }}
43+
DEBUG_MODE: false
44+
steps:
45+
- uses: actions/checkout@v2
46+
47+
- name: Check it whether get the output of previous one job which has version info or not
48+
run: bash scripts/ci/check_getting_output.sh
49+
50+
- name: Create new git branch by the tagged commit
51+
run: bash ./scripts/ci/deployment_new_version_workflow.sh $DEBUG_MODE
52+

.github/workflows/organize_and_generate_testing_coverage_reports.yaml renamed to .github/workflows/organize_and_generate_test_cov_reports.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
############################################################################
1+
###################################################################################################################################
22
#
33
# Workflow Description:
44
# Organize all the testing coverage reports. (it would save reports by 'actions/upload-artifact@v3').
@@ -9,7 +9,11 @@
99
# Workflow running output:
1010
# No, but it would save the testing coverage reports (coverage.xml) to provide after-process to organize and record.
1111
#
12-
############################################################################
12+
# * Upload-Artifact:
13+
# * test_coverage_report: The handled test coverage report (.coverage file). It's file name format would be .coverage.<inputs.test type>.
14+
# * test_coverage_xml_report: The handled test coverage report (.xml file). It's file name format would be coverage_<inputs.test type>.xml.
15+
#
16+
###################################################################################################################################
1317

1418
name: Organize all testing coverage reports which be tested in many different runtime OS and Python version as a testing coverage report
1519

@@ -45,6 +49,8 @@ jobs:
4549
python3 -m pip install --upgrade pip
4650
pip3 install -U pip
4751
pip3 install coverage
52+
pip3 install codecov
53+
pip3 install coveralls
4854
4955
- name: Combine all testing code coverage result files with one specific test type
5056
if: ${{ inputs.test_type == 'unit-test' || inputs.test_type == 'integration-test' }}
@@ -60,9 +66,16 @@ jobs:
6066
- name: General testing coverage report as XML format with ${{ inputs.test_type }}
6167
run: coverage xml --data-file=.coverage.${{ inputs.test_type }} -o coverage_${{ inputs.test_type }}.xml
6268

63-
- name: Upload testing coverage report
69+
- name: Upload testing coverage report (.coverage)
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: test_coverage_report
73+
path: .coverage.${{ inputs.test_type }}
74+
if-no-files-found: error
75+
76+
- name: Upload testing coverage report (.xml)
6477
uses: actions/upload-artifact@v3
6578
with:
66-
name: final_project_testing_coverage_report
79+
name: test_coverage_xml_report
6780
path: coverage_${{ inputs.test_type }}.xml
6881
if-no-files-found: error

.github/workflows/run_test_items_via_pytest.yaml

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
############################################################################
1+
#################################################################################################################################
22
#
33
# Workflow Description:
44
# Run testing by specific type with all test items via PyTest and generate its testing
@@ -12,11 +12,16 @@
1212
# * http_server_port: The port number of HTTP server.
1313
# * http_server_app_module: The module path of HTTP server.
1414
# * http_server_enter_point: The object about the web application.
15+
# * debug_mode: For debug, so it's matrix would one has os: ubuntu-22.04 & python-version: '3.10'.
1516
#
1617
# Workflow running output:
1718
# No, but it would save the testing coverage reports to provide after-process to organize and record.
1819
#
19-
############################################################################
20+
# * Upload-Artifact:
21+
# * coverage: The test coverage report which be generated by PyTest, and it's recorded after run test done.
22+
# The file name format would be .coverage.<test type>.<runtime os>-<python-version>
23+
#
24+
#################################################################################################################################
2025

2126
name: Run test items via PyTest
2227

@@ -56,16 +61,22 @@ on:
5661
type: string
5762
required: false
5863
default: app
64+
debug_mode:
65+
description: "For debug, so it's matrix would one has os: ubuntu-22.04 & python-version: '3.10'."
66+
type: boolean
67+
required: false
68+
default: false
5969

6070

6171
jobs:
6272
run_test_items:
73+
if: ${{ inputs.debug_mode == false }}
6374
runs-on: ${{ matrix.os }}
6475

6576
strategy:
6677
matrix:
6778
python-version: [3.6,3.7,3.8,3.9,'3.10']
68-
os: [ubuntu-18.04,ubuntu-20.04,ubuntu-22.04, macos-10.15,macos-11,macos-12]
79+
os: [ubuntu-18.04,ubuntu-20.04,ubuntu-22.04,macos-10.15,macos-11,macos-12]
6980
exclude:
7081
- os: ubuntu-18.04
7182
python-version: 3.6
@@ -128,3 +139,50 @@ jobs:
128139
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
129140
if-no-files-found: error
130141

142+
143+
run_test_items_with_debug_mode:
144+
if: ${{ inputs.debug_mode == true }}
145+
runs-on: ${{ matrix.os }}
146+
147+
strategy:
148+
matrix:
149+
python-version: ['3.10']
150+
os: [ubuntu-22.04]
151+
test-path: ${{fromJson(inputs.all_test_items_paths)}}
152+
153+
steps:
154+
- uses: actions/checkout@v2
155+
156+
- name: Install Python ${{ matrix.python-version }}
157+
uses: actions/setup-python@v2
158+
with:
159+
python-version: ${{ matrix.python-version }}
160+
161+
- name: Install Python dependencies
162+
run: |
163+
python -m pip install --upgrade pip
164+
pip install -U pip
165+
pip install -U -r ./requirements/requirements.txt
166+
pip install -U -r ./requirements/requirements-test.txt
167+
168+
- name: Setup and run HTTP server for testing
169+
if: ${{ inputs.setup_http_server == true }}
170+
run: gunicorn --bind ${{ inputs.http_server_host }}:${{ inputs.http_server_port }} '${{ inputs.http_server_app_module }}:${{ inputs.http_server_enter_point }}' --daemon
171+
172+
- name: Test to send HTTP request to sample HTTP server
173+
if: ${{ inputs.setup_http_server == true }}
174+
run: curl "http://${{ inputs.http_server_host }}:${{ inputs.http_server_port }}/exchangeReport/STOCK_DAY?response=json&date=20170101&stockNo=2331"
175+
176+
- name: Run tests with pytest
177+
run: pytest ${{ matrix.test-path }}
178+
continue-on-error: true
179+
180+
- name: Rename the code coverage result file
181+
run: mv ./.coverage ./.coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
182+
183+
- name: Upload code coverage result file
184+
uses: actions/upload-artifact@v3
185+
with:
186+
name: coverage
187+
path: .coverage.${{ inputs.test_type }}.${{ matrix.os }}-${{ matrix.python-version }}
188+
if-no-files-found: error
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: GitHub Action reusable workflow project CI Test
2+
3+
on:
4+
push:
5+
branches:
6+
- "develop"
7+
- "release"
8+
- "release-**"
9+
- "release/**"
10+
- "master"
11+
paths-ignore:
12+
- ".gitcommitrules"
13+
- ".gitignore"
14+
- "LICENSE"
15+
- "README.md"
16+
17+
pull_request:
18+
branches:
19+
- "develop"
20+
- "release"
21+
- "release-**"
22+
- "release/**"
23+
- "master"
24+
paths-ignore:
25+
- ".gitcommitrules"
26+
- ".gitignore"
27+
- "LICENSE"
28+
- "README.md"
29+
30+
jobs:
31+
test_build_git-tag_and_create_github-release:
32+
# name: Build git tag and GitHub release if it needs
33+
uses: ./.github/workflows/build_git-tag_and_create_github-release.yaml
34+
with:
35+
project_type: github-action-reusable-workflow
36+
debug_mode: true
37+
38+
39+
test_deploy_as_new_branch:
40+
# name: Create new git branch by the tagged commit
41+
needs: test_build_git-tag_and_create_github-release
42+
if: ${{ github.event_name == 'push' &&
43+
needs.test_build_git-tag_and_create_github-release.outputs.github-action_reusable_workflow_release_version != 'Initial' &&
44+
needs.test_build_git-tag_and_create_github-release.outputs.github-action_reusable_workflow_release_version != 'Pre' }}
45+
runs-on: ubuntu-latest
46+
env:
47+
RELEASE_TYPE: ${{ needs.test_build_git-tag_and_create_github-release.outputs.github-action_reusable_workflow_release_version }}
48+
steps:
49+
- uses: actions/checkout@v2
50+
51+
- name: Check it whether get the output of previous one job which has version info or not
52+
run: bash scripts/ci/check_getting_output.sh
53+
54+
- name: Create new git branch by the tagged commit
55+
run: bash ./scripts/ci/deployment_new_version_workflow.sh 'true'
56+

0 commit comments

Comments
 (0)