From bdff2a12876fcd7a7f6d4953a49ad5dcc218a873 Mon Sep 17 00:00:00 2001 From: Jannis-Mittenzwei <145327095+Jannis-Mittenzwei@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:15:35 +0100 Subject: [PATCH] Fix creating workflow if if directory .github/workflows already exists #298 (#312) --------- Co-authored-by: Nicola Coretti --- doc/changes/unreleased.md | 1 + exasol/toolbox/tools/template.py | 4 ++-- exasol/toolbox/tools/workflow.py | 1 - .../cli/issue-install-if-github-directory-exist.t | 7 +++++++ test/integration/cli/issue-install-if-issue-exist | 12 ++++++++++++ .../cli/workflow-install-if-github-directory-exist.t | 6 ++++++ .../cli/workflow-install-if-workflow-exists | 12 ++++++++++++ 7 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/integration/cli/issue-install-if-github-directory-exist.t create mode 100644 test/integration/cli/issue-install-if-issue-exist create mode 100644 test/integration/cli/workflow-install-if-github-directory-exist.t create mode 100644 test/integration/cli/workflow-install-if-workflow-exists diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index 4e5b64a91..8311d0e44 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -43,3 +43,4 @@ * Fixed `index.rst` documentation template to provide the correct underlining length of the main heading * Added multi-version extension to Sphinx configuration of the project template +* fixed bug in tbx worflow install error if directory exists[#298](https://github.com/exasol/python-toolbox/issues/298) also [#297](https://github.com/exasol/python-toolbox/issues/297) \ No newline at end of file diff --git a/exasol/toolbox/tools/template.py b/exasol/toolbox/tools/template.py index 8dbdde8ec..37b3aa80f 100644 --- a/exasol/toolbox/tools/template.py +++ b/exasol/toolbox/tools/template.py @@ -120,7 +120,7 @@ def install_template(template: str, dest: Path, pkg: str, template_type: str) -> Attention: If there is an existing template with the same name it will be overwritten! """ if not dest.exists(): - dest.mkdir() + dest.mkdir(parents=True) try: templates = _select_templates(template, pkg, template_type) @@ -139,7 +139,7 @@ def update_template( ) -> None: """Similar to install but checks for existing templates and shows diff""" if not dest.exists(): - dest.mkdir() + dest.mkdir(parents=True) try: templates = _select_templates(template, pkg, template_type) diff --git a/exasol/toolbox/tools/workflow.py b/exasol/toolbox/tools/workflow.py index 6537630cf..e948ce485 100644 --- a/exasol/toolbox/tools/workflow.py +++ b/exasol/toolbox/tools/workflow.py @@ -56,7 +56,6 @@ def install_workflow( Attention: If there is an existing workflow with the same name it will be overwritten! """ - dest.mkdir(parents=True) template.install_template( template=workflow, dest=dest, pkg=PKG, template_type=TEMPLATE_TYPE ) diff --git a/test/integration/cli/issue-install-if-github-directory-exist.t b/test/integration/cli/issue-install-if-github-directory-exist.t new file mode 100644 index 000000000..9797ee31f --- /dev/null +++ b/test/integration/cli/issue-install-if-github-directory-exist.t @@ -0,0 +1,7 @@ +Create project directory + $ mkdir .github + $ mkdir -p .github/workflows + +install issue + $ tbx issue install bug + Installed bug in .github/ISSUE_TEMPLATE/bug.md diff --git a/test/integration/cli/issue-install-if-issue-exist b/test/integration/cli/issue-install-if-issue-exist new file mode 100644 index 000000000..615741633 --- /dev/null +++ b/test/integration/cli/issue-install-if-issue-exist @@ -0,0 +1,12 @@ +install issue template + $ tbx issue install feature + Installed feature in .github/ISSUE_TEMPLATE/feature.md + +install another issue template + $ tbx issue install bug + Installed bug in .github/ISSUE_TEMPLATE/bug.md + +Install another issue template while an issue template with the same name already exists + $ touch .github/ISSUE_TEMPLATE/refactoring.md + $ tbx issue install refactoring + Installed refactoring in .github/ISSUE_TEMPLATE/refactoring.md \ No newline at end of file diff --git a/test/integration/cli/workflow-install-if-github-directory-exist.t b/test/integration/cli/workflow-install-if-github-directory-exist.t new file mode 100644 index 000000000..e64f47d3b --- /dev/null +++ b/test/integration/cli/workflow-install-if-github-directory-exist.t @@ -0,0 +1,6 @@ +Create project directory + $ mkdir -p .github/workflows + +install workflow + $ tbx workflow install pr-merge + Installed pr-merge in .github/workflows/pr-merge.yml diff --git a/test/integration/cli/workflow-install-if-workflow-exists b/test/integration/cli/workflow-install-if-workflow-exists new file mode 100644 index 000000000..b7fb5f18e --- /dev/null +++ b/test/integration/cli/workflow-install-if-workflow-exists @@ -0,0 +1,12 @@ +install workflow + $ tbx workflow install cd + Installed cd in .github/workflows/cd.yml + +install another workflow + $ tbx workflow install checks + Installed checks in .github/workflows/checks.yml + +install workflow while a workflow with this name already exists + $ touch .github/workflows/ci.yml + $ tbx workflow install ci + Installed ci in .github/workflows/ci.yml \ No newline at end of file