diff --git a/Taskfile.yml b/Taskfile.yml index 1322800..b5c5c1b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -29,15 +29,16 @@ tasks: - uv sync --frozen init-pre-commit: - desc: Install the pre-commit hooks + desc: Setup pre-commit internal: true sources: - .pre-commit-config.yaml status: - # Don't install the pre-commit hooks if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag + # Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag # https://yaml.org/spec/1.2.2/#691-node-tags - '! test -d .git' cmds: + - uv tool install pre-commit # Don't run this in pipelines - '{{if ne .GITHUB_ACTIONS "true"}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo "Detected a github actions pipeline; skipping the pre-commit install"{{end}}' @@ -88,6 +89,7 @@ tasks: cmds: # This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future - '{{if ne .GITHUB_ACTIONS "true"}}brew upgrade uv{{end}}' + - uv tool upgrade --all - pre-commit autoupdate --freeze --jobs 4 # Copy the newly updated config into the project template, excluding the exclude line - cat .pre-commit-config.yaml | grep -v ^exclude > '{{`{{cookiecutter.project_name|replace(" ", "")}}`}}/.pre-commit-config.yaml' diff --git a/tests/test_cookiecutter.py b/tests/test_cookiecutter.py index d5637fc..d7ddfa0 100755 --- a/tests/test_cookiecutter.py +++ b/tests/test_cookiecutter.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -Test cookiecutter-python +Test ai-native-python """ import copy @@ -109,7 +109,7 @@ def check_files(files): ) def test_supported_options(cookies, context_override): """ - Test all supported cookiecutter-python answer combinations + Test all supported answer combinations """ # Turn off the post generation hooks os.environ["RUN_POST_HOOK"] = "false" @@ -126,10 +126,47 @@ def test_supported_options(cookies, context_override): check_files(files) +@pytest.mark.integration +def test_update(cookies): + """ + Test task update + """ + # Turn on the post generation hooks but skip git push + os.environ["RUN_POST_HOOK"] = "true" + os.environ["SKIP_GIT_PUSH"] = "true" + + result = cookies.bake() + project = result.project_path + + try: + # First init the project just in case + # Clean environment to avoid VIRTUAL_ENV conflicts + env = os.environ.copy() + env.pop("VIRTUAL_ENV", None) + subprocess.run( + ["task", "init"], + capture_output=True, + check=True, + cwd=project, + env=env, + ) + + # And then run a task update + subprocess.run( + ["task", "update"], + capture_output=True, + check=True, + cwd=project, + env=env, + ) + except subprocess.CalledProcessError as error: + pytest.fail(f"stdout: {error.stdout.decode('utf-8')}, stderr: {error.stderr.decode('utf-8')}") + + @pytest.mark.integration def test_autofix_hook(cookies, context): """ - Test the post-generation pre-commit autofix hook of cookiecutter-python + Test the post-generation pre-commit autofix hook """ # Turn on the post generation hooks but skip git push os.environ["RUN_POST_HOOK"] = "true" @@ -177,7 +214,7 @@ def test_autofix_hook(cookies, context): @pytest.mark.integration def test_default_project(cookies): """ - Test a default cookiecutter-python project thoroughly + Test a default project thoroughly """ # Turn on the post generation hooks but skip git push os.environ["RUN_POST_HOOK"] = "true" diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" index 623a704..b0ebfde 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" @@ -49,3 +49,5 @@ Both tools are pre-configured and will start working once the repository is push ## FAQs For frequently asked questions including release workflow troubleshooting, see our [FAQ documentation](./FAQ.md). + +_This project was generated with 🤟 by [Zenable](https://zenable.io)_ diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" index ba60abb..6da9061 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" @@ -47,10 +47,11 @@ tasks: sources: - .pre-commit-config.yaml status: - # Only install the pre-commit hooks if you are in a git repository; quote to avoid yaml intrepretering the ! as a node tag + # Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag # https://yaml.org/spec/1.2.2/#691-node-tags - '! test -d .git' cmds: + - uv tool install pre-commit # Don't run this in pipelines - '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo \"Detected a github actions pipeline; skipping the pre-commit install\"{{end}}" }}' @@ -169,10 +170,11 @@ tasks: cmds: # This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future - '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}" }}brew upgrade uv{{ "{{" }}end{{ "}}" }}' + - uv tool upgrade --all - pre-commit autoupdate --freeze --jobs 4 - uv lock --upgrade # This can take a while but it's required for the following step to update BuildKit in the docker driver - - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "}}" }}end {{ "}}" }}' + - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "{{" }}end{{ "}}" }}' # If we just destroyed the "multiplatform" builder instance, this will configure a new one. The next time the host runs a `docker buildx build` it will # rebuild the builder instance, updating its BuildKit. There's no harm in running this even if we didn't do the `docker buildx rm` previously - task: init-docker-multiplatform