Skip to content

Commit 5a2b5e5

Browse files
feat: support codspeed (#245)
* feat: support codspeed * Potential fix for code scanning alert no. 46: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent dac2281 commit 5a2b5e5

File tree

8 files changed

+106
-2
lines changed

8 files changed

+106
-2
lines changed

.github/workflows/codspeed.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CodSpeed
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- "main"
10+
paths:
11+
- "commit_check/**"
12+
- "tests/**"
13+
- ".github/workflows/codspeed.yml"
14+
- "pyproject.toml"
15+
pull_request:
16+
branches:
17+
- "main"
18+
paths:
19+
- "commit_check/**"
20+
- "tests/**"
21+
- ".github/workflows/codspeed.yml"
22+
- "pyproject.toml"
23+
# `workflow_dispatch` allows CodSpeed to trigger backtest
24+
# performance analysis in order to generate initial data.
25+
workflow_dispatch:
26+
27+
jobs:
28+
benchmarks:
29+
name: Run benchmarks
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.13"
36+
37+
- name: Install dependencies
38+
run: pip install -e .[test]
39+
40+
- name: Run benchmarks
41+
uses: CodSpeedHQ/action@v3
42+
with:
43+
token: ${{ secrets.CODSPEED_TOKEN }}
44+
run: pytest tests/ --codspeed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ tracker = "https://github.com/commit-check/commit-check/issues"
4242

4343
[project.optional-dependencies]
4444
dev = ['nox']
45-
test = ['coverage', 'pytest', 'pytest-mock']
45+
test = ['coverage', 'pytest', 'pytest-mock', 'pytest-codspeed']
4646
docs = ['sphinx-immaterial', 'sphinx-autobuild']
4747

4848
[tool.setuptools]

tests/author_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from commit_check import PASS, FAIL
23
from commit_check.author import check_author
34

@@ -11,6 +12,7 @@ class TestAuthorName:
1112
fake_author_value_an = "fake_author_name"
1213
fake_accented_author_value_an = "fáké_áúthór_námé"
1314

15+
@pytest.mark.benchmark
1416
def test_check_author(self, mocker):
1517
# Must call get_commit_info, re.match.
1618
checks = [{
@@ -30,6 +32,7 @@ def test_check_author(self, mocker):
3032
assert m_get_commit_info.call_count == 1
3133
assert m_re_match.call_count == 1
3234

35+
@pytest.mark.benchmark
3336
def test_check_author_with_accented_letters(self, mocker):
3437
# Must call get_commit_info, re.match.
3538
checks = [{
@@ -49,6 +52,7 @@ def test_check_author_with_accented_letters(self, mocker):
4952
assert m_get_commit_info.call_count == 1
5053
assert m_re_match.call_count == 1
5154

55+
@pytest.mark.benchmark
5256
def test_check_author_with_empty_checks(self, mocker):
5357
# Must NOT call get_commit_info, re.match. with `checks` param with length 0.
5458
checks = []
@@ -65,6 +69,7 @@ def test_check_author_with_empty_checks(self, mocker):
6569
assert m_get_commit_info.call_count == 0
6670
assert m_re_match.call_count == 0
6771

72+
@pytest.mark.benchmark
6873
def test_check_author_with_different_check(self, mocker):
6974
# Must NOT call get_commit_info, re.match with not `author_name`.
7075
checks = [{
@@ -84,6 +89,7 @@ def test_check_author_with_different_check(self, mocker):
8489
assert m_get_commit_info.call_count == 0
8590
assert m_re_match.call_count == 0
8691

92+
@pytest.mark.benchmark
8793
def test_check_author_with_len0_regex(self, mocker, capfd):
8894
# Must NOT call get_commit_info, re.match with `regex` with length 0.
8995
checks = [
@@ -107,6 +113,7 @@ def test_check_author_with_len0_regex(self, mocker, capfd):
107113
out, _ = capfd.readouterr()
108114
assert "Not found regex for author_name." in out
109115

116+
@pytest.mark.benchmark
110117
def test_check_author_with_result_none(self, mocker):
111118
# Must call print_error_message, print_suggestion when re.match returns NONE.
112119
checks = [{
@@ -140,6 +147,7 @@ class TestAuthorEmail:
140147
# used by get_commit_info mock
141148
fake_author_value_ae = "fake_author_email"
142149

150+
@pytest.mark.benchmark
143151
def test_check_author(self, mocker):
144152
# Must call get_commit_info, re.match.
145153
checks = [{
@@ -159,6 +167,7 @@ def test_check_author(self, mocker):
159167
assert m_get_commit_info.call_count == 1
160168
assert m_re_match.call_count == 1
161169

170+
@pytest.mark.benchmark
162171
def test_check_author_with_empty_checks(self, mocker):
163172
# Must NOT call get_commit_info, re.match. with `checks` param with length 0.
164173
checks = []
@@ -175,6 +184,7 @@ def test_check_author_with_empty_checks(self, mocker):
175184
assert m_get_commit_info.call_count == 0
176185
assert m_re_match.call_count == 0
177186

187+
@pytest.mark.benchmark
178188
def test_check_author_with_different_check(self, mocker):
179189
# Must NOT call get_commit_info, re.match with not `author_email`.
180190
checks = [{
@@ -194,6 +204,7 @@ def test_check_author_with_different_check(self, mocker):
194204
assert m_get_commit_info.call_count == 0
195205
assert m_re_match.call_count == 0
196206

207+
@pytest.mark.benchmark
197208
def test_check_author_with_len0_regex(self, mocker, capfd):
198209
# Must NOT call get_commit_info, re.match with `regex` with length 0.
199210
checks = [
@@ -217,6 +228,7 @@ def test_check_author_with_len0_regex(self, mocker, capfd):
217228
out, _ = capfd.readouterr()
218229
assert "Not found regex for author_email." in out
219230

231+
@pytest.mark.benchmark
220232
def test_check_author_with_result_none(self, mocker):
221233
# Must call print_error_message, print_suggestion when re.match returns NONE.
222234
checks = [{

tests/branch_test.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from commit_check import PASS, FAIL
23
from commit_check.branch import check_branch, check_merge_base
34

@@ -7,6 +8,7 @@
78

89

910
class TestCheckBranch:
11+
@pytest.mark.benchmark
1012
def test_check_branch(self, mocker):
1113
# Must call get_branch_name, re.match at once.
1214
checks = [{
@@ -26,6 +28,7 @@ def test_check_branch(self, mocker):
2628
assert m_get_branch_name.call_count == 1
2729
assert m_re_match.call_count == 1
2830

31+
@pytest.mark.benchmark
2932
def test_check_branch_with_empty_checks(self, mocker):
3033
# Must NOT call get_branch_name, re.match with `checks` param with length 0.
3134
checks = []
@@ -42,6 +45,7 @@ def test_check_branch_with_empty_checks(self, mocker):
4245
assert m_get_branch_name.call_count == 0
4346
assert m_re_match.call_count == 0
4447

48+
@pytest.mark.benchmark
4549
def test_check_branch_with_different_check(self, mocker):
4650
# Must NOT call get_branch_name, re.match with not `branch`.
4751
checks = [{
@@ -61,6 +65,7 @@ def test_check_branch_with_different_check(self, mocker):
6165
assert m_get_branch_name.call_count == 0
6266
assert m_re_match.call_count == 0
6367

68+
@pytest.mark.benchmark
6469
def test_check_branch_with_len0_regex(self, mocker, capfd):
6570
# Must NOT call get_branch_name, re.match with `regex` with length 0.
6671
checks = [
@@ -84,6 +89,7 @@ def test_check_branch_with_len0_regex(self, mocker, capfd):
8489
out, _ = capfd.readouterr()
8590
assert "Not found regex for branch naming." in out
8691

92+
@pytest.mark.benchmark
8793
def test_check_branch_with_result_none(self, mocker):
8894
# Must call print_error_message, print_suggestion when re.match returns NONE.
8995
checks = [{
@@ -115,14 +121,15 @@ def test_check_branch_with_result_none(self, mocker):
115121

116122

117123
class TestCheckMergeBase:
124+
@pytest.mark.benchmark
118125
def test_check_merge_base_with_empty_checks(self, mocker):
119126
checks = []
120127
m_check_merge = mocker.patch(f"{LOCATION}.check_merge_base")
121128
retval = check_merge_base(checks)
122129
assert retval == PASS
123130
assert m_check_merge.call_count == 0
124131

125-
132+
@pytest.mark.benchmark
126133
def test_check_merge_base_with_empty_regex(self, mocker):
127134
checks = [{
128135
"check": "merge_base",
@@ -133,6 +140,7 @@ def test_check_merge_base_with_empty_regex(self, mocker):
133140
assert retval == PASS
134141
assert m_check_merge.call_count == 0
135142

143+
@pytest.mark.benchmark
136144
def test_check_merge_base_with_different_check(self, mocker):
137145
checks = [{
138146
"check": "branch",
@@ -143,6 +151,7 @@ def test_check_merge_base_with_different_check(self, mocker):
143151
assert retval == PASS
144152
assert m_check_merge.call_count == 0
145153

154+
@pytest.mark.benchmark
146155
def test_check_merge_base_fail_with_messages(self, mocker, capfd):
147156
checks = [{
148157
"check": "merge_base",

tests/commit_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from commit_check import PASS, FAIL
23
from commit_check.commit import check_commit_msg, get_default_commit_msg_file, read_commit_msg, check_commit_signoff
34

@@ -9,11 +10,13 @@
910
MSG_FILE = '.git/COMMIT_EDITMSG'
1011

1112

13+
@pytest.mark.benchmark
1214
def test_get_default_commit_msg_file(mocker):
1315
retval = get_default_commit_msg_file()
1416
assert retval == ".git/COMMIT_EDITMSG"
1517

1618

19+
@pytest.mark.benchmark
1720
def test_read_commit_msg_from_existing_file(tmp_path):
1821
# Create a temporary file with a known content
1922
commit_msg_content = "Test commit message content."
@@ -24,12 +27,14 @@ def test_read_commit_msg_from_existing_file(tmp_path):
2427
assert result == commit_msg_content
2528

2629

30+
@pytest.mark.benchmark
2731
def test_read_commit_msg_file_not_found(mocker):
2832
m_commits_info = mocker.patch('commit_check.util.get_commit_info', return_value='mocked_commits_info')
2933
read_commit_msg("non_existent_file.txt")
3034
assert m_commits_info.call_count == 0
3135

3236

37+
@pytest.mark.benchmark
3338
def test_check_commit_msg_no_commit_msg_file(mocker):
3439
mock_get_default_commit_msg_file = mocker.patch(
3540
"commit_check.commit.get_default_commit_msg_file",
@@ -49,6 +54,7 @@ def test_check_commit_msg_no_commit_msg_file(mocker):
4954
assert result == 0
5055

5156

57+
@pytest.mark.benchmark
5258
def test_check_commit_with_empty_checks(mocker):
5359
checks = []
5460
m_re_match = mocker.patch(
@@ -60,6 +66,7 @@ def test_check_commit_with_empty_checks(mocker):
6066
assert m_re_match.call_count == 0
6167

6268

69+
@pytest.mark.benchmark
6370
def test_check_commit_with_different_check(mocker):
6471
checks = [{
6572
"check": "branch",
@@ -74,6 +81,7 @@ def test_check_commit_with_different_check(mocker):
7481
assert m_re_match.call_count == 0
7582

7683

84+
@pytest.mark.benchmark
7785
def test_check_commit_with_len0_regex(mocker, capfd):
7886
checks = [
7987
{
@@ -92,6 +100,7 @@ def test_check_commit_with_len0_regex(mocker, capfd):
92100
assert "Not found regex for commit message." in out
93101

94102

103+
@pytest.mark.benchmark
95104
def test_check_commit_with_result_none(mocker):
96105
checks = [{
97106
"check": "message",
@@ -116,6 +125,7 @@ def test_check_commit_with_result_none(mocker):
116125
assert m_print_suggestion.call_count == 1
117126

118127

128+
@pytest.mark.benchmark
119129
def test_check_commit_signoff(mocker):
120130
checks = [{
121131
"check": "commit_signoff",
@@ -140,6 +150,7 @@ def test_check_commit_signoff(mocker):
140150
assert m_print_suggestion.call_count == 1
141151

142152

153+
@pytest.mark.benchmark
143154
def test_check_commit_signoff_with_empty_regex(mocker):
144155
checks = [{
145156
"check": "commit_signoff",
@@ -156,6 +167,7 @@ def test_check_commit_signoff_with_empty_regex(mocker):
156167
assert m_re_match.call_count == 0
157168

158169

170+
@pytest.mark.benchmark
159171
def test_check_commit_signoff_with_empty_checks(mocker):
160172
checks = []
161173
m_re_match = mocker.patch(

tests/error_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@
33
from commit_check.error import error_handler, log_and_exit
44

55

6+
@pytest.mark.benchmark
67
def test_error_handler_RuntimeError():
78
with pytest.raises(SystemExit) as exit_info:
89
with error_handler():
910
raise RuntimeError("Test error")
1011
assert exit_info.value.code == 1
1112

1213

14+
@pytest.mark.benchmark
1315
def test_error_handler_KeyboardInterrupt():
1416
with pytest.raises(SystemExit) as exit_info:
1517
with error_handler():
1618
raise KeyboardInterrupt
1719
assert exit_info.value.code == 130
1820

1921

22+
@pytest.mark.benchmark
2023
def test_error_handler_unexpected_error():
2124
with pytest.raises(SystemExit) as exit_info:
2225
with error_handler():
2326
raise Exception("Test error")
2427
assert exit_info.value.code == 3
2528

2629

30+
@pytest.mark.benchmark
2731
def test_error_handler_cannot_access(mocker):
2832
with pytest.raises(SystemExit):
2933
store_dir = "/fake/commit-check"
@@ -50,6 +54,7 @@ def test_error_handler_cannot_access(mocker):
5054
mock_open().write.assert_any_call(f"Failed to write to log at {log_path}\n")
5155

5256

57+
@pytest.mark.benchmark
5358
@pytest.mark.xfail
5459
def test_log_and_exit(monkeypatch):
5560
monkeypatch.setenv("COMMIT_CHECK_HOME", "")

tests/main_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
class TestMain:
10+
@pytest.mark.benchmark
1011
@pytest.mark.parametrize("argv, check_commit_call_count, check_branch_call_count, check_author_call_count, check_commit_signoff_call_count, check_merge_base_call_count", [
1112
([CMD, "--message"], 1, 0, 0, 0, 0),
1213
([CMD, "--branch"], 0, 1, 0, 0, 0),
@@ -53,6 +54,7 @@ def test_main(
5354
assert m_check_commit_signoff.call_count == check_commit_signoff_call_count
5455
assert m_check_merge_base.call_count == check_merge_base_call_count
5556

57+
@pytest.mark.benchmark
5658
def test_main_help(self, mocker, capfd):
5759
mocker.patch(
5860
"commit_check.main.validate_config",
@@ -78,6 +80,7 @@ def test_main_help(self, mocker, capfd):
7880
stdout, _ = capfd.readouterr()
7981
assert "usage: " in stdout
8082

83+
@pytest.mark.benchmark
8184
def test_main_version(self, mocker):
8285
mocker.patch(
8386
"commit_check.main.validate_config",
@@ -101,6 +104,7 @@ def test_main_version(self, mocker):
101104
assert m_check_commit_signoff.call_count == 0
102105
assert m_check_merge_base.call_count == 0
103106

107+
@pytest.mark.benchmark
104108
def test_main_validate_config_ret_none(self, mocker):
105109
mocker.patch(
106110
"commit_check.main.validate_config",
@@ -116,6 +120,7 @@ def test_main_validate_config_ret_none(self, mocker):
116120
assert m_check_commit.call_count == 1
117121
assert m_check_commit.call_args[0][0] == DEFAULT_CONFIG["checks"]
118122

123+
@pytest.mark.benchmark
119124
@pytest.mark.parametrize(
120125
"argv, message_result, branch_result, author_name_result, author_email_result, commit_signoff_result, merge_base_result, final_result",
121126
[

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy