-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from Tecnativa/conf-available-to-template
Tasks and migrations env utilities
- Loading branch information
Showing
13 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Changes here will be overwritten by Copier | ||
[[ _copier_answers|to_nice_yaml ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
_exclude: | ||
- tasks.sh | ||
- migrations.py | ||
- .git | ||
|
||
_tasks: | ||
- "[[ _copier_conf.src_path / 'tasks.sh' ]] 1" | ||
- ["[[ _copier_conf.src_path / 'tasks.sh' ]]", 2] | ||
|
||
_migrations: | ||
# This migration is never executed because it's the 1st version copied, and | ||
# migrations are only executed when updating | ||
- version: v1.0.0 | ||
before: | ||
- &mig | ||
- "[[ _copier_conf.src_path / 'migrations.py' ]]" | ||
- "[[ _copier_conf.json() ]]" | ||
after: | ||
- *mig | ||
- version: v2 | ||
before: [*mig] | ||
after: | ||
- *mig | ||
- "rm delete-in-migration-$VERSION_CURRENT.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file will be deleted after migrating to v2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file will be deleted in tasks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
import json | ||
import os | ||
import sys | ||
|
||
NAME = "{VERSION_FROM}-{VERSION_CURRENT}-{VERSION_TO}-{STAGE}.json" | ||
|
||
with open(NAME.format(**os.environ), "w") as fd: | ||
json.dump(sys.argv, fd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
echo $STAGE "$@" >> created-with-tasks.txt | ||
git init | ||
rm -f delete-in-tasks.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from glob import glob | ||
from pathlib import Path | ||
from shutil import copytree | ||
|
||
import py | ||
import yaml | ||
from plumbum import local | ||
from plumbum.cmd import git | ||
|
||
from copier import copy | ||
|
||
from .helpers import PROJECT_TEMPLATE | ||
|
||
SRC = Path(f"{PROJECT_TEMPLATE}_migrations").absolute() | ||
|
||
|
||
def test_migrations_and_tasks(tmpdir: py.path.local): | ||
"""Check migrations and tasks are run properly.""" | ||
# Convert demo_migrations in a git repository with 2 versions | ||
git_src, dst = tmpdir / "src", tmpdir / "dst" | ||
copytree(SRC, git_src) | ||
with local.cwd(git_src): | ||
git("init") | ||
git("config", "user.name", "Copier Test") | ||
git("config", "user.email", "test@copier") | ||
git("add", ".") | ||
git("commit", "-m1") | ||
git("tag", "v1.0.0") | ||
git("commit", "--allow-empty", "-m2") | ||
git("tag", "v2.0") | ||
# Copy it in v1 | ||
copy(src_path=str(git_src), dst_path=str(dst), vcs_ref="v1.0.0") | ||
# Check copy was OK | ||
assert (dst / "created-with-tasks.txt").read() == "task 1\ntask 2\n" | ||
assert not (dst / "delete-in-tasks.txt").exists() | ||
assert (dst / "delete-in-migration-v2.txt").isfile() | ||
assert not (dst / "migrations.py").exists() | ||
assert not (dst / "tasks.sh").exists() | ||
assert not glob(str(dst / "*-before.txt")) | ||
assert not glob(str(dst / "*-after.txt")) | ||
answers = yaml.safe_load((dst / ".copier-answers.yml").read()) | ||
assert answers == {"_commit": "v1.0.0", "_src_path": str(git_src)} | ||
# Save changes in downstream repo | ||
with local.cwd(dst): | ||
git("add", ".") | ||
git("config", "user.name", "Copier Test") | ||
git("config", "user.email", "test@copier") | ||
git("commit", "-m1") | ||
# Update it to v2 | ||
copy(dst_path=str(dst), force=True) | ||
# Check update was OK | ||
assert (dst / "created-with-tasks.txt").read() == "task 1\ntask 2\n" * 2 | ||
assert not (dst / "delete-in-tasks.txt").exists() | ||
assert not (dst / "delete-in-migration-v2.txt").exists() | ||
assert not (dst / "migrations.py").exists() | ||
assert not (dst / "tasks.sh").exists() | ||
assert (dst / "v1.0.0-v2-v2.0-before.json").isfile() | ||
assert (dst / "v1.0.0-v2-v2.0-after.json").isfile() | ||
answers = yaml.safe_load((dst / ".copier-answers.yml").read()) | ||
assert answers == {"_commit": "v2.0", "_src_path": str(git_src)} |