Skip to content

Commit 08ddf2a

Browse files
authored
Fix issues in CI and updating projects (frequenz-floss#70)
- Don't copy the replay file if it already exists - Add function to recursively move files overwriting the target - Fix updating `lib` projects - Fix CI mkdocs related jobs not to use `env` - Improve the suggested `rsync` command for updates
2 parents 6accc2a + 67e1039 commit 08ddf2a

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
# To speed things up a bit we use the speciall ci_checks_max session
5454
# that uses the same venv to run multiple linting sessions
5555
run: nox -e ci_checks_max pytest_min
56-
timeout-minutes: 10
56+
timeout-minutes: 60
5757

5858
build:
5959
name: Build distribution packages
@@ -86,7 +86,7 @@ jobs:
8686
test-docs:
8787
name: Test documentation website generation
8888
if: github.event_name != 'push'
89-
runs-on: ubuntu-${{ env.DEFAULT_UBUNTU_VERSION }}
89+
runs-on: ubuntu-20.04
9090
steps:
9191
- name: Fetch sources
9292
uses: actions/checkout@v3
@@ -121,9 +121,9 @@ jobs:
121121

122122
publish-docs:
123123
name: Publish documentation website to GitHub pages
124-
needs: ["test", "build"]
124+
needs: ["nox", "build"]
125125
if: github.event_name == 'push'
126-
runs-on: ubuntu-${{ env.DEFAULT_UBUNTU_VERSION }}
126+
runs-on: ubuntu-20.04
127127
permissions:
128128
contents: write
129129
steps:

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ the files in your existing project by using `rsync` or similar tools:
7171
```sh
7272
cd /tmp
7373
cookiecutter gh:frequenz-floss/frequenz-repo-config-python --directory=cookiecutter
74-
rsync -r new-project/ /path/to/existing/project
74+
rsync -vr --exclude=.git/ new-project/ /path/to/existing/project
7575
cd /path/to/existing/project
7676
git diff
7777
# Fix all the `TODO`s and cleanup the generated files
@@ -83,6 +83,9 @@ git commit -a
8383
The trailing slash in `new-project/` and the lack of it in
8484
`/path/to/existing/project` are meaningful to `rsync`.
8585

86+
Also make sure to **exclude** the `.git/` directory to avoid messing up
87+
with your local git repository.
88+
8689
## Update an existing project
8790

8891
To update an existing project you can use the [Cookiecutter *replay

cookiecutter/hooks/post_gen_project.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ def copy_replay_file() -> None:
116116
"""Copy the replay file to the project root."""
117117
src = _pathlib.Path("~/.cookiecutter_replay/cookiecutter.json").expanduser()
118118
dst = _pathlib.Path(".cookiecutter-replay.json")
119+
120+
if dst.exists():
121+
print(f"Replay file {dst} already exists. Skipping...")
122+
return
123+
119124
if not src.exists():
120125
print(f"WARNING: No replay file found in {src}. Skipping...")
121126

@@ -376,12 +381,8 @@ def finish_api_setup() -> None:
376381
* Rename `src` to `py`
377382
* Rename `tests` to `pytests`
378383
"""
379-
# We can't do a simple rename because the target directory might not be empty if
380-
# overwriting an existing project.
381-
_shutil.copytree("src", "py", dirs_exist_ok=True)
382-
_shutil.rmtree("src")
383-
_shutil.copytree("tests", "pytests", dirs_exist_ok=True)
384-
_shutil.rmtree("tests")
384+
recursive_overwrite_move(_pathlib.Path("src"), _pathlib.Path("py"))
385+
recursive_overwrite_move(_pathlib.Path("tests"), _pathlib.Path("pytests"))
385386

386387

387388
def finish_app_setup() -> None:
@@ -405,8 +406,9 @@ def finish_lib_setup() -> None:
405406
- `lib`: `src/frequenz/{name}`
406407
- `rest`: `src/frequenz/{type}/{name}`
407408
"""
408-
_pathlib.Path(f"src/frequenz/{cookiecutter.type}/{cookiecutter.name}").rename(
409-
f"src/frequenz/{cookiecutter.name}"
409+
recursive_overwrite_move(
410+
_pathlib.Path(f"src/frequenz/{cookiecutter.type}/{cookiecutter.name}"),
411+
_pathlib.Path(f"src/frequenz/{cookiecutter.name}"),
410412
)
411413
_pathlib.Path(f"src/frequenz/{cookiecutter.type}").rmdir()
412414

@@ -466,6 +468,19 @@ def try_run(
466468
return result
467469

468470

471+
def recursive_overwrite_move(src: _pathlib.Path, dst: _pathlib.Path) -> None:
472+
"""Recursively move a directory overwriting the target files if they exist.
473+
474+
Useful when overwriting an existing project to update it.
475+
476+
Args:
477+
src: The source directory.
478+
dst: The target directory.
479+
"""
480+
_shutil.copytree(src, dst, dirs_exist_ok=True)
481+
_shutil.rmtree(src)
482+
483+
469484
def success(message: str) -> None:
470485
"""Print a success message.
471486

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
test-docs:
8787
name: Test documentation website generation
8888
if: github.event_name != 'push'
89-
runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}}
89+
runs-on: ubuntu-20.04
9090
steps:
9191
- name: Fetch sources
9292
uses: actions/checkout@v3
@@ -121,9 +121,9 @@ jobs:
121121

122122
publish-docs:
123123
name: Publish documentation website to GitHub pages
124-
needs: ["test", "build"]
124+
needs: ["nox", "build"]
125125
if: github.event_name == 'push'
126-
runs-on: ubuntu-{{'${{ env.DEFAULT_UBUNTU_VERSION }}'}}
126+
runs-on: ubuntu-20.04
127127
permissions:
128128
contents: write
129129
steps:

0 commit comments

Comments
 (0)