Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Specify bash shell in CI Workflows #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e82cfb1
fix(pythonpackage.yml): use `bash`
adam-grant-hendry Oct 17, 2022
906cf00
ci: rerun workflow
adam-grant-hendry Oct 19, 2022
d858b96
fix(pythonpackage.yml): undo indent reformatting
adam-grant-hendry Oct 19, 2022
c3a446b
fix(scripts): use portable shebang
adam-grant-hendry Oct 19, 2022
8557a3b
fix(scripts): use cross-platform POSIX
adam-grant-hendry Oct 19, 2022
8822bf3
ci: rerun workflow
adam-grant-hendry Oct 19, 2022
8176121
test(conf.py): don't set `GNUPGHOME` on Windows
adam-grant-hendry Oct 19, 2022
6d59a5b
test(conf.py): remove `os.linesep`
adam-grant-hendry Oct 19, 2022
7cd675f
test(test_init_command.py): use `os.sep`
adam-grant-hendry Oct 19, 2022
dc07120
test(bump): handle Windows path separator
adam-grant-hendry Oct 20, 2022
500cf71
test(cli): skip argcomplete activation on Windows
adam-grant-hendry Oct 20, 2022
9d40918
test(commit): use double-quotes
adam-grant-hendry Oct 20, 2022
d1a2919
test(bump_command): use `/` path separator
adam-grant-hendry Oct 20, 2022
6a963a8
fix(bump.py): use `sys.stdin.isatty()`
adam-grant-hendry Oct 20, 2022
d936262
fix(scripts): pydocstyle and cz
adam-grant-hendry Oct 20, 2022
53ac7c9
feat(scripts): add error message to `test`
adam-grant-hendry Oct 20, 2022
4536f93
test(argcomplete): fix command
adam-grant-hendry Oct 20, 2022
24adbcd
feat(scripts): remove `venv/bin/`
adam-grant-hendry Oct 20, 2022
db5131e
fix(scripts/test): use double-quotes
adam-grant-hendry Oct 20, 2022
5d1eaba
ci(rerun): random `poetry` exception
adam-grant-hendry Oct 20, 2022
a079fe4
fix(scripts/test): MinGW64 workaround
adam-grant-hendry Oct 20, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
./scripts/test
shell: bash
- name: Upload coverage to Codecov
if: runner.os == 'Linux'
uses: codecov/codecov-action@v1.0.3
Expand Down
5 changes: 4 additions & 1 deletion commitizen/bump.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
from collections import OrderedDict
from itertools import zip_longest
Expand Down Expand Up @@ -155,7 +156,9 @@ def update_version_in_files(
"""
# TODO: separate check step and write step
for location in files:
filepath, _, regex = location.partition(":")
drive, tail = os.path.splitdrive(location)
path, _, regex = tail.partition(":")
filepath = drive + path
if not regex:
regex = _version_to_regex(current_version)

Expand Down
9 changes: 8 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from logging import getLogger
from typing import List, Optional

Expand Down Expand Up @@ -230,9 +231,15 @@ def __call__(self): # noqa: C901
},
)
changelog_cmd()
file_names = []
for file_name in version_files:
drive, tail = os.path.splitdrive(file_name)
path, _, regex = tail.partition(":")
path = drive + path if path != "" else drive + regex
file_names.append(path)
git_add_changelog_and_version_files_command = (
f"git add {changelog_cmd.file_name} "
f"{' '.join(file_name.partition(':')[0] for file_name in version_files)}"
f"{' '.join(name for name in file_names)}"
)
c = cmd.run(git_add_changelog_and_version_files_command)

Expand Down
2 changes: 1 addition & 1 deletion commitizen/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _valid_command_argument(self):
arg is not None
for arg in (self.commit_msg_file, self.commit_msg, self.rev_range)
)
if num_exclusive_args_provided == 0 and not os.isatty(0):
if num_exclusive_args_provided == 0 and not sys.stdin.isatty():
self.commit_msg: Optional[str] = sys.stdin.read()
elif num_exclusive_args_provided != 1:
raise InvalidCommandArgumentError(
Expand Down
6 changes: 2 additions & 4 deletions scripts/format
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/sh -e
#!/usr/bin/env sh
set -e

export PREFIX="poetry run python -m "
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi

set -x

Expand Down
11 changes: 5 additions & 6 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/sh -e
#!/usr/bin/env sh
set -e

export PREFIX="poetry run python -m "
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
export PREFIX='poetry run python -m '
export REGEX='^(?![.]|venv).*'

${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/
${PREFIX}black commitizen tests --check
${PREFIX}isort --check-only commitizen tests
${PREFIX}flake8 commitizen/ tests/
${PREFIX}mypy commitizen/ tests/
${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415
${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 --match-dir='"${REGEX}"'
${PREFIX}commitizen check --rev-range origin/master..
9 changes: 6 additions & 3 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,10 @@ def test_bump_when_version_inconsistent_in_version_files(
tmp_version_file = tmp_commitizen_project.join("__version__.py")
tmp_version_file.write("100.999.10000")
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_version_file_string = str(tmp_version_file).replace("\\", "/")
tmp_commitizen_cfg_file.write(
f"{tmp_commitizen_cfg_file.read()}\n"
f'version_files = ["{str(tmp_version_file)}"]'
f'version_files = ["{tmp_version_file_string}"]'
)

create_file_and_commit("feat: new file")
Expand All @@ -323,9 +324,10 @@ def test_bump_files_only(mocker, tmp_commitizen_project):
tmp_version_file = tmp_commitizen_project.join("__version__.py")
tmp_version_file.write("0.1.0")
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_version_file_string = str(tmp_version_file).replace("\\", "/")
tmp_commitizen_cfg_file.write(
f"{tmp_commitizen_cfg_file.read()}\n"
f'version_files = ["{str(tmp_version_file)}"]'
f'version_files = ["{tmp_version_file_string}"]'
)

create_file_and_commit("feat: new user interface")
Expand Down Expand Up @@ -355,10 +357,11 @@ def test_bump_local_version(mocker, tmp_commitizen_project):
tmp_version_file = tmp_commitizen_project.join("__version__.py")
tmp_version_file.write("4.5.1+0.1.0")
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_version_file_string = str(tmp_version_file).replace("\\", "/")
tmp_commitizen_cfg_file.write(
f"[tool.commitizen]\n"
'version="4.5.1+0.1.0"\n'
f'version_files = ["{str(tmp_version_file)}"]'
f'version_files = ["{tmp_version_file_string}"]'
)

create_file_and_commit("feat: new user interface")
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker, config):

def test_init_when_config_already_exists(config, capsys):
# Set config path
path = "tests/pyproject.toml"
path = os.sep.join(["tests", "pyproject.toml"])
config.add_path(path)

commands.Init(config)()
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def tmp_commitizen_project(tmp_git_project):
def _get_gpg_keyid(signer_mail):
_new_key = cmd.run(f"gpg --list-secret-keys {signer_mail}")
_m = re.search(
rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*",
r"[a-zA-Z0-9 \[\]-_]*\n[ ]*([0-9A-Za-z]*)\n[\na-zA-Z0-9 \[\]-_<>@]*",
_new_key.out,
)
return _m.group(1) if _m else None
Expand All @@ -42,7 +42,8 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project):
# create a temporary GPGHOME to store a temporary keyring.
# Home path must be less than 104 characters
gpg_home = tempfile.TemporaryDirectory(suffix="_cz")
os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring
if os.name != "nt":
os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring

# create a key (a keyring will be generated within GPUPGHOME)
c = cmd.run(
Expand Down
11 changes: 9 additions & 2 deletions tests/test_bump_create_commit_message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from pathlib import Path
from textwrap import dedent
Expand Down Expand Up @@ -55,7 +56,10 @@ def test_bump_pre_commit_changelog(tmp_commitizen_project, mocker, freezer, retr
"""
)
cmd.run("git add -A")
cmd.run("git commit -m 'fix: _test'")
if os.name == "nt":
cmd.run('git commit -m "fix: _test"')
else:
cmd.run("git commit -m 'fix: _test'")
cmd.run("pre-commit install")
cli.main()
# Pre-commit fixed last line adding extra indent and "\" char
Expand Down Expand Up @@ -93,7 +97,10 @@ def test_bump_pre_commit_changelog_fails_always(
"""
)
cmd.run("git add -A")
cmd.run("git commit -m 'feat: forbid changelogs'")
if os.name == "nt":
cmd.run('git commit -m "feat: forbid changelogs"')
else:
cmd.run("git commit -m 'feat: forbid changelogs'")
cmd.run("pre-commit install")
with pytest.raises(exceptions.BumpCommitFailedError):
cli.main()
6 changes: 3 additions & 3 deletions tests/test_bump_update_version_in_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
def _copy_sample_file_to_tmpdir(
tmpdir: LocalPath, source_filename: str, dest_filename: str
) -> str:
tmp_file = tmpdir.join(dest_filename)
copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file))
return str(tmp_file)
tmp_file = str(tmpdir.join(dest_filename)).replace("\\", "/")
copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", tmp_file)
return tmp_file


@pytest.fixture(scope="function")
Expand Down
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import subprocess
import sys

Expand Down Expand Up @@ -84,6 +85,10 @@ def test_commitizen_debug_excepthook(capsys):
assert "NotAGitProjectError" in str(excinfo.traceback[0])


@pytest.mark.skipif(
os.name == "nt",
reason="`argcomplete` does not support Git Bash on Windows.",
)
def test_argcomplete_activation():
"""
This function is testing the one-time activation of argcomplete for
Expand Down
5 changes: 4 additions & 1 deletion tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ def test_is_staging_clean_when_updating_file(tmp_commitizen_project):

cmd.run("touch test_file")
cmd.run("git add test_file")
cmd.run("git commit -m 'add test_file'")
if os.name == "nt":
cmd.run('git commit -m "add test_file"')
else:
cmd.run("git commit -m 'add test_file'")
cmd.run("echo 'test' > test_file")

assert git.is_staging_clean() is True
Expand Down