Skip to content

Commit 906dd25

Browse files
committed
refactor: clean up setting helper script executable
1 parent d4a27b4 commit 906dd25

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

src/ci_starter/cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
LOCKFILE_ARTIFACT,
2525
SEMANTIC_RELEASE_CONFIG_FILE,
2626
)
27-
from ..utils import dump
27+
from ..utils import dump, make_path_executable
2828
from .callbacks import WorkDir as WorkDir
2929
from .callbacks import get_package_name, set_module_name, set_workdir
3030
from .validations import validate_test_group, validate_workflow_file_name
@@ -101,7 +101,7 @@ def workflows(
101101
with workdir.helper_script.open("w", encoding="utf-8") as script_file:
102102
script: str = generate_helper_script()
103103
script_file.write(script)
104-
_make_script_executable = workdir.helper_script.chmod(0o755)
104+
make_path_executable(workdir.helper_script)
105105

106106
base_workflow_file = workdir.workflows / workflow_file_name.name
107107
with base_workflow_file.open("w", encoding="utf-8") as base_workflow:

src/ci_starter/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from collections.abc import Iterable, Mapping
22
from pathlib import Path
3+
from stat import S_IXGRP as EXECUTABLE_FOR_GROUP
4+
from stat import S_IXOTH as EXECUTABLE_FOR_OTHERS
5+
from stat import S_IXUSR as EXECUTABLE_FOR_USER
36
from sys import version_info
47
from typing import TYPE_CHECKING, Any, TextIO
58

@@ -92,3 +95,9 @@ def compare(actual: Version, expected: Version) -> str:
9295
elif actual.compare(expected) == -1:
9396
return "older"
9497
return "same"
98+
99+
100+
def make_path_executable(path: Path) -> None:
101+
old_mode = path.stat().st_mode
102+
executable = old_mode | EXECUTABLE_FOR_USER | EXECUTABLE_FOR_GROUP | EXECUTABLE_FOR_OTHERS
103+
path.chmod(executable)

tests/e2e/test_helper_script.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
from stat import S_IXGRP as EXECUTABLE_FOR_GROUP
3+
from stat import S_IXOTH as EXECUTABLE_FOR_OTHERS
4+
from stat import S_IXUSR as EXECUTABLE_FOR_USER
5+
6+
from click.testing import CliRunner, Result
7+
8+
from ci_starter.cli import cli
9+
from ci_starter.constants import HELPER_SCRIPT_FILE_PATH
10+
from tests.e2e.constants import SUCCESSFUL_RETURN_CODE
11+
12+
13+
def is_executable(path: Path) -> bool:
14+
mode = path.stat().st_mode
15+
return all((mode | EXECUTABLE_FOR_USER, mode | EXECUTABLE_FOR_GROUP, mode | EXECUTABLE_FOR_OTHERS))
16+
17+
18+
def test_verify_remote_has_not_changed_is_executable(test_project_path_str: str, cli_runner: CliRunner):
19+
result: Result = cli_runner.invoke(cli, ["-C", test_project_path_str, "workflows"])
20+
assert result.exit_code == SUCCESSFUL_RETURN_CODE
21+
22+
script = Path(test_project_path_str, HELPER_SCRIPT_FILE_PATH)
23+
24+
assert is_executable(script)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
from stat import S_IXGRP as EXECUTABLE_FOR_GROUP
3+
from stat import S_IXOTH as EXECUTABLE_FOR_OTHERS
4+
from stat import S_IXUSR as EXECUTABLE_FOR_USER
5+
6+
from click.testing import CliRunner, Result
7+
8+
from ci_starter.cli import cli
9+
from ci_starter.constants import HELPER_SCRIPT_FILE_PATH
10+
from tests.e2e.constants import SUCCESSFUL_RETURN_CODE
11+
12+
13+
def is_executable(path: Path) -> bool:
14+
mode = path.stat().st_mode
15+
return all((mode | EXECUTABLE_FOR_USER, mode | EXECUTABLE_FOR_GROUP, mode | EXECUTABLE_FOR_OTHERS))
16+
17+
18+
def test_helper_script_is_executable(test_project_path_str: str, cli_runner: CliRunner):
19+
result: Result = cli_runner.invoke(cli, ["-C", test_project_path_str, "workflows"])
20+
assert result.exit_code == SUCCESSFUL_RETURN_CODE
21+
22+
script = Path(test_project_path_str, HELPER_SCRIPT_FILE_PATH)
23+
24+
assert is_executable(script)

0 commit comments

Comments
 (0)