From e00f809ca1ca5c063b0edebf482a86a7581d2539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Tue, 3 Mar 2026 13:53:54 +0200 Subject: [PATCH 01/22] refactor(template): emit nested copier template payload --- .../workflows/template-correctness.yaml | 45 ---- template/template/README.md | 46 ++++ template/template/scripts/init-dev.sh | 22 ++ template/template/tasks.py | 218 ++++++++++++++++++ 4 files changed, 286 insertions(+), 45 deletions(-) delete mode 100644 template/.github/workflows/template-correctness.yaml create mode 100644 template/template/README.md create mode 100755 template/template/scripts/init-dev.sh create mode 100644 template/template/tasks.py diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml deleted file mode 100644 index f4aa1eb..0000000 --- a/template/.github/workflows/template-correctness.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: Template Correctness - -on: - push: - branches: [main] - pull_request: - -jobs: - render-template: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - - name: Install copier - run: pip install copier - - - name: Render sample project - run: | - copier copy . /tmp/sample-project --trust --defaults \ - -d copier__project_name_raw="Sample Project" \ - -d copier__project_slug="sample_project" \ - -d copier__description="Sample generated project" \ - -d copier__author_name="Sample Author" \ - -d copier__email="sample@example.com" \ - -d copier__version="0.1.0" \ - -d copier__configure_repo=false \ - -d copier__ci_provider="github" \ - -d copier__enable_semantic_release=false \ - -d copier__enable_secret_scanning=false \ - -d copier__task_runner="task" - - - name: Validate generated project files - run: | - test -f /tmp/sample-project/README.md - test -f /tmp/sample-project/.copier-answers.yml - test -f /tmp/sample-project/Taskfile.yml - test ! -f /tmp/sample-project/Makefile - test ! -f /tmp/sample-project/justfile diff --git a/template/template/README.md b/template/template/README.md new file mode 100644 index 0000000..c4bf84d --- /dev/null +++ b/template/template/README.md @@ -0,0 +1,46 @@ +{% raw %}# {{ copier__project_name }} + +{{ copier__description }} + +## What This Includes + +- Copier-based scaf template structure +- {{ copier__ci_provider | upper }} CI scaffolding +- Optional semantic-release automation +- Optional secret scanning +- Local init tasks for `make`, `task`, and `just` (primary: `{{ copier__task_runner }}`) +- Usage and upgrade docs + +## Quick Start + +1. Initialize your local development tools: + +```bash +{% if copier__task_runner == "make" %} +make init +{% elif copier__task_runner == "just" %} +just init +{% else %} +task init +{% endif %} +``` + +2. Run a quick local sanity check: + +```bash +{% if copier__task_runner == "make" %} +make check +{% elif copier__task_runner == "just" %} +just check +{% else %} +task check +{% endif %} +``` + +## Docs + +- [Using This Template](docs/using-template.md) +- [Upgrading Projects](docs/upgrading.md) +{% if copier__ci_provider == "github" and copier__enable_semantic_release %}- [GitHub Semantic Release Setup](docs/semantic-release-github.md) +{% endif %} +{% endraw %} diff --git a/template/template/scripts/init-dev.sh b/template/template/scripts/init-dev.sh new file mode 100755 index 0000000..2a8aaa0 --- /dev/null +++ b/template/template/scripts/init-dev.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +if command -v pre-commit >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + pre-commit install || echo "pre-commit install failed; continuing" +fi + +{% if copier__enable_semantic_release %} +if command -v npm >/dev/null 2>&1; then + xargs npm install < dependencies-init.txt + xargs npm install --save-dev < dependencies-dev-init.txt +elif command -v docker >/dev/null 2>&1; then + docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ + "xargs npm install < dependencies-init.txt" + docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ + "xargs npm install --save-dev < dependencies-dev-init.txt" +else + echo "docker and npm not found; skipping semantic-release dependency install" +fi +{% endif %} + +echo "Local development setup complete." diff --git a/template/template/tasks.py b/template/template/tasks.py new file mode 100644 index 0000000..137926d --- /dev/null +++ b/template/template/tasks.py @@ -0,0 +1,218 @@ +import os +import pathlib +import shlex +import shutil +import subprocess + +CI_PROVIDER = "{{ copier__ci_provider }}" +SEMANTIC_RELEASE = {{ "True" if copier__enable_semantic_release else "False" }} +SECRET_SCANNING = {{ "True" if copier__enable_secret_scanning else "False" }} +TASK_RUNNER = "{{ copier__task_runner }}" +CONFIGURE_REPO = {{ "True" if copier__configure_repo else "False" }} +REPO_PROVIDER = "{{ copier__repo_provider }}" +REPO_ORG = "{{ copier__repo_org }}" +REPO_NAME = "{{ copier__repo_name }}" +REPO_URL = "{{ copier__repo_url }}" +CREATE_REPO = {{ "True" if copier__create_repo else "False" }} +REPO_VISIBILITY = "{{ copier__repo_visibility }}" + +ROOT = pathlib.Path(".") +TERMINATOR = "\x1b[0m" +WARNING = "\x1b[1;33m [WARNING]: " +INFO = "\x1b[1;33m [INFO]: " +SUCCESS = "\x1b[1;32m [SUCCESS]: " + + +def remove(path: str) -> None: + p = ROOT / path + if p.exists(): + if p.is_file() or p.is_symlink(): + p.unlink() + else: + for child in sorted(p.rglob("*"), reverse=True): + if child.is_file() or child.is_symlink(): + child.unlink() + elif child.is_dir(): + child.rmdir() + p.rmdir() + + +def run(cmd: list[str]) -> None: + subprocess.run(cmd, check=True) + + +def run_init_script() -> None: + run(["bash", "./scripts/init-dev.sh"]) + + +def init_git_repo() -> None: + if (ROOT / ".git").exists(): + return + print(INFO + "Initializing git repository..." + TERMINATOR) + print(INFO + f"Current working directory: {os.getcwd()}" + TERMINATOR) + subprocess.run( + shlex.split("git -c init.defaultBranch=main init . --quiet"), check=True + ) + print(SUCCESS + "Git repository initialized." + TERMINATOR) + + +def configure_git_remote() -> None: + if not CONFIGURE_REPO: + return + repo_url = REPO_URL.strip() + if repo_url: + print(INFO + f"repo_url: {repo_url}" + TERMINATOR) + existing_origin = subprocess.run( + shlex.split("git remote get-url origin"), + capture_output=True, + text=True, + ) + if existing_origin.returncode == 0: + current_origin = existing_origin.stdout.strip() + print( + INFO + + f"Remote origin already configured ({current_origin}). Skipping add." + + TERMINATOR + ) + return + command = f"git remote add origin {repo_url}" + subprocess.run(shlex.split(command), check=True) + print(SUCCESS + f"Remote origin={repo_url} added." + TERMINATOR) + else: + print( + WARNING + + "No repo_url provided. Skipping git remote configuration." + + TERMINATOR + ) + + +def maybe_create_repo() -> None: + if not CREATE_REPO: + return + + if not CONFIGURE_REPO: + return + if not REPO_ORG.strip() or not REPO_NAME.strip(): + print(WARNING + "Repo org/name not set. Skipping repo creation." + TERMINATOR) + return + repo_name = f"{REPO_ORG.strip()}/{REPO_NAME.strip()}" + + if REPO_PROVIDER == "github": + if not shutil.which("gh"): + print(WARNING + "gh CLI is not installed. Skipping repo creation." + TERMINATOR) + return + + gh_env = os.environ.copy() + gh_env["GH_HOST"] = "github.com" + + repo_exists = subprocess.run( + ["gh", "repo", "view", repo_name], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + env=gh_env, + ) + if repo_exists.returncode == 0: + print(INFO + f"GitHub repository {repo_name} already exists." + TERMINATOR) + return + + print( + INFO + + f"Creating GitHub repository {repo_name} ({REPO_VISIBILITY})..." + + TERMINATOR + ) + create_repo = subprocess.run( + ["gh", "repo", "create", repo_name, f"--{REPO_VISIBILITY}"], + capture_output=True, + text=True, + env=gh_env, + ) + if create_repo.returncode != 0: + error = create_repo.stderr.strip() or create_repo.stdout.strip() or "unknown error" + print( + WARNING + + f"Failed to create GitHub repository {repo_name}: {error}" + + TERMINATOR + ) + return + print(SUCCESS + f"GitHub repository {repo_name} created." + TERMINATOR) + return + + if REPO_PROVIDER == "gitlab": + if not shutil.which("glab"): + print(WARNING + "glab CLI is not installed. Skipping repo creation." + TERMINATOR) + return + + glab_env = os.environ.copy() + glab_env["GITLAB_HOST"] = "gitlab.com" + repo_exists = subprocess.run( + ["glab", "repo", "view", repo_name], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + env=glab_env, + ) + if repo_exists.returncode == 0: + print(INFO + f"GitLab repository {repo_name} already exists." + TERMINATOR) + return + + print( + INFO + + f"Creating GitLab repository {repo_name} ({REPO_VISIBILITY})..." + + TERMINATOR + ) + create_repo = subprocess.run( + ["glab", "repo", "create", repo_name, f"--{REPO_VISIBILITY}"], + capture_output=True, + text=True, + env=glab_env, + ) + if create_repo.returncode != 0: + error = create_repo.stderr.strip() or create_repo.stdout.strip() or "unknown error" + print( + WARNING + + f"Failed to create GitLab repository {repo_name}: {error}" + + TERMINATOR + ) + return + print(SUCCESS + f"GitLab repository {repo_name} created." + TERMINATOR) + return + + print( + WARNING + + f"Repo creation not implemented for provider '{REPO_PROVIDER}'. Skipping." + + TERMINATOR + ) + + +def main() -> None: + init_git_repo() + maybe_create_repo() + configure_git_remote() + run_init_script() + + if TASK_RUNNER != "make": + remove("Makefile") + if TASK_RUNNER != "task": + remove("Taskfile.yml") + if TASK_RUNNER != "just": + remove("justfile") + + if CI_PROVIDER != "github": + remove(".github") + if CI_PROVIDER != "gitlab": + remove(".gitlab-ci.yml") + + if not SEMANTIC_RELEASE: + remove("package.json") + remove("dependencies-init.txt") + remove("dependencies-dev-init.txt") + remove(".releaserc.json") + remove("CHANGELOG.md") + remove(".github/workflows/semantic-release.yaml") + remove(".github/workflows/semantic-pull-request.yaml") + + if not SECRET_SCANNING: + remove(".github/workflows/secret-scan.yaml") + + +if __name__ == "__main__": + main() From 09f8b7dd4ee7e5461269d6107c4ae59bfb4e7f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Fri, 6 Mar 2026 19:26:36 +0200 Subject: [PATCH 02/22] fix(template): add root guide/workflow and preserve README rendering --- .../workflows/template-correctness.yaml | 45 ++++++++++++++++++ template/template/README.md | 46 ------------------- 2 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 template/.github/workflows/template-correctness.yaml delete mode 100644 template/template/README.md diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml new file mode 100644 index 0000000..f4aa1eb --- /dev/null +++ b/template/.github/workflows/template-correctness.yaml @@ -0,0 +1,45 @@ +name: Template Correctness + +on: + push: + branches: [main] + pull_request: + +jobs: + render-template: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install copier + run: pip install copier + + - name: Render sample project + run: | + copier copy . /tmp/sample-project --trust --defaults \ + -d copier__project_name_raw="Sample Project" \ + -d copier__project_slug="sample_project" \ + -d copier__description="Sample generated project" \ + -d copier__author_name="Sample Author" \ + -d copier__email="sample@example.com" \ + -d copier__version="0.1.0" \ + -d copier__configure_repo=false \ + -d copier__ci_provider="github" \ + -d copier__enable_semantic_release=false \ + -d copier__enable_secret_scanning=false \ + -d copier__task_runner="task" + + - name: Validate generated project files + run: | + test -f /tmp/sample-project/README.md + test -f /tmp/sample-project/.copier-answers.yml + test -f /tmp/sample-project/Taskfile.yml + test ! -f /tmp/sample-project/Makefile + test ! -f /tmp/sample-project/justfile diff --git a/template/template/README.md b/template/template/README.md deleted file mode 100644 index c4bf84d..0000000 --- a/template/template/README.md +++ /dev/null @@ -1,46 +0,0 @@ -{% raw %}# {{ copier__project_name }} - -{{ copier__description }} - -## What This Includes - -- Copier-based scaf template structure -- {{ copier__ci_provider | upper }} CI scaffolding -- Optional semantic-release automation -- Optional secret scanning -- Local init tasks for `make`, `task`, and `just` (primary: `{{ copier__task_runner }}`) -- Usage and upgrade docs - -## Quick Start - -1. Initialize your local development tools: - -```bash -{% if copier__task_runner == "make" %} -make init -{% elif copier__task_runner == "just" %} -just init -{% else %} -task init -{% endif %} -``` - -2. Run a quick local sanity check: - -```bash -{% if copier__task_runner == "make" %} -make check -{% elif copier__task_runner == "just" %} -just check -{% else %} -task check -{% endif %} -``` - -## Docs - -- [Using This Template](docs/using-template.md) -- [Upgrading Projects](docs/upgrading.md) -{% if copier__ci_provider == "github" and copier__enable_semantic_release %}- [GitHub Semantic Release Setup](docs/semantic-release-github.md) -{% endif %} -{% endraw %} From 276ccee360191554e84e285c11bd268977964b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sat, 7 Mar 2026 14:10:25 +0200 Subject: [PATCH 03/22] fix(template): run first-stage tasks for generated template repo --- template/template/scripts/init-dev.sh | 22 ------------------- .../template/{tasks.py => tasks.py.jinja} | 22 +++++++++++-------- 2 files changed, 13 insertions(+), 31 deletions(-) delete mode 100755 template/template/scripts/init-dev.sh rename template/template/{tasks.py => tasks.py.jinja} (91%) diff --git a/template/template/scripts/init-dev.sh b/template/template/scripts/init-dev.sh deleted file mode 100755 index 2a8aaa0..0000000 --- a/template/template/scripts/init-dev.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -if command -v pre-commit >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then - pre-commit install || echo "pre-commit install failed; continuing" -fi - -{% if copier__enable_semantic_release %} -if command -v npm >/dev/null 2>&1; then - xargs npm install < dependencies-init.txt - xargs npm install --save-dev < dependencies-dev-init.txt -elif command -v docker >/dev/null 2>&1; then - docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ - "xargs npm install < dependencies-init.txt" - docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ - "xargs npm install --save-dev < dependencies-dev-init.txt" -else - echo "docker and npm not found; skipping semantic-release dependency install" -fi -{% endif %} - -echo "Local development setup complete." diff --git a/template/template/tasks.py b/template/template/tasks.py.jinja similarity index 91% rename from template/template/tasks.py rename to template/template/tasks.py.jinja index 137926d..f09230e 100644 --- a/template/template/tasks.py +++ b/template/template/tasks.py.jinja @@ -16,7 +16,8 @@ CREATE_REPO = {{ "True" if copier__create_repo else "False" }} REPO_VISIBILITY = "{{ copier__repo_visibility }}" -ROOT = pathlib.Path(".") +PROJECT_ROOT = pathlib.Path.cwd() +TEMPLATE_ROOT = pathlib.Path(__file__).resolve().parent TERMINATOR = "\x1b[0m" WARNING = "\x1b[1;33m [WARNING]: " INFO = "\x1b[1;33m [INFO]: " @@ -24,7 +25,7 @@ def remove(path: str) -> None: - p = ROOT / path + p = TEMPLATE_ROOT / path if p.exists(): if p.is_file() or p.is_symlink(): p.unlink() @@ -37,21 +38,23 @@ def remove(path: str) -> None: p.rmdir() -def run(cmd: list[str]) -> None: - subprocess.run(cmd, check=True) +def run(cmd: list[str], *, cwd: pathlib.Path | None = None) -> None: + subprocess.run(cmd, check=True, cwd=cwd) def run_init_script() -> None: - run(["bash", "./scripts/init-dev.sh"]) + run(["bash", "./scripts/init-dev.sh"], cwd=TEMPLATE_ROOT) def init_git_repo() -> None: - if (ROOT / ".git").exists(): + if (PROJECT_ROOT / ".git").exists(): return print(INFO + "Initializing git repository..." + TERMINATOR) - print(INFO + f"Current working directory: {os.getcwd()}" + TERMINATOR) + print(INFO + f"Current working directory: {PROJECT_ROOT}" + TERMINATOR) subprocess.run( - shlex.split("git -c init.defaultBranch=main init . --quiet"), check=True + shlex.split("git -c init.defaultBranch=main init . --quiet"), + check=True, + cwd=PROJECT_ROOT, ) print(SUCCESS + "Git repository initialized." + TERMINATOR) @@ -66,6 +69,7 @@ def configure_git_remote() -> None: shlex.split("git remote get-url origin"), capture_output=True, text=True, + cwd=PROJECT_ROOT, ) if existing_origin.returncode == 0: current_origin = existing_origin.stdout.strip() @@ -76,7 +80,7 @@ def configure_git_remote() -> None: ) return command = f"git remote add origin {repo_url}" - subprocess.run(shlex.split(command), check=True) + subprocess.run(shlex.split(command), check=True, cwd=PROJECT_ROOT) print(SUCCESS + f"Remote origin={repo_url} added." + TERMINATOR) else: print( From 037f8f195b3212b286f18daaa7ad2930bffd5474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sat, 7 Mar 2026 14:54:41 +0200 Subject: [PATCH 04/22] fix(tasks): skip starter-stage npm init in nested template --- template/template/tasks.py.jinja | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/template/template/tasks.py.jinja b/template/template/tasks.py.jinja index f09230e..9566481 100644 --- a/template/template/tasks.py.jinja +++ b/template/template/tasks.py.jinja @@ -38,12 +38,17 @@ def remove(path: str) -> None: p.rmdir() -def run(cmd: list[str], *, cwd: pathlib.Path | None = None) -> None: - subprocess.run(cmd, check=True, cwd=cwd) +def run( + cmd: list[str], *, cwd: pathlib.Path | None = None, env: dict[str, str] | None = None +) -> None: + subprocess.run(cmd, check=True, cwd=cwd, env=env) def run_init_script() -> None: - run(["bash", "./scripts/init-dev.sh"], cwd=TEMPLATE_ROOT) + env = os.environ.copy() + if env.get("SCAF_TEMPLATE_STARTER_STAGE") == "1": + env["SCAF_SKIP_INIT_DEV_NPM"] = "1" + run(["bash", "./scripts/init-dev.sh"], cwd=TEMPLATE_ROOT, env=env) def init_git_repo() -> None: From 278de7babe146f9639bdd607d823f0c6f6662408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sat, 7 Mar 2026 15:21:53 +0200 Subject: [PATCH 05/22] refactor(tasks): split starter and template post-copy scripts --- template/.scaf/starter-post-copy.sh.jinja | 211 +++++++++++++++++++ template/template/.scaf/post-copy.sh.jinja | 163 +++++++++++++++ template/template/tasks.py.jinja | 227 --------------------- 3 files changed, 374 insertions(+), 227 deletions(-) create mode 100644 template/.scaf/starter-post-copy.sh.jinja create mode 100644 template/template/.scaf/post-copy.sh.jinja delete mode 100644 template/template/tasks.py.jinja diff --git a/template/.scaf/starter-post-copy.sh.jinja b/template/.scaf/starter-post-copy.sh.jinja new file mode 100644 index 0000000..68a91ea --- /dev/null +++ b/template/.scaf/starter-post-copy.sh.jinja @@ -0,0 +1,211 @@ +#!/usr/bin/env bash +set -euo pipefail + +CI_PROVIDER="{{ copier__ci_provider }}" +SEMANTIC_RELEASE="{{ 'true' if copier__enable_semantic_release else 'false' }}" +SECRET_SCANNING="{{ 'true' if copier__enable_secret_scanning else 'false' }}" +TASK_RUNNER="{{ copier__task_runner }}" +CONFIGURE_REPO="{{ 'true' if copier__configure_repo else 'false' }}" +REPO_PROVIDER="{{ copier__repo_provider }}" +REPO_ORG="{{ copier__repo_org }}" +REPO_NAME="{{ copier__repo_name }}" +REPO_URL="{{ copier__repo_url }}" +CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" +REPO_VISIBILITY="{{ copier__repo_visibility }}" + +TERMINATOR="\033[0m" +WARNING="\033[1;33m [WARNING]: " +INFO="\033[1;33m [INFO]: " +SUCCESS="\033[1;32m [SUCCESS]: " + +is_true() { + [[ "${1:-false}" == "true" ]] +} + +log_info() { + printf "%b%s%b\n" "$INFO" "$1" "$TERMINATOR" +} + +log_warning() { + printf "%b%s%b\n" "$WARNING" "$1" "$TERMINATOR" +} + +log_success() { + printf "%b%s%b\n" "$SUCCESS" "$1" "$TERMINATOR" +} + +remove_path() { + local path="$1" + [[ -e "$path" ]] || return 0 + rm -rf "$path" +} + +install_semantic_release_deps() { + local init_file="$1" + local dev_file="$2" + + if command -v npm >/dev/null 2>&1; then + [[ -s "$init_file" ]] && xargs npm install < "$init_file" + [[ -s "$dev_file" ]] && xargs npm install --save-dev < "$dev_file" + return + fi + + if command -v docker >/dev/null 2>&1; then + docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ + "if [ -s \"$init_file\" ]; then xargs npm install < \"$init_file\"; fi; if [ -s \"$dev_file\" ]; then xargs npm install --save-dev < \"$dev_file\"; fi" + return + fi + + log_warning "docker and npm not found; skipping semantic-release dependency install" +} + +run_template_init() { + ( + cd template + + if command -v pre-commit >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + pre-commit install || echo "pre-commit install failed; continuing" + fi + + if is_true "$SEMANTIC_RELEASE"; then + local tmp_init_file tmp_dev_file tmp_dev_filtered + tmp_init_file="$(mktemp ./.scaf-deps-init.XXXXXX)" + tmp_dev_file="$(mktemp ./.scaf-deps-dev.XXXXXX)" + tmp_dev_filtered="${tmp_dev_file}.filtered" + + sed -E '/[{][{]/d; /[{][%]/d; /^[[:space:]]*$/d' dependencies-init.txt > "$tmp_init_file" + sed -E '/[{][{]/d; /[{][%]/d; /^[[:space:]]*$/d' dependencies-dev-init.txt > "$tmp_dev_file" + + if [[ "$CI_PROVIDER" == "github" ]]; then + awk '!/@semantic-release\/gitlab/' "$tmp_dev_file" > "$tmp_dev_filtered" + mv "$tmp_dev_filtered" "$tmp_dev_file" + elif [[ "$CI_PROVIDER" == "gitlab" ]]; then + awk '!/@semantic-release\/github/' "$tmp_dev_file" > "$tmp_dev_filtered" + mv "$tmp_dev_filtered" "$tmp_dev_file" + fi + + install_semantic_release_deps "$tmp_init_file" "$tmp_dev_file" + rm -f "$tmp_init_file" "$tmp_dev_file" "$tmp_dev_filtered" + fi + + echo "Local development setup complete." + ) +} + +init_git_repo() { + if [[ -d .git ]]; then + return + fi + log_info "Initializing git repository..." + log_info "Current working directory: $(pwd)" + git -c init.defaultBranch=main init . --quiet + log_success "Git repository initialized." +} + +configure_git_remote() { + if ! is_true "$CONFIGURE_REPO"; then + return + fi + + local repo_url + repo_url="$(printf "%s" "$REPO_URL" | xargs)" + if [[ -z "$repo_url" ]]; then + log_warning "No repo_url provided. Skipping git remote configuration." + return + fi + + log_info "repo_url: $repo_url" + if git remote get-url origin >/dev/null 2>&1; then + local current_origin + current_origin="$(git remote get-url origin)" + log_info "Remote origin already configured (${current_origin}). Skipping add." + return + fi + + git remote add origin "$repo_url" + log_success "Remote origin=${repo_url} added." +} + +maybe_create_repo() { + if ! is_true "$CREATE_REPO" || ! is_true "$CONFIGURE_REPO"; then + return + fi + + if [[ -z "${REPO_ORG// }" || -z "${REPO_NAME// }" ]]; then + log_warning "Repo org/name not set. Skipping repo creation." + return + fi + + local repo_full_name="${REPO_ORG}/${REPO_NAME}" + + if [[ "$REPO_PROVIDER" == "github" ]]; then + if ! command -v gh >/dev/null 2>&1; then + log_warning "gh CLI is not installed. Skipping repo creation." + return + fi + if GH_HOST=github.com gh repo view "$repo_full_name" >/dev/null 2>&1; then + log_info "GitHub repository ${repo_full_name} already exists." + return + fi + log_info "Creating GitHub repository ${repo_full_name} (${REPO_VISIBILITY})..." + if ! create_error="$(GH_HOST=github.com gh repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then + log_warning "Failed to create GitHub repository ${repo_full_name}: ${create_error}" + return + fi + log_success "GitHub repository ${repo_full_name} created." + return + fi + + if [[ "$REPO_PROVIDER" == "gitlab" ]]; then + if ! command -v glab >/dev/null 2>&1; then + log_warning "glab CLI is not installed. Skipping repo creation." + return + fi + if GITLAB_HOST=gitlab.com glab repo view "$repo_full_name" >/dev/null 2>&1; then + log_info "GitLab repository ${repo_full_name} already exists." + return + fi + log_info "Creating GitLab repository ${repo_full_name} (${REPO_VISIBILITY})..." + if ! create_error="$(GITLAB_HOST=gitlab.com glab repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then + log_warning "Failed to create GitLab repository ${repo_full_name}: ${create_error}" + return + fi + log_success "GitLab repository ${repo_full_name} created." + return + fi + + log_warning "Repo creation not implemented for provider '${REPO_PROVIDER}'. Skipping." +} + +main() { + init_git_repo + maybe_create_repo + configure_git_remote + run_template_init + + if [[ "$TASK_RUNNER" != "make" ]]; then remove_path "template/Makefile"; fi + if [[ "$TASK_RUNNER" != "task" ]]; then remove_path "template/Taskfile.yml"; fi + if [[ "$TASK_RUNNER" != "just" ]]; then remove_path "template/justfile"; fi + + if [[ "$CI_PROVIDER" != "github" ]]; then remove_path "template/.github"; fi + if [[ "$CI_PROVIDER" != "gitlab" ]]; then remove_path "template/.gitlab-ci.yml"; fi + + if ! is_true "$SEMANTIC_RELEASE"; then + remove_path "template/package.json" + remove_path "template/dependencies-init.txt" + remove_path "template/dependencies-dev-init.txt" + remove_path "template/.releaserc.json" + remove_path "template/CHANGELOG.md" + remove_path "template/.github/workflows/semantic-release.yaml" + remove_path "template/.github/workflows/semantic-pull-request.yaml" + fi + + if ! is_true "$SECRET_SCANNING"; then + remove_path "template/.github/workflows/secret-scan.yaml" + fi + + remove_path ".scaf/starter-post-copy.sh" + rmdir ".scaf" 2>/dev/null || true +} + +main "$@" diff --git a/template/template/.scaf/post-copy.sh.jinja b/template/template/.scaf/post-copy.sh.jinja new file mode 100644 index 0000000..d085c2b --- /dev/null +++ b/template/template/.scaf/post-copy.sh.jinja @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +set -euo pipefail + +CI_PROVIDER="{{ copier__ci_provider }}" +SEMANTIC_RELEASE="{{ 'true' if copier__enable_semantic_release else 'false' }}" +SECRET_SCANNING="{{ 'true' if copier__enable_secret_scanning else 'false' }}" +TASK_RUNNER="{{ copier__task_runner }}" +CONFIGURE_REPO="{{ 'true' if copier__configure_repo else 'false' }}" +REPO_PROVIDER="{{ copier__repo_provider }}" +REPO_ORG="{{ copier__repo_org }}" +REPO_NAME="{{ copier__repo_name }}" +REPO_URL="{{ copier__repo_url }}" +CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" +REPO_VISIBILITY="{{ copier__repo_visibility }}" + +TERMINATOR="\033[0m" +WARNING="\033[1;33m [WARNING]: " +INFO="\033[1;33m [INFO]: " +SUCCESS="\033[1;32m [SUCCESS]: " + +is_true() { + [[ "${1:-false}" == "true" ]] +} + +log_info() { + printf "%b%s%b\n" "$INFO" "$1" "$TERMINATOR" +} + +log_warning() { + printf "%b%s%b\n" "$WARNING" "$1" "$TERMINATOR" +} + +log_success() { + printf "%b%s%b\n" "$SUCCESS" "$1" "$TERMINATOR" +} + +remove_path() { + local path="$1" + [[ -e "$path" ]] || return 0 + rm -rf "$path" +} + +run_init_script() { + bash ./scripts/init-dev.sh +} + +init_git_repo() { + if [[ -d .git ]]; then + return + fi + log_info "Initializing git repository..." + log_info "Current working directory: $(pwd)" + git -c init.defaultBranch=main init . --quiet + log_success "Git repository initialized." +} + +configure_git_remote() { + if ! is_true "$CONFIGURE_REPO"; then + return + fi + + local repo_url + repo_url="$(printf "%s" "$REPO_URL" | xargs)" + if [[ -z "$repo_url" ]]; then + log_warning "No repo_url provided. Skipping git remote configuration." + return + fi + + log_info "repo_url: $repo_url" + if git remote get-url origin >/dev/null 2>&1; then + local current_origin + current_origin="$(git remote get-url origin)" + log_info "Remote origin already configured (${current_origin}). Skipping add." + return + fi + + git remote add origin "$repo_url" + log_success "Remote origin=${repo_url} added." +} + +maybe_create_repo() { + if ! is_true "$CREATE_REPO" || ! is_true "$CONFIGURE_REPO"; then + return + fi + + if [[ -z "${REPO_ORG// }" || -z "${REPO_NAME// }" ]]; then + log_warning "Repo org/name not set. Skipping repo creation." + return + fi + + local repo_full_name="${REPO_ORG}/${REPO_NAME}" + + if [[ "$REPO_PROVIDER" == "github" ]]; then + if ! command -v gh >/dev/null 2>&1; then + log_warning "gh CLI is not installed. Skipping repo creation." + return + fi + if GH_HOST=github.com gh repo view "$repo_full_name" >/dev/null 2>&1; then + log_info "GitHub repository ${repo_full_name} already exists." + return + fi + log_info "Creating GitHub repository ${repo_full_name} (${REPO_VISIBILITY})..." + if ! create_error="$(GH_HOST=github.com gh repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then + log_warning "Failed to create GitHub repository ${repo_full_name}: ${create_error}" + return + fi + log_success "GitHub repository ${repo_full_name} created." + return + fi + + if [[ "$REPO_PROVIDER" == "gitlab" ]]; then + if ! command -v glab >/dev/null 2>&1; then + log_warning "glab CLI is not installed. Skipping repo creation." + return + fi + if GITLAB_HOST=gitlab.com glab repo view "$repo_full_name" >/dev/null 2>&1; then + log_info "GitLab repository ${repo_full_name} already exists." + return + fi + log_info "Creating GitLab repository ${repo_full_name} (${REPO_VISIBILITY})..." + if ! create_error="$(GITLAB_HOST=gitlab.com glab repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then + log_warning "Failed to create GitLab repository ${repo_full_name}: ${create_error}" + return + fi + log_success "GitLab repository ${repo_full_name} created." + return + fi + + log_warning "Repo creation not implemented for provider '${REPO_PROVIDER}'. Skipping." +} + +main() { + init_git_repo + maybe_create_repo + configure_git_remote + run_init_script + + if [[ "$TASK_RUNNER" != "make" ]]; then remove_path "Makefile"; fi + if [[ "$TASK_RUNNER" != "task" ]]; then remove_path "Taskfile.yml"; fi + if [[ "$TASK_RUNNER" != "just" ]]; then remove_path "justfile"; fi + + if [[ "$CI_PROVIDER" != "github" ]]; then remove_path ".github"; fi + if [[ "$CI_PROVIDER" != "gitlab" ]]; then remove_path ".gitlab-ci.yml"; fi + + if ! is_true "$SEMANTIC_RELEASE"; then + remove_path "package.json" + remove_path "dependencies-init.txt" + remove_path "dependencies-dev-init.txt" + remove_path ".releaserc.json" + remove_path "CHANGELOG.md" + remove_path ".github/workflows/semantic-release.yaml" + remove_path ".github/workflows/semantic-pull-request.yaml" + fi + + if ! is_true "$SECRET_SCANNING"; then + remove_path ".github/workflows/secret-scan.yaml" + fi + + remove_path ".scaf/post-copy.sh" + rmdir ".scaf" 2>/dev/null || true +} + +main "$@" diff --git a/template/template/tasks.py.jinja b/template/template/tasks.py.jinja deleted file mode 100644 index 9566481..0000000 --- a/template/template/tasks.py.jinja +++ /dev/null @@ -1,227 +0,0 @@ -import os -import pathlib -import shlex -import shutil -import subprocess - -CI_PROVIDER = "{{ copier__ci_provider }}" -SEMANTIC_RELEASE = {{ "True" if copier__enable_semantic_release else "False" }} -SECRET_SCANNING = {{ "True" if copier__enable_secret_scanning else "False" }} -TASK_RUNNER = "{{ copier__task_runner }}" -CONFIGURE_REPO = {{ "True" if copier__configure_repo else "False" }} -REPO_PROVIDER = "{{ copier__repo_provider }}" -REPO_ORG = "{{ copier__repo_org }}" -REPO_NAME = "{{ copier__repo_name }}" -REPO_URL = "{{ copier__repo_url }}" -CREATE_REPO = {{ "True" if copier__create_repo else "False" }} -REPO_VISIBILITY = "{{ copier__repo_visibility }}" - -PROJECT_ROOT = pathlib.Path.cwd() -TEMPLATE_ROOT = pathlib.Path(__file__).resolve().parent -TERMINATOR = "\x1b[0m" -WARNING = "\x1b[1;33m [WARNING]: " -INFO = "\x1b[1;33m [INFO]: " -SUCCESS = "\x1b[1;32m [SUCCESS]: " - - -def remove(path: str) -> None: - p = TEMPLATE_ROOT / path - if p.exists(): - if p.is_file() or p.is_symlink(): - p.unlink() - else: - for child in sorted(p.rglob("*"), reverse=True): - if child.is_file() or child.is_symlink(): - child.unlink() - elif child.is_dir(): - child.rmdir() - p.rmdir() - - -def run( - cmd: list[str], *, cwd: pathlib.Path | None = None, env: dict[str, str] | None = None -) -> None: - subprocess.run(cmd, check=True, cwd=cwd, env=env) - - -def run_init_script() -> None: - env = os.environ.copy() - if env.get("SCAF_TEMPLATE_STARTER_STAGE") == "1": - env["SCAF_SKIP_INIT_DEV_NPM"] = "1" - run(["bash", "./scripts/init-dev.sh"], cwd=TEMPLATE_ROOT, env=env) - - -def init_git_repo() -> None: - if (PROJECT_ROOT / ".git").exists(): - return - print(INFO + "Initializing git repository..." + TERMINATOR) - print(INFO + f"Current working directory: {PROJECT_ROOT}" + TERMINATOR) - subprocess.run( - shlex.split("git -c init.defaultBranch=main init . --quiet"), - check=True, - cwd=PROJECT_ROOT, - ) - print(SUCCESS + "Git repository initialized." + TERMINATOR) - - -def configure_git_remote() -> None: - if not CONFIGURE_REPO: - return - repo_url = REPO_URL.strip() - if repo_url: - print(INFO + f"repo_url: {repo_url}" + TERMINATOR) - existing_origin = subprocess.run( - shlex.split("git remote get-url origin"), - capture_output=True, - text=True, - cwd=PROJECT_ROOT, - ) - if existing_origin.returncode == 0: - current_origin = existing_origin.stdout.strip() - print( - INFO - + f"Remote origin already configured ({current_origin}). Skipping add." - + TERMINATOR - ) - return - command = f"git remote add origin {repo_url}" - subprocess.run(shlex.split(command), check=True, cwd=PROJECT_ROOT) - print(SUCCESS + f"Remote origin={repo_url} added." + TERMINATOR) - else: - print( - WARNING - + "No repo_url provided. Skipping git remote configuration." - + TERMINATOR - ) - - -def maybe_create_repo() -> None: - if not CREATE_REPO: - return - - if not CONFIGURE_REPO: - return - if not REPO_ORG.strip() or not REPO_NAME.strip(): - print(WARNING + "Repo org/name not set. Skipping repo creation." + TERMINATOR) - return - repo_name = f"{REPO_ORG.strip()}/{REPO_NAME.strip()}" - - if REPO_PROVIDER == "github": - if not shutil.which("gh"): - print(WARNING + "gh CLI is not installed. Skipping repo creation." + TERMINATOR) - return - - gh_env = os.environ.copy() - gh_env["GH_HOST"] = "github.com" - - repo_exists = subprocess.run( - ["gh", "repo", "view", repo_name], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - env=gh_env, - ) - if repo_exists.returncode == 0: - print(INFO + f"GitHub repository {repo_name} already exists." + TERMINATOR) - return - - print( - INFO - + f"Creating GitHub repository {repo_name} ({REPO_VISIBILITY})..." - + TERMINATOR - ) - create_repo = subprocess.run( - ["gh", "repo", "create", repo_name, f"--{REPO_VISIBILITY}"], - capture_output=True, - text=True, - env=gh_env, - ) - if create_repo.returncode != 0: - error = create_repo.stderr.strip() or create_repo.stdout.strip() or "unknown error" - print( - WARNING - + f"Failed to create GitHub repository {repo_name}: {error}" - + TERMINATOR - ) - return - print(SUCCESS + f"GitHub repository {repo_name} created." + TERMINATOR) - return - - if REPO_PROVIDER == "gitlab": - if not shutil.which("glab"): - print(WARNING + "glab CLI is not installed. Skipping repo creation." + TERMINATOR) - return - - glab_env = os.environ.copy() - glab_env["GITLAB_HOST"] = "gitlab.com" - repo_exists = subprocess.run( - ["glab", "repo", "view", repo_name], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, - env=glab_env, - ) - if repo_exists.returncode == 0: - print(INFO + f"GitLab repository {repo_name} already exists." + TERMINATOR) - return - - print( - INFO - + f"Creating GitLab repository {repo_name} ({REPO_VISIBILITY})..." - + TERMINATOR - ) - create_repo = subprocess.run( - ["glab", "repo", "create", repo_name, f"--{REPO_VISIBILITY}"], - capture_output=True, - text=True, - env=glab_env, - ) - if create_repo.returncode != 0: - error = create_repo.stderr.strip() or create_repo.stdout.strip() or "unknown error" - print( - WARNING - + f"Failed to create GitLab repository {repo_name}: {error}" - + TERMINATOR - ) - return - print(SUCCESS + f"GitLab repository {repo_name} created." + TERMINATOR) - return - - print( - WARNING - + f"Repo creation not implemented for provider '{REPO_PROVIDER}'. Skipping." - + TERMINATOR - ) - - -def main() -> None: - init_git_repo() - maybe_create_repo() - configure_git_remote() - run_init_script() - - if TASK_RUNNER != "make": - remove("Makefile") - if TASK_RUNNER != "task": - remove("Taskfile.yml") - if TASK_RUNNER != "just": - remove("justfile") - - if CI_PROVIDER != "github": - remove(".github") - if CI_PROVIDER != "gitlab": - remove(".gitlab-ci.yml") - - if not SEMANTIC_RELEASE: - remove("package.json") - remove("dependencies-init.txt") - remove("dependencies-dev-init.txt") - remove(".releaserc.json") - remove("CHANGELOG.md") - remove(".github/workflows/semantic-release.yaml") - remove(".github/workflows/semantic-pull-request.yaml") - - if not SECRET_SCANNING: - remove(".github/workflows/secret-scan.yaml") - - -if __name__ == "__main__": - main() From 51ec3196144f32f86a779c52043eb5e438afab78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sat, 7 Mar 2026 15:29:17 +0200 Subject: [PATCH 06/22] fix(tasks): create initial commit after scaffold init --- template/.scaf/starter-post-copy.sh.jinja | 26 ++++++++++++++++++++++ template/template/.scaf/post-copy.sh.jinja | 26 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/template/.scaf/starter-post-copy.sh.jinja b/template/.scaf/starter-post-copy.sh.jinja index 68a91ea..370062d 100644 --- a/template/.scaf/starter-post-copy.sh.jinja +++ b/template/.scaf/starter-post-copy.sh.jinja @@ -12,6 +12,9 @@ REPO_NAME="{{ copier__repo_name }}" REPO_URL="{{ copier__repo_url }}" CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" REPO_VISIBILITY="{{ copier__repo_visibility }}" +AUTHOR_NAME="{{ copier__author_name }}" +AUTHOR_EMAIL="{{ copier__email }}" +REPO_INITIALIZED="false" TERMINATOR="\033[0m" WARNING="\033[1;33m [WARNING]: " @@ -99,9 +102,31 @@ init_git_repo() { log_info "Initializing git repository..." log_info "Current working directory: $(pwd)" git -c init.defaultBranch=main init . --quiet + REPO_INITIALIZED="true" log_success "Git repository initialized." } +maybe_initial_commit() { + if ! is_true "$REPO_INITIALIZED"; then + return + fi + + if git rev-parse --verify HEAD >/dev/null 2>&1; then + return + fi + + git add -A + if [[ -z "$(git status --porcelain)" ]]; then + return + fi + + if ! git -c "user.name=${AUTHOR_NAME}" -c "user.email=${AUTHOR_EMAIL}" commit --no-verify -m "chore: initialize from template" >/dev/null 2>&1; then + log_warning "Initial commit failed. Configure git user.name and user.email, then commit manually." + return + fi + log_success "Initial commit created." +} + configure_git_remote() { if ! is_true "$CONFIGURE_REPO"; then return @@ -206,6 +231,7 @@ main() { remove_path ".scaf/starter-post-copy.sh" rmdir ".scaf" 2>/dev/null || true + maybe_initial_commit } main "$@" diff --git a/template/template/.scaf/post-copy.sh.jinja b/template/template/.scaf/post-copy.sh.jinja index d085c2b..d5f98e0 100644 --- a/template/template/.scaf/post-copy.sh.jinja +++ b/template/template/.scaf/post-copy.sh.jinja @@ -12,6 +12,9 @@ REPO_NAME="{{ copier__repo_name }}" REPO_URL="{{ copier__repo_url }}" CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" REPO_VISIBILITY="{{ copier__repo_visibility }}" +AUTHOR_NAME="{{ copier__author_name }}" +AUTHOR_EMAIL="{{ copier__email }}" +REPO_INITIALIZED="false" TERMINATOR="\033[0m" WARNING="\033[1;33m [WARNING]: " @@ -51,9 +54,31 @@ init_git_repo() { log_info "Initializing git repository..." log_info "Current working directory: $(pwd)" git -c init.defaultBranch=main init . --quiet + REPO_INITIALIZED="true" log_success "Git repository initialized." } +maybe_initial_commit() { + if ! is_true "$REPO_INITIALIZED"; then + return + fi + + if git rev-parse --verify HEAD >/dev/null 2>&1; then + return + fi + + git add -A + if [[ -z "$(git status --porcelain)" ]]; then + return + fi + + if ! git -c "user.name=${AUTHOR_NAME}" -c "user.email=${AUTHOR_EMAIL}" commit --no-verify -m "chore: initialize from template" >/dev/null 2>&1; then + log_warning "Initial commit failed. Configure git user.name and user.email, then commit manually." + return + fi + log_success "Initial commit created." +} + configure_git_remote() { if ! is_true "$CONFIGURE_REPO"; then return @@ -158,6 +183,7 @@ main() { remove_path ".scaf/post-copy.sh" rmdir ".scaf" 2>/dev/null || true + maybe_initial_commit } main "$@" From ac347a530d24c90fb23b2d14b0f8d10ff2f64b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sat, 7 Mar 2026 15:46:44 +0200 Subject: [PATCH 07/22] refactor(tasks): switch phase post-copy scripts to python --- template/.scaf/starter-post-copy.sh.jinja | 237 --------------------- template/template/.scaf/post-copy.sh.jinja | 189 ---------------- 2 files changed, 426 deletions(-) delete mode 100644 template/.scaf/starter-post-copy.sh.jinja delete mode 100644 template/template/.scaf/post-copy.sh.jinja diff --git a/template/.scaf/starter-post-copy.sh.jinja b/template/.scaf/starter-post-copy.sh.jinja deleted file mode 100644 index 370062d..0000000 --- a/template/.scaf/starter-post-copy.sh.jinja +++ /dev/null @@ -1,237 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -CI_PROVIDER="{{ copier__ci_provider }}" -SEMANTIC_RELEASE="{{ 'true' if copier__enable_semantic_release else 'false' }}" -SECRET_SCANNING="{{ 'true' if copier__enable_secret_scanning else 'false' }}" -TASK_RUNNER="{{ copier__task_runner }}" -CONFIGURE_REPO="{{ 'true' if copier__configure_repo else 'false' }}" -REPO_PROVIDER="{{ copier__repo_provider }}" -REPO_ORG="{{ copier__repo_org }}" -REPO_NAME="{{ copier__repo_name }}" -REPO_URL="{{ copier__repo_url }}" -CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" -REPO_VISIBILITY="{{ copier__repo_visibility }}" -AUTHOR_NAME="{{ copier__author_name }}" -AUTHOR_EMAIL="{{ copier__email }}" -REPO_INITIALIZED="false" - -TERMINATOR="\033[0m" -WARNING="\033[1;33m [WARNING]: " -INFO="\033[1;33m [INFO]: " -SUCCESS="\033[1;32m [SUCCESS]: " - -is_true() { - [[ "${1:-false}" == "true" ]] -} - -log_info() { - printf "%b%s%b\n" "$INFO" "$1" "$TERMINATOR" -} - -log_warning() { - printf "%b%s%b\n" "$WARNING" "$1" "$TERMINATOR" -} - -log_success() { - printf "%b%s%b\n" "$SUCCESS" "$1" "$TERMINATOR" -} - -remove_path() { - local path="$1" - [[ -e "$path" ]] || return 0 - rm -rf "$path" -} - -install_semantic_release_deps() { - local init_file="$1" - local dev_file="$2" - - if command -v npm >/dev/null 2>&1; then - [[ -s "$init_file" ]] && xargs npm install < "$init_file" - [[ -s "$dev_file" ]] && xargs npm install --save-dev < "$dev_file" - return - fi - - if command -v docker >/dev/null 2>&1; then - docker run --rm --user "$(id -u):$(id -g)" -w "/app" -v "$(pwd):/app" -e npm_config_cache=/tmp/.npm node:lts /bin/bash -c \ - "if [ -s \"$init_file\" ]; then xargs npm install < \"$init_file\"; fi; if [ -s \"$dev_file\" ]; then xargs npm install --save-dev < \"$dev_file\"; fi" - return - fi - - log_warning "docker and npm not found; skipping semantic-release dependency install" -} - -run_template_init() { - ( - cd template - - if command -v pre-commit >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then - pre-commit install || echo "pre-commit install failed; continuing" - fi - - if is_true "$SEMANTIC_RELEASE"; then - local tmp_init_file tmp_dev_file tmp_dev_filtered - tmp_init_file="$(mktemp ./.scaf-deps-init.XXXXXX)" - tmp_dev_file="$(mktemp ./.scaf-deps-dev.XXXXXX)" - tmp_dev_filtered="${tmp_dev_file}.filtered" - - sed -E '/[{][{]/d; /[{][%]/d; /^[[:space:]]*$/d' dependencies-init.txt > "$tmp_init_file" - sed -E '/[{][{]/d; /[{][%]/d; /^[[:space:]]*$/d' dependencies-dev-init.txt > "$tmp_dev_file" - - if [[ "$CI_PROVIDER" == "github" ]]; then - awk '!/@semantic-release\/gitlab/' "$tmp_dev_file" > "$tmp_dev_filtered" - mv "$tmp_dev_filtered" "$tmp_dev_file" - elif [[ "$CI_PROVIDER" == "gitlab" ]]; then - awk '!/@semantic-release\/github/' "$tmp_dev_file" > "$tmp_dev_filtered" - mv "$tmp_dev_filtered" "$tmp_dev_file" - fi - - install_semantic_release_deps "$tmp_init_file" "$tmp_dev_file" - rm -f "$tmp_init_file" "$tmp_dev_file" "$tmp_dev_filtered" - fi - - echo "Local development setup complete." - ) -} - -init_git_repo() { - if [[ -d .git ]]; then - return - fi - log_info "Initializing git repository..." - log_info "Current working directory: $(pwd)" - git -c init.defaultBranch=main init . --quiet - REPO_INITIALIZED="true" - log_success "Git repository initialized." -} - -maybe_initial_commit() { - if ! is_true "$REPO_INITIALIZED"; then - return - fi - - if git rev-parse --verify HEAD >/dev/null 2>&1; then - return - fi - - git add -A - if [[ -z "$(git status --porcelain)" ]]; then - return - fi - - if ! git -c "user.name=${AUTHOR_NAME}" -c "user.email=${AUTHOR_EMAIL}" commit --no-verify -m "chore: initialize from template" >/dev/null 2>&1; then - log_warning "Initial commit failed. Configure git user.name and user.email, then commit manually." - return - fi - log_success "Initial commit created." -} - -configure_git_remote() { - if ! is_true "$CONFIGURE_REPO"; then - return - fi - - local repo_url - repo_url="$(printf "%s" "$REPO_URL" | xargs)" - if [[ -z "$repo_url" ]]; then - log_warning "No repo_url provided. Skipping git remote configuration." - return - fi - - log_info "repo_url: $repo_url" - if git remote get-url origin >/dev/null 2>&1; then - local current_origin - current_origin="$(git remote get-url origin)" - log_info "Remote origin already configured (${current_origin}). Skipping add." - return - fi - - git remote add origin "$repo_url" - log_success "Remote origin=${repo_url} added." -} - -maybe_create_repo() { - if ! is_true "$CREATE_REPO" || ! is_true "$CONFIGURE_REPO"; then - return - fi - - if [[ -z "${REPO_ORG// }" || -z "${REPO_NAME// }" ]]; then - log_warning "Repo org/name not set. Skipping repo creation." - return - fi - - local repo_full_name="${REPO_ORG}/${REPO_NAME}" - - if [[ "$REPO_PROVIDER" == "github" ]]; then - if ! command -v gh >/dev/null 2>&1; then - log_warning "gh CLI is not installed. Skipping repo creation." - return - fi - if GH_HOST=github.com gh repo view "$repo_full_name" >/dev/null 2>&1; then - log_info "GitHub repository ${repo_full_name} already exists." - return - fi - log_info "Creating GitHub repository ${repo_full_name} (${REPO_VISIBILITY})..." - if ! create_error="$(GH_HOST=github.com gh repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then - log_warning "Failed to create GitHub repository ${repo_full_name}: ${create_error}" - return - fi - log_success "GitHub repository ${repo_full_name} created." - return - fi - - if [[ "$REPO_PROVIDER" == "gitlab" ]]; then - if ! command -v glab >/dev/null 2>&1; then - log_warning "glab CLI is not installed. Skipping repo creation." - return - fi - if GITLAB_HOST=gitlab.com glab repo view "$repo_full_name" >/dev/null 2>&1; then - log_info "GitLab repository ${repo_full_name} already exists." - return - fi - log_info "Creating GitLab repository ${repo_full_name} (${REPO_VISIBILITY})..." - if ! create_error="$(GITLAB_HOST=gitlab.com glab repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then - log_warning "Failed to create GitLab repository ${repo_full_name}: ${create_error}" - return - fi - log_success "GitLab repository ${repo_full_name} created." - return - fi - - log_warning "Repo creation not implemented for provider '${REPO_PROVIDER}'. Skipping." -} - -main() { - init_git_repo - maybe_create_repo - configure_git_remote - run_template_init - - if [[ "$TASK_RUNNER" != "make" ]]; then remove_path "template/Makefile"; fi - if [[ "$TASK_RUNNER" != "task" ]]; then remove_path "template/Taskfile.yml"; fi - if [[ "$TASK_RUNNER" != "just" ]]; then remove_path "template/justfile"; fi - - if [[ "$CI_PROVIDER" != "github" ]]; then remove_path "template/.github"; fi - if [[ "$CI_PROVIDER" != "gitlab" ]]; then remove_path "template/.gitlab-ci.yml"; fi - - if ! is_true "$SEMANTIC_RELEASE"; then - remove_path "template/package.json" - remove_path "template/dependencies-init.txt" - remove_path "template/dependencies-dev-init.txt" - remove_path "template/.releaserc.json" - remove_path "template/CHANGELOG.md" - remove_path "template/.github/workflows/semantic-release.yaml" - remove_path "template/.github/workflows/semantic-pull-request.yaml" - fi - - if ! is_true "$SECRET_SCANNING"; then - remove_path "template/.github/workflows/secret-scan.yaml" - fi - - remove_path ".scaf/starter-post-copy.sh" - rmdir ".scaf" 2>/dev/null || true - maybe_initial_commit -} - -main "$@" diff --git a/template/template/.scaf/post-copy.sh.jinja b/template/template/.scaf/post-copy.sh.jinja deleted file mode 100644 index d5f98e0..0000000 --- a/template/template/.scaf/post-copy.sh.jinja +++ /dev/null @@ -1,189 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -CI_PROVIDER="{{ copier__ci_provider }}" -SEMANTIC_RELEASE="{{ 'true' if copier__enable_semantic_release else 'false' }}" -SECRET_SCANNING="{{ 'true' if copier__enable_secret_scanning else 'false' }}" -TASK_RUNNER="{{ copier__task_runner }}" -CONFIGURE_REPO="{{ 'true' if copier__configure_repo else 'false' }}" -REPO_PROVIDER="{{ copier__repo_provider }}" -REPO_ORG="{{ copier__repo_org }}" -REPO_NAME="{{ copier__repo_name }}" -REPO_URL="{{ copier__repo_url }}" -CREATE_REPO="{{ 'true' if copier__create_repo else 'false' }}" -REPO_VISIBILITY="{{ copier__repo_visibility }}" -AUTHOR_NAME="{{ copier__author_name }}" -AUTHOR_EMAIL="{{ copier__email }}" -REPO_INITIALIZED="false" - -TERMINATOR="\033[0m" -WARNING="\033[1;33m [WARNING]: " -INFO="\033[1;33m [INFO]: " -SUCCESS="\033[1;32m [SUCCESS]: " - -is_true() { - [[ "${1:-false}" == "true" ]] -} - -log_info() { - printf "%b%s%b\n" "$INFO" "$1" "$TERMINATOR" -} - -log_warning() { - printf "%b%s%b\n" "$WARNING" "$1" "$TERMINATOR" -} - -log_success() { - printf "%b%s%b\n" "$SUCCESS" "$1" "$TERMINATOR" -} - -remove_path() { - local path="$1" - [[ -e "$path" ]] || return 0 - rm -rf "$path" -} - -run_init_script() { - bash ./scripts/init-dev.sh -} - -init_git_repo() { - if [[ -d .git ]]; then - return - fi - log_info "Initializing git repository..." - log_info "Current working directory: $(pwd)" - git -c init.defaultBranch=main init . --quiet - REPO_INITIALIZED="true" - log_success "Git repository initialized." -} - -maybe_initial_commit() { - if ! is_true "$REPO_INITIALIZED"; then - return - fi - - if git rev-parse --verify HEAD >/dev/null 2>&1; then - return - fi - - git add -A - if [[ -z "$(git status --porcelain)" ]]; then - return - fi - - if ! git -c "user.name=${AUTHOR_NAME}" -c "user.email=${AUTHOR_EMAIL}" commit --no-verify -m "chore: initialize from template" >/dev/null 2>&1; then - log_warning "Initial commit failed. Configure git user.name and user.email, then commit manually." - return - fi - log_success "Initial commit created." -} - -configure_git_remote() { - if ! is_true "$CONFIGURE_REPO"; then - return - fi - - local repo_url - repo_url="$(printf "%s" "$REPO_URL" | xargs)" - if [[ -z "$repo_url" ]]; then - log_warning "No repo_url provided. Skipping git remote configuration." - return - fi - - log_info "repo_url: $repo_url" - if git remote get-url origin >/dev/null 2>&1; then - local current_origin - current_origin="$(git remote get-url origin)" - log_info "Remote origin already configured (${current_origin}). Skipping add." - return - fi - - git remote add origin "$repo_url" - log_success "Remote origin=${repo_url} added." -} - -maybe_create_repo() { - if ! is_true "$CREATE_REPO" || ! is_true "$CONFIGURE_REPO"; then - return - fi - - if [[ -z "${REPO_ORG// }" || -z "${REPO_NAME// }" ]]; then - log_warning "Repo org/name not set. Skipping repo creation." - return - fi - - local repo_full_name="${REPO_ORG}/${REPO_NAME}" - - if [[ "$REPO_PROVIDER" == "github" ]]; then - if ! command -v gh >/dev/null 2>&1; then - log_warning "gh CLI is not installed. Skipping repo creation." - return - fi - if GH_HOST=github.com gh repo view "$repo_full_name" >/dev/null 2>&1; then - log_info "GitHub repository ${repo_full_name} already exists." - return - fi - log_info "Creating GitHub repository ${repo_full_name} (${REPO_VISIBILITY})..." - if ! create_error="$(GH_HOST=github.com gh repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then - log_warning "Failed to create GitHub repository ${repo_full_name}: ${create_error}" - return - fi - log_success "GitHub repository ${repo_full_name} created." - return - fi - - if [[ "$REPO_PROVIDER" == "gitlab" ]]; then - if ! command -v glab >/dev/null 2>&1; then - log_warning "glab CLI is not installed. Skipping repo creation." - return - fi - if GITLAB_HOST=gitlab.com glab repo view "$repo_full_name" >/dev/null 2>&1; then - log_info "GitLab repository ${repo_full_name} already exists." - return - fi - log_info "Creating GitLab repository ${repo_full_name} (${REPO_VISIBILITY})..." - if ! create_error="$(GITLAB_HOST=gitlab.com glab repo create "$repo_full_name" "--${REPO_VISIBILITY}" 2>&1)"; then - log_warning "Failed to create GitLab repository ${repo_full_name}: ${create_error}" - return - fi - log_success "GitLab repository ${repo_full_name} created." - return - fi - - log_warning "Repo creation not implemented for provider '${REPO_PROVIDER}'. Skipping." -} - -main() { - init_git_repo - maybe_create_repo - configure_git_remote - run_init_script - - if [[ "$TASK_RUNNER" != "make" ]]; then remove_path "Makefile"; fi - if [[ "$TASK_RUNNER" != "task" ]]; then remove_path "Taskfile.yml"; fi - if [[ "$TASK_RUNNER" != "just" ]]; then remove_path "justfile"; fi - - if [[ "$CI_PROVIDER" != "github" ]]; then remove_path ".github"; fi - if [[ "$CI_PROVIDER" != "gitlab" ]]; then remove_path ".gitlab-ci.yml"; fi - - if ! is_true "$SEMANTIC_RELEASE"; then - remove_path "package.json" - remove_path "dependencies-init.txt" - remove_path "dependencies-dev-init.txt" - remove_path ".releaserc.json" - remove_path "CHANGELOG.md" - remove_path ".github/workflows/semantic-release.yaml" - remove_path ".github/workflows/semantic-pull-request.yaml" - fi - - if ! is_true "$SECRET_SCANNING"; then - remove_path ".github/workflows/secret-scan.yaml" - fi - - remove_path ".scaf/post-copy.sh" - rmdir ".scaf" 2>/dev/null || true - maybe_initial_commit -} - -main "$@" From 7f0e1ed8108cd54916674839a58d5dbf54857517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sun, 8 Mar 2026 11:22:33 +0200 Subject: [PATCH 08/22] fix(pre-commit): skip templated yaml under template dir --- template/template/.pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/template/template/.pre-commit-config.yaml b/template/template/.pre-commit-config.yaml index ef57604..dd552b9 100644 --- a/template/template/.pre-commit-config.yaml +++ b/template/template/.pre-commit-config.yaml @@ -9,3 +9,4 @@ repos: - id: trailing-whitespace - id: check-yaml args: ['--unsafe'] + exclude: '^template/' From d186baf38f55bce22703b587330ff168e8185606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sun, 8 Mar 2026 12:44:20 +0200 Subject: [PATCH 09/22] feat(template): add root render-test Makefile for generated template --- Makefile | 4 + .../workflows/template-correctness.yaml | 24 +----- template/Makefile.jinja | 79 +++++++++++++++++++ template/README.md.jinja | 8 +- 4 files changed, 92 insertions(+), 23 deletions(-) create mode 100644 template/Makefile.jinja diff --git a/Makefile b/Makefile index 9eeabce..4f65d47 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ test-template-render-github: -d copier__enable_secret_scanning=true \ -d copier__task_runner="task"; \ test -f "$$out_dir/copier.yml"; \ + test -f "$$out_dir/Makefile"; \ test -f "$$out_dir/README.md"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ @@ -41,6 +42,7 @@ test-template-render-github: grep -Fq '{{ copier__project_name }}' "$$out_dir/template/README.md"; \ grep -Fq 'copier copy . /path/to/new-project --trust' "$$out_dir/README.md"; \ grep -Eq '^copier__project_name_raw:' "$$out_dir/copier.yml"; \ + $(MAKE) -C "$$out_dir" test-template-render; \ render_dir="$$(mktemp -d /tmp/scaf-template-rendered-gh-XXXXXX)"; \ copier copy "$$out_dir" "$$render_dir" --trust --defaults \ -d copier__configure_repo=false \ @@ -69,6 +71,7 @@ test-template-render-gitlab: -d copier__enable_secret_scanning=true \ -d copier__task_runner="just"; \ test -f "$$out_dir/copier.yml"; \ + test -f "$$out_dir/Makefile"; \ test -f "$$out_dir/README.md"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ @@ -86,6 +89,7 @@ test-template-render-gitlab: grep -Fq '{{ copier__project_name }}' "$$out_dir/template/README.md"; \ grep -Fq 'copier copy . /path/to/new-project --trust' "$$out_dir/README.md"; \ grep -Eq '^copier__project_name_raw:' "$$out_dir/copier.yml"; \ + $(MAKE) -C "$$out_dir" test-template-render; \ render_dir="$$(mktemp -d /tmp/scaf-template-rendered-gl-XXXXXX)"; \ copier copy "$$out_dir" "$$render_dir" --trust --defaults \ -d copier__configure_repo=false \ diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml index f4aa1eb..bf8df6f 100644 --- a/template/.github/workflows/template-correctness.yaml +++ b/template/.github/workflows/template-correctness.yaml @@ -21,25 +21,5 @@ jobs: - name: Install copier run: pip install copier - - name: Render sample project - run: | - copier copy . /tmp/sample-project --trust --defaults \ - -d copier__project_name_raw="Sample Project" \ - -d copier__project_slug="sample_project" \ - -d copier__description="Sample generated project" \ - -d copier__author_name="Sample Author" \ - -d copier__email="sample@example.com" \ - -d copier__version="0.1.0" \ - -d copier__configure_repo=false \ - -d copier__ci_provider="github" \ - -d copier__enable_semantic_release=false \ - -d copier__enable_secret_scanning=false \ - -d copier__task_runner="task" - - - name: Validate generated project files - run: | - test -f /tmp/sample-project/README.md - test -f /tmp/sample-project/.copier-answers.yml - test -f /tmp/sample-project/Taskfile.yml - test ! -f /tmp/sample-project/Makefile - test ! -f /tmp/sample-project/justfile + - name: Run render tests + run: make test-template-render diff --git a/template/Makefile.jinja b/template/Makefile.jinja new file mode 100644 index 0000000..e0b1be6 --- /dev/null +++ b/template/Makefile.jinja @@ -0,0 +1,79 @@ +SHELL := bash + +COPIER_CI_PROVIDER := {{ copier__ci_provider }} +COPIER_TASK_RUNNER := {{ copier__task_runner }} +COPIER_ENABLE_SEMANTIC_RELEASE := {{ 'true' if copier__enable_semantic_release else 'false' }} +COPIER_ENABLE_SECRET_SCANNING := {{ 'true' if copier__enable_secret_scanning else 'false' }} +COPIER_GITHUB_SEMANTIC_RELEASE_AUTH := {{ copier__github_semantic_release_auth if copier__ci_provider == 'github' and copier__enable_semantic_release else 'github_token' }} + +.PHONY: test-template-render + +test-template-render: + @set -euo pipefail; \ + out_dir="$$(mktemp -d /tmp/scaf-template-render-XXXXXX)"; \ + github_auth_arg=""; \ + if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ + github_auth_arg="-d copier__github_semantic_release_auth=$(COPIER_GITHUB_SEMANTIC_RELEASE_AUTH)"; \ + fi; \ + copier copy . "$$out_dir" --trust --defaults \ + -d copier__project_name_raw="Sample Project" \ + -d copier__project_slug="sample_project" \ + -d copier__description="Sample generated project" \ + -d copier__author_name="Sample Author" \ + -d copier__email="sample@example.com" \ + -d copier__version="0.1.0" \ + -d copier__configure_repo=false \ + -d copier__ci_provider="$(COPIER_CI_PROVIDER)" \ + -d copier__enable_semantic_release=$(COPIER_ENABLE_SEMANTIC_RELEASE) \ + $$github_auth_arg \ + -d copier__enable_secret_scanning=$(COPIER_ENABLE_SECRET_SCANNING) \ + -d copier__task_runner="$(COPIER_TASK_RUNNER)"; \ + test -f "$$out_dir/README.md"; \ + test -f "$$out_dir/.copier-answers.yml"; \ + test ! -f "$$out_dir/{% raw %}{{_copier_conf.answers_file}}{% endraw %}"; \ + if [ "$(COPIER_TASK_RUNNER)" = "make" ]; then \ + test -f "$$out_dir/Makefile"; \ + test ! -f "$$out_dir/Taskfile.yml"; \ + test ! -f "$$out_dir/justfile"; \ + elif [ "$(COPIER_TASK_RUNNER)" = "task" ]; then \ + test -f "$$out_dir/Taskfile.yml"; \ + test ! -f "$$out_dir/Makefile"; \ + test ! -f "$$out_dir/justfile"; \ + else \ + test -f "$$out_dir/justfile"; \ + test ! -f "$$out_dir/Makefile"; \ + test ! -f "$$out_dir/Taskfile.yml"; \ + fi; \ + if [ "$(COPIER_CI_PROVIDER)" = "github" ]; then \ + test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ + test ! -f "$$out_dir/.gitlab-ci.yml"; \ + else \ + test -f "$$out_dir/.gitlab-ci.yml"; \ + test ! -d "$$out_dir/.github"; \ + fi; \ + if [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ + test -f "$$out_dir/package.json"; \ + test -f "$$out_dir/dependencies-init.txt"; \ + test -f "$$out_dir/dependencies-dev-init.txt"; \ + test -f "$$out_dir/.releaserc.json"; \ + test -f "$$out_dir/CHANGELOG.md"; \ + else \ + test ! -f "$$out_dir/package.json"; \ + test ! -f "$$out_dir/dependencies-init.txt"; \ + test ! -f "$$out_dir/dependencies-dev-init.txt"; \ + test ! -f "$$out_dir/.releaserc.json"; \ + test ! -f "$$out_dir/CHANGELOG.md"; \ + fi; \ + if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ + test -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ + test -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ + else \ + test ! -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ + test ! -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ + fi; \ + if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SECRET_SCANNING)" = "true" ]; then \ + test -f "$$out_dir/.github/workflows/secret-scan.yaml"; \ + else \ + test ! -f "$$out_dir/.github/workflows/secret-scan.yaml"; \ + fi; \ + rm -rf "$$out_dir" diff --git a/template/README.md.jinja b/template/README.md.jinja index fe1ab7f..51c6a14 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -24,4 +24,10 @@ copier copy /path/to/new-project --trust ## Template Validation -This repository includes `.github/workflows/template-correctness.yaml`, which renders a sample project on every push/PR to verify the template remains valid. +Run local render checks with: + +```bash +make test-template-render +``` + +This repository also includes `.github/workflows/template-correctness.yaml`, which runs the same check on every push/PR (for GitHub CI). From fd7409da5723950cff75b06df588f35079d514e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sun, 8 Mar 2026 17:48:39 +0200 Subject: [PATCH 10/22] refactor(template): use runner template files for stage-1 root tasks --- Makefile | 14 ++- .../workflows/template-correctness.yaml | 2 +- template/.scaf/starter-post-copy.py.jinja | 22 +++++ template/.scaf/task-runners/Makefile | 6 ++ template/.scaf/task-runners/Taskfile.yml | 7 ++ template/.scaf/task-runners/justfile | 2 + template/Makefile.jinja | 79 ----------------- template/README.md.jinja | 6 ++ .../scripts/test-template-render.sh.jinja | 86 +++++++++++++++++++ 9 files changed, 140 insertions(+), 84 deletions(-) create mode 100644 template/.scaf/task-runners/Makefile create mode 100644 template/.scaf/task-runners/Taskfile.yml create mode 100644 template/.scaf/task-runners/justfile delete mode 100644 template/Makefile.jinja create mode 100755 template/scripts/test-template-render.sh.jinja diff --git a/Makefile b/Makefile index 4f65d47..e3d2916 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,13 @@ test-template-render-github: -d copier__enable_secret_scanning=true \ -d copier__task_runner="task"; \ test -f "$$out_dir/copier.yml"; \ - test -f "$$out_dir/Makefile"; \ + test -f "$$out_dir/Taskfile.yml"; \ + test ! -f "$$out_dir/Makefile"; \ + test ! -f "$$out_dir/justfile"; \ test -f "$$out_dir/README.md"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ + test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ test -f "$$out_dir/template/.scaf/post-copy.py"; \ test -f "$$out_dir/template/Taskfile.yml"; \ @@ -42,7 +45,7 @@ test-template-render-github: grep -Fq '{{ copier__project_name }}' "$$out_dir/template/README.md"; \ grep -Fq 'copier copy . /path/to/new-project --trust' "$$out_dir/README.md"; \ grep -Eq '^copier__project_name_raw:' "$$out_dir/copier.yml"; \ - $(MAKE) -C "$$out_dir" test-template-render; \ + (cd "$$out_dir" && bash ./scripts/test-template-render.sh); \ render_dir="$$(mktemp -d /tmp/scaf-template-rendered-gh-XXXXXX)"; \ copier copy "$$out_dir" "$$render_dir" --trust --defaults \ -d copier__configure_repo=false \ @@ -71,10 +74,13 @@ test-template-render-gitlab: -d copier__enable_secret_scanning=true \ -d copier__task_runner="just"; \ test -f "$$out_dir/copier.yml"; \ - test -f "$$out_dir/Makefile"; \ + test -f "$$out_dir/justfile"; \ + test ! -f "$$out_dir/Makefile"; \ + test ! -f "$$out_dir/Taskfile.yml"; \ test -f "$$out_dir/README.md"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ + test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ test -f "$$out_dir/template/.scaf/post-copy.py"; \ test -f "$$out_dir/template/justfile"; \ @@ -89,7 +95,7 @@ test-template-render-gitlab: grep -Fq '{{ copier__project_name }}' "$$out_dir/template/README.md"; \ grep -Fq 'copier copy . /path/to/new-project --trust' "$$out_dir/README.md"; \ grep -Eq '^copier__project_name_raw:' "$$out_dir/copier.yml"; \ - $(MAKE) -C "$$out_dir" test-template-render; \ + (cd "$$out_dir" && bash ./scripts/test-template-render.sh); \ render_dir="$$(mktemp -d /tmp/scaf-template-rendered-gl-XXXXXX)"; \ copier copy "$$out_dir" "$$render_dir" --trust --defaults \ -d copier__configure_repo=false \ diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml index bf8df6f..2ef1636 100644 --- a/template/.github/workflows/template-correctness.yaml +++ b/template/.github/workflows/template-correctness.yaml @@ -22,4 +22,4 @@ jobs: run: pip install copier - name: Run render tests - run: make test-template-render + run: bash ./scripts/test-template-render.sh diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index e7096c7..e034cdc 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -238,7 +238,29 @@ def run_template_init() -> None: print("Local development setup complete.") +def render_root_task_runner() -> None: + runner_templates = PROJECT_ROOT / ".scaf" / "task-runners" + by_runner = { + "make": "Makefile", + "task": "Taskfile.yml", + "just": "justfile", + } + selected = by_runner.get(TASK_RUNNER) + + for runner_file in by_runner.values(): + target = PROJECT_ROOT / runner_file + source = runner_templates / runner_file + if runner_file == selected and source.exists(): + shutil.copyfile(source, target) + else: + remove(target) + + remove(runner_templates) + + def prune_starter_template() -> None: + render_root_task_runner() + if TASK_RUNNER != "make": remove(TEMPLATE_ROOT / "Makefile") if TASK_RUNNER != "task": diff --git a/template/.scaf/task-runners/Makefile b/template/.scaf/task-runners/Makefile new file mode 100644 index 0000000..ef14bf2 --- /dev/null +++ b/template/.scaf/task-runners/Makefile @@ -0,0 +1,6 @@ +SHELL := bash + +.PHONY: test-template-render + +test-template-render: + bash ./scripts/test-template-render.sh diff --git a/template/.scaf/task-runners/Taskfile.yml b/template/.scaf/task-runners/Taskfile.yml new file mode 100644 index 0000000..22041bc --- /dev/null +++ b/template/.scaf/task-runners/Taskfile.yml @@ -0,0 +1,7 @@ +version: "3" + +tasks: + test-template-render: + desc: Validate template rendering output + cmds: + - bash ./scripts/test-template-render.sh diff --git a/template/.scaf/task-runners/justfile b/template/.scaf/task-runners/justfile new file mode 100644 index 0000000..80d797e --- /dev/null +++ b/template/.scaf/task-runners/justfile @@ -0,0 +1,2 @@ +test-template-render: + bash ./scripts/test-template-render.sh diff --git a/template/Makefile.jinja b/template/Makefile.jinja deleted file mode 100644 index e0b1be6..0000000 --- a/template/Makefile.jinja +++ /dev/null @@ -1,79 +0,0 @@ -SHELL := bash - -COPIER_CI_PROVIDER := {{ copier__ci_provider }} -COPIER_TASK_RUNNER := {{ copier__task_runner }} -COPIER_ENABLE_SEMANTIC_RELEASE := {{ 'true' if copier__enable_semantic_release else 'false' }} -COPIER_ENABLE_SECRET_SCANNING := {{ 'true' if copier__enable_secret_scanning else 'false' }} -COPIER_GITHUB_SEMANTIC_RELEASE_AUTH := {{ copier__github_semantic_release_auth if copier__ci_provider == 'github' and copier__enable_semantic_release else 'github_token' }} - -.PHONY: test-template-render - -test-template-render: - @set -euo pipefail; \ - out_dir="$$(mktemp -d /tmp/scaf-template-render-XXXXXX)"; \ - github_auth_arg=""; \ - if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ - github_auth_arg="-d copier__github_semantic_release_auth=$(COPIER_GITHUB_SEMANTIC_RELEASE_AUTH)"; \ - fi; \ - copier copy . "$$out_dir" --trust --defaults \ - -d copier__project_name_raw="Sample Project" \ - -d copier__project_slug="sample_project" \ - -d copier__description="Sample generated project" \ - -d copier__author_name="Sample Author" \ - -d copier__email="sample@example.com" \ - -d copier__version="0.1.0" \ - -d copier__configure_repo=false \ - -d copier__ci_provider="$(COPIER_CI_PROVIDER)" \ - -d copier__enable_semantic_release=$(COPIER_ENABLE_SEMANTIC_RELEASE) \ - $$github_auth_arg \ - -d copier__enable_secret_scanning=$(COPIER_ENABLE_SECRET_SCANNING) \ - -d copier__task_runner="$(COPIER_TASK_RUNNER)"; \ - test -f "$$out_dir/README.md"; \ - test -f "$$out_dir/.copier-answers.yml"; \ - test ! -f "$$out_dir/{% raw %}{{_copier_conf.answers_file}}{% endraw %}"; \ - if [ "$(COPIER_TASK_RUNNER)" = "make" ]; then \ - test -f "$$out_dir/Makefile"; \ - test ! -f "$$out_dir/Taskfile.yml"; \ - test ! -f "$$out_dir/justfile"; \ - elif [ "$(COPIER_TASK_RUNNER)" = "task" ]; then \ - test -f "$$out_dir/Taskfile.yml"; \ - test ! -f "$$out_dir/Makefile"; \ - test ! -f "$$out_dir/justfile"; \ - else \ - test -f "$$out_dir/justfile"; \ - test ! -f "$$out_dir/Makefile"; \ - test ! -f "$$out_dir/Taskfile.yml"; \ - fi; \ - if [ "$(COPIER_CI_PROVIDER)" = "github" ]; then \ - test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ - test ! -f "$$out_dir/.gitlab-ci.yml"; \ - else \ - test -f "$$out_dir/.gitlab-ci.yml"; \ - test ! -d "$$out_dir/.github"; \ - fi; \ - if [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ - test -f "$$out_dir/package.json"; \ - test -f "$$out_dir/dependencies-init.txt"; \ - test -f "$$out_dir/dependencies-dev-init.txt"; \ - test -f "$$out_dir/.releaserc.json"; \ - test -f "$$out_dir/CHANGELOG.md"; \ - else \ - test ! -f "$$out_dir/package.json"; \ - test ! -f "$$out_dir/dependencies-init.txt"; \ - test ! -f "$$out_dir/dependencies-dev-init.txt"; \ - test ! -f "$$out_dir/.releaserc.json"; \ - test ! -f "$$out_dir/CHANGELOG.md"; \ - fi; \ - if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SEMANTIC_RELEASE)" = "true" ]; then \ - test -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ - test -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ - else \ - test ! -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ - test ! -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ - fi; \ - if [ "$(COPIER_CI_PROVIDER)" = "github" ] && [ "$(COPIER_ENABLE_SECRET_SCANNING)" = "true" ]; then \ - test -f "$$out_dir/.github/workflows/secret-scan.yaml"; \ - else \ - test ! -f "$$out_dir/.github/workflows/secret-scan.yaml"; \ - fi; \ - rm -rf "$$out_dir" diff --git a/template/README.md.jinja b/template/README.md.jinja index 51c6a14..b23c307 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -27,7 +27,13 @@ copier copy /path/to/new-project --trust Run local render checks with: ```bash +{% if copier__task_runner == "make" %} make test-template-render +{% elif copier__task_runner == "just" %} +just test-template-render +{% else %} +task test-template-render +{% endif %} ``` This repository also includes `.github/workflows/template-correctness.yaml`, which runs the same check on every push/PR (for GitHub CI). diff --git a/template/scripts/test-template-render.sh.jinja b/template/scripts/test-template-render.sh.jinja new file mode 100755 index 0000000..cd72464 --- /dev/null +++ b/template/scripts/test-template-render.sh.jinja @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +set -euo pipefail + +copier_ci_provider="{{ copier__ci_provider }}" +copier_task_runner="{{ copier__task_runner }}" +copier_enable_semantic_release="{{ 'true' if copier__enable_semantic_release else 'false' }}" +copier_enable_secret_scanning="{{ 'true' if copier__enable_secret_scanning else 'false' }}" +copier_github_semantic_release_auth="{{ copier__github_semantic_release_auth if copier__ci_provider == 'github' and copier__enable_semantic_release else 'github_token' }}" + +out_dir="$(mktemp -d /tmp/scaf-template-render-XXXXXX)" +trap 'rm -rf "$out_dir"' EXIT + +copy_cmd=( + copier copy . "$out_dir" --trust --defaults + -d "copier__project_name_raw=Sample Project" + -d "copier__project_slug=sample_project" + -d "copier__description=Sample generated project" + -d "copier__author_name=Sample Author" + -d "copier__email=sample@example.com" + -d "copier__version=0.1.0" + -d "copier__configure_repo=false" + -d "copier__ci_provider=$copier_ci_provider" + -d "copier__enable_semantic_release=$copier_enable_semantic_release" + -d "copier__enable_secret_scanning=$copier_enable_secret_scanning" + -d "copier__task_runner=$copier_task_runner" +) + +if [[ "$copier_ci_provider" == "github" && "$copier_enable_semantic_release" == "true" ]]; then + copy_cmd+=(-d "copier__github_semantic_release_auth=$copier_github_semantic_release_auth") +fi + +"${copy_cmd[@]}" + +test -f "$out_dir/README.md" +test -f "$out_dir/.copier-answers.yml" +test ! -f "$out_dir/{% raw %}{{_copier_conf.answers_file}}{% endraw %}" + +if [[ "$copier_task_runner" == "make" ]]; then + test -f "$out_dir/Makefile" + test ! -f "$out_dir/Taskfile.yml" + test ! -f "$out_dir/justfile" +elif [[ "$copier_task_runner" == "task" ]]; then + test -f "$out_dir/Taskfile.yml" + test ! -f "$out_dir/Makefile" + test ! -f "$out_dir/justfile" +else + test -f "$out_dir/justfile" + test ! -f "$out_dir/Makefile" + test ! -f "$out_dir/Taskfile.yml" +fi + +if [[ "$copier_ci_provider" == "github" ]]; then + test -f "$out_dir/.github/workflows/template-correctness.yaml" + test ! -f "$out_dir/.gitlab-ci.yml" +else + test -f "$out_dir/.gitlab-ci.yml" + test ! -d "$out_dir/.github" +fi + +if [[ "$copier_enable_semantic_release" == "true" ]]; then + test -f "$out_dir/package.json" + test -f "$out_dir/dependencies-init.txt" + test -f "$out_dir/dependencies-dev-init.txt" + test -f "$out_dir/.releaserc.json" + test -f "$out_dir/CHANGELOG.md" +else + test ! -f "$out_dir/package.json" + test ! -f "$out_dir/dependencies-init.txt" + test ! -f "$out_dir/dependencies-dev-init.txt" + test ! -f "$out_dir/.releaserc.json" + test ! -f "$out_dir/CHANGELOG.md" +fi + +if [[ "$copier_ci_provider" == "github" && "$copier_enable_semantic_release" == "true" ]]; then + test -f "$out_dir/.github/workflows/semantic-release.yaml" + test -f "$out_dir/.github/workflows/semantic-pull-request.yaml" +else + test ! -f "$out_dir/.github/workflows/semantic-release.yaml" + test ! -f "$out_dir/.github/workflows/semantic-pull-request.yaml" +fi + +if [[ "$copier_ci_provider" == "github" && "$copier_enable_secret_scanning" == "true" ]]; then + test -f "$out_dir/.github/workflows/secret-scan.yaml" +else + test ! -f "$out_dir/.github/workflows/secret-scan.yaml" +fi From e9c29a33186c0be97e6909ee2cc9cafbca39c885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sun, 8 Mar 2026 18:00:22 +0200 Subject: [PATCH 11/22] fix(pre-commit): scope template yaml exclusion to stage-1 only --- template/.pre-commit-config.yaml | 12 ++++++++++++ template/template/.pre-commit-config.yaml | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 template/.pre-commit-config.yaml diff --git a/template/.pre-commit-config.yaml b/template/.pre-commit-config.yaml new file mode 100644 index 0000000..dd552b9 --- /dev/null +++ b/template/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-case-conflict + - id: check-merge-conflict + - id: detect-private-key + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-yaml + args: ['--unsafe'] + exclude: '^template/' diff --git a/template/template/.pre-commit-config.yaml b/template/template/.pre-commit-config.yaml index dd552b9..ef57604 100644 --- a/template/template/.pre-commit-config.yaml +++ b/template/template/.pre-commit-config.yaml @@ -9,4 +9,3 @@ repos: - id: trailing-whitespace - id: check-yaml args: ['--unsafe'] - exclude: '^template/' From 0df770ca5445b681193cda42d22ad044df0113c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Sun, 8 Mar 2026 18:02:08 +0200 Subject: [PATCH 12/22] feat(template): include license in stage-1 and stage-2 outputs --- Makefile | 6 + template/LICENSE | 178 ++++++++++++++++++ .../scripts/test-template-render.sh.jinja | 1 + template/template/LICENSE | 178 ++++++++++++++++++ 4 files changed, 363 insertions(+) create mode 100644 template/LICENSE create mode 100644 template/template/LICENSE diff --git a/Makefile b/Makefile index e3d2916..159f950 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,12 @@ test-template-render-github: test ! -f "$$out_dir/Makefile"; \ test ! -f "$$out_dir/justfile"; \ test -f "$$out_dir/README.md"; \ + test -f "$$out_dir/LICENSE"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ + test -f "$$out_dir/template/LICENSE"; \ test -f "$$out_dir/template/.scaf/post-copy.py"; \ test -f "$$out_dir/template/Taskfile.yml"; \ test ! -f "$$out_dir/template/Makefile"; \ @@ -54,6 +56,7 @@ test-template-render-github: -d copier__ci_provider="github" \ -d copier__task_runner="task"; \ test -f "$$render_dir/.copier-answers.yml"; \ + test -f "$$render_dir/LICENSE"; \ test ! -f "$$render_dir/{{_copier_conf.answers_file}}"; \ rm -rf "$$render_dir"; \ rm -rf "$$out_dir" @@ -78,10 +81,12 @@ test-template-render-gitlab: test ! -f "$$out_dir/Makefile"; \ test ! -f "$$out_dir/Taskfile.yml"; \ test -f "$$out_dir/README.md"; \ + test -f "$$out_dir/LICENSE"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ + test -f "$$out_dir/template/LICENSE"; \ test -f "$$out_dir/template/.scaf/post-copy.py"; \ test -f "$$out_dir/template/justfile"; \ test ! -f "$$out_dir/template/Makefile"; \ @@ -104,6 +109,7 @@ test-template-render-gitlab: -d copier__ci_provider="gitlab" \ -d copier__task_runner="just"; \ test -f "$$render_dir/.copier-answers.yml"; \ + test -f "$$render_dir/LICENSE"; \ test ! -f "$$render_dir/{{_copier_conf.answers_file}}"; \ rm -rf "$$render_dir"; \ rm -rf "$$out_dir" diff --git a/template/LICENSE b/template/LICENSE new file mode 100644 index 0000000..587222c --- /dev/null +++ b/template/LICENSE @@ -0,0 +1,178 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or +Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices +stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works +that You distribute, all copyright, patent, trademark, and +attribution notices from the Source form of the Work, +excluding those notices that do not pertain to any part of +the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its +distribution, then any Derivative Works that You distribute must +include a readable copy of the attribution notices contained +within such NOTICE file, excluding those notices that do not +pertain to any part of the Derivative Works, in at least one +of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, +within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents +of the NOTICE file are for informational purposes only and +do not modify the License. You may add Your own attribution +notices within Derivative Works that You distribute, alongside +or as an addendum to the NOTICE text from the Work, provided +that such additional attribution notices cannot be construed +as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +Copyright 2026 getscaf contributors diff --git a/template/scripts/test-template-render.sh.jinja b/template/scripts/test-template-render.sh.jinja index cd72464..35c1a79 100755 --- a/template/scripts/test-template-render.sh.jinja +++ b/template/scripts/test-template-render.sh.jinja @@ -32,6 +32,7 @@ fi "${copy_cmd[@]}" test -f "$out_dir/README.md" +test -f "$out_dir/LICENSE" test -f "$out_dir/.copier-answers.yml" test ! -f "$out_dir/{% raw %}{{_copier_conf.answers_file}}{% endraw %}" diff --git a/template/template/LICENSE b/template/template/LICENSE new file mode 100644 index 0000000..587222c --- /dev/null +++ b/template/template/LICENSE @@ -0,0 +1,178 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or +Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices +stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works +that You distribute, all copyright, patent, trademark, and +attribution notices from the Source form of the Work, +excluding those notices that do not pertain to any part of +the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its +distribution, then any Derivative Works that You distribute must +include a readable copy of the attribution notices contained +within such NOTICE file, excluding those notices that do not +pertain to any part of the Derivative Works, in at least one +of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, +within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents +of the NOTICE file are for informational purposes only and +do not modify the License. You may add Your own attribution +notices within Derivative Works that You distribute, alongside +or as an addendum to the NOTICE text from the Work, provided +that such additional attribution notices cannot be construed +as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +Copyright 2026 getscaf contributors From 6359e2b480d9becb3797fe6bac9f776130466458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 11:21:01 +0200 Subject: [PATCH 13/22] fix(ci): skip repository creation during template render tests --- Makefile | 2 ++ template/scripts/test-template-render.sh.jinja | 1 + template/template/.github/workflows/template-correctness.yaml | 2 ++ template/template/.gitlab-ci.yml | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 159f950..1cf5aff 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ test-template-render-github: -d copier__ci_provider="github" \ -d copier__enable_semantic_release=false \ -d copier__github_semantic_release_auth="github_token" \ + -d copier__create_repo=false \ -d copier__enable_secret_scanning=true \ -d copier__task_runner="task"; \ test -f "$$out_dir/copier.yml"; \ @@ -74,6 +75,7 @@ test-template-render-gitlab: -d copier__version="0.1.0" \ -d copier__ci_provider="gitlab" \ -d copier__enable_semantic_release=false \ + -d copier__create_repo=false \ -d copier__enable_secret_scanning=true \ -d copier__task_runner="just"; \ test -f "$$out_dir/copier.yml"; \ diff --git a/template/scripts/test-template-render.sh.jinja b/template/scripts/test-template-render.sh.jinja index 35c1a79..79fdc06 100755 --- a/template/scripts/test-template-render.sh.jinja +++ b/template/scripts/test-template-render.sh.jinja @@ -19,6 +19,7 @@ copy_cmd=( -d "copier__email=sample@example.com" -d "copier__version=0.1.0" -d "copier__configure_repo=false" + -d "copier__create_repo=false" -d "copier__ci_provider=$copier_ci_provider" -d "copier__enable_semantic_release=$copier_enable_semantic_release" -d "copier__enable_secret_scanning=$copier_enable_secret_scanning" diff --git a/template/template/.github/workflows/template-correctness.yaml b/template/template/.github/workflows/template-correctness.yaml index c40151d..2f3e2ae 100644 --- a/template/template/.github/workflows/template-correctness.yaml +++ b/template/template/.github/workflows/template-correctness.yaml @@ -30,6 +30,8 @@ jobs: -d copier__author_name="Sample Author" \ -d copier__email="sample@example.com" \ -d copier__version="0.1.0" \ + -d copier__configure_repo=false \ + -d copier__create_repo=false \ -d copier__ci_provider="{{ copier__ci_provider }}" \ -d copier__enable_semantic_release={{ 'true' if copier__enable_semantic_release else 'false' }} \ -d copier__github_semantic_release_auth="{{ copier__github_semantic_release_auth }}" \ diff --git a/template/template/.gitlab-ci.yml b/template/template/.gitlab-ci.yml index 2e91ef7..662a459 100644 --- a/template/template/.gitlab-ci.yml +++ b/template/template/.gitlab-ci.yml @@ -12,7 +12,7 @@ template_correctness: image: python:3.11 script: - pip install copier - - copier copy . /tmp/{{ copier__template_sample_name }} --trust --defaults -d copier__project_name_raw="Sample Project" -d copier__project_slug="sample_project" -d copier__description="Sample generated project" -d copier__author_name="Sample Author" -d copier__email="sample@example.com" -d copier__version="0.1.0" -d copier__ci_provider="gitlab" -d copier__enable_semantic_release={{ 'true' if copier__enable_semantic_release else 'false' }} -d copier__github_semantic_release_auth="{{ copier__github_semantic_release_auth }}" -d copier__enable_secret_scanning={{ 'true' if copier__enable_secret_scanning else 'false' }} -d copier__task_runner="{{ copier__task_runner }}" + - copier copy . /tmp/{{ copier__template_sample_name }} --trust --defaults -d copier__project_name_raw="Sample Project" -d copier__project_slug="sample_project" -d copier__description="Sample generated project" -d copier__author_name="Sample Author" -d copier__email="sample@example.com" -d copier__version="0.1.0" -d copier__configure_repo=false -d copier__create_repo=false -d copier__ci_provider="gitlab" -d copier__enable_semantic_release={{ 'true' if copier__enable_semantic_release else 'false' }} -d copier__github_semantic_release_auth="{{ copier__github_semantic_release_auth }}" -d copier__enable_secret_scanning={{ 'true' if copier__enable_secret_scanning else 'false' }} -d copier__task_runner="{{ copier__task_runner }}" - test -f /tmp/{{ copier__template_sample_name }}/README.md {% if copier__enable_secret_scanning %} From b53224f3cfd7367cf63a07506532be04db201523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 12:12:31 +0200 Subject: [PATCH 14/22] fix(ci): pin node 22.14 for template render workflows --- .github/workflows/template-render-tests.yaml | 5 +++++ template/.github/workflows/template-correctness.yaml | 5 +++++ .../template/.github/workflows/template-correctness.yaml | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.github/workflows/template-render-tests.yaml b/.github/workflows/template-render-tests.yaml index 402c2c6..6c2f68d 100644 --- a/.github/workflows/template-render-tests.yaml +++ b/.github/workflows/template-render-tests.yaml @@ -18,6 +18,11 @@ jobs: with: python-version: '3.11' + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "22.14.0" + - name: Install copier run: pip install copier diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml index 2ef1636..612e22f 100644 --- a/template/.github/workflows/template-correctness.yaml +++ b/template/.github/workflows/template-correctness.yaml @@ -18,6 +18,11 @@ jobs: with: python-version: '3.11' + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "22.14.0" + - name: Install copier run: pip install copier diff --git a/template/template/.github/workflows/template-correctness.yaml b/template/template/.github/workflows/template-correctness.yaml index 2f3e2ae..c377c60 100644 --- a/template/template/.github/workflows/template-correctness.yaml +++ b/template/template/.github/workflows/template-correctness.yaml @@ -18,6 +18,11 @@ jobs: with: python-version: '3.11' + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "22.14.0" + - name: Install copier run: pip install copier From 69946d04085e7321978a8d85f0948f420f1c8c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 12:20:06 +0200 Subject: [PATCH 15/22] fix(template): restore stage-1 semantic workflows and prune correctly --- Makefile | 4 ++ .../workflows/semantic-pull-request.yaml | 17 +++++++ .../workflows/semantic-release.yaml.jinja | 46 +++++++++++++++++++ template/.scaf/starter-post-copy.py.jinja | 4 ++ 4 files changed, 71 insertions(+) create mode 100644 template/.github/workflows/semantic-pull-request.yaml create mode 100644 template/.github/workflows/semantic-release.yaml.jinja diff --git a/Makefile b/Makefile index 1cf5aff..59292de 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,8 @@ test-template-render-github: test -f "$$out_dir/README.md"; \ test -f "$$out_dir/LICENSE"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ + test ! -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ + test ! -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ @@ -85,6 +87,8 @@ test-template-render-gitlab: test -f "$$out_dir/README.md"; \ test -f "$$out_dir/LICENSE"; \ test -f "$$out_dir/.github/workflows/template-correctness.yaml"; \ + test ! -f "$$out_dir/.github/workflows/semantic-release.yaml"; \ + test ! -f "$$out_dir/.github/workflows/semantic-pull-request.yaml"; \ test -f "$$out_dir/.copier-answers.yml"; \ test -f "$$out_dir/scripts/test-template-render.sh"; \ test -f "$$out_dir/template/README.md"; \ diff --git a/template/.github/workflows/semantic-pull-request.yaml b/template/.github/workflows/semantic-pull-request.yaml new file mode 100644 index 0000000..817c466 --- /dev/null +++ b/template/.github/workflows/semantic-pull-request.yaml @@ -0,0 +1,17 @@ +name: Lint PR + +on: + pull_request_target: + types: [opened, edited, synchronize, reopened] + +permissions: + pull-requests: read + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/template/.github/workflows/semantic-release.yaml.jinja b/template/.github/workflows/semantic-release.yaml.jinja new file mode 100644 index 0000000..c629ed4 --- /dev/null +++ b/template/.github/workflows/semantic-release.yaml.jinja @@ -0,0 +1,46 @@ +name: Semantic Release + +on: + push: + branches: [main] + +permissions: + contents: write + issues: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + {% if copier__github_semantic_release_auth == "github_app" %} + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: {% raw %}${{ secrets.SEMANTIC_RELEASE_APP_ID }}{% endraw %} + private-key: {% raw %}${{ secrets.SEMANTIC_RELEASE_APP_PRIVATE_KEY }}{% endraw %} + + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + token: {% raw %}${{ steps.app-token.outputs.token }}{% endraw %} + {% else %} + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + {% endif %} + + - uses: actions/setup-node@v4 + with: + node-version: "22.14.0" + + - run: npm install + + - run: npx semantic-release + env: + {% if copier__github_semantic_release_auth == "github_app" %} + GITHUB_TOKEN: {% raw %}${{ steps.app-token.outputs.token }}{% endraw %} + {% else %} + GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + {% endif %} diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index e034cdc..34d28b9 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -273,6 +273,10 @@ def prune_starter_template() -> None: if CI_PROVIDER != "gitlab": remove(TEMPLATE_ROOT / ".gitlab-ci.yml") + if CI_PROVIDER != "github" or not SEMANTIC_RELEASE: + remove(PROJECT_ROOT / ".github/workflows/semantic-release.yaml") + remove(PROJECT_ROOT / ".github/workflows/semantic-pull-request.yaml") + if not SEMANTIC_RELEASE: remove(TEMPLATE_ROOT / "package.json") remove(TEMPLATE_ROOT / "dependencies-init.txt") From b6011871d31867ad07776a8615511cbd75a13dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 12:33:51 +0200 Subject: [PATCH 16/22] chore(ci): use node lts aliases across workflows --- .github/workflows/template-render-tests.yaml | 2 +- template/.github/workflows/semantic-release.yaml.jinja | 2 +- template/.github/workflows/template-correctness.yaml | 2 +- template/template/.github/workflows/semantic-release.yaml | 2 +- template/template/.github/workflows/template-correctness.yaml | 2 +- template/template/.gitlab-ci.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/template-render-tests.yaml b/.github/workflows/template-render-tests.yaml index 6c2f68d..d90d7bd 100644 --- a/.github/workflows/template-render-tests.yaml +++ b/.github/workflows/template-render-tests.yaml @@ -21,7 +21,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: "22.14.0" + node-version: "lts/*" - name: Install copier run: pip install copier diff --git a/template/.github/workflows/semantic-release.yaml.jinja b/template/.github/workflows/semantic-release.yaml.jinja index c629ed4..fa82567 100644 --- a/template/.github/workflows/semantic-release.yaml.jinja +++ b/template/.github/workflows/semantic-release.yaml.jinja @@ -33,7 +33,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: "22.14.0" + node-version: "lts/*" - run: npm install diff --git a/template/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml index 612e22f..c204c8c 100644 --- a/template/.github/workflows/template-correctness.yaml +++ b/template/.github/workflows/template-correctness.yaml @@ -21,7 +21,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: "22.14.0" + node-version: "lts/*" - name: Install copier run: pip install copier diff --git a/template/template/.github/workflows/semantic-release.yaml b/template/template/.github/workflows/semantic-release.yaml index a626292..b18b2f6 100644 --- a/template/template/.github/workflows/semantic-release.yaml +++ b/template/template/.github/workflows/semantic-release.yaml @@ -33,7 +33,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 'lts/*' + node-version: "lts/*" - run: npm install diff --git a/template/template/.github/workflows/template-correctness.yaml b/template/template/.github/workflows/template-correctness.yaml index c377c60..0f75bb5 100644 --- a/template/template/.github/workflows/template-correctness.yaml +++ b/template/template/.github/workflows/template-correctness.yaml @@ -21,7 +21,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: "22.14.0" + node-version: "lts/*" - name: Install copier run: pip install copier diff --git a/template/template/.gitlab-ci.yml b/template/template/.gitlab-ci.yml index 662a459..49be435 100644 --- a/template/template/.gitlab-ci.yml +++ b/template/template/.gitlab-ci.yml @@ -26,7 +26,7 @@ secret_scan: {% if copier__enable_semantic_release %} semantic_release: stage: release - image: node:22 + image: node:lts script: - npm install - npx semantic-release From c7e62cbc7a344e2d154cc9a21fc309cbeba82590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:05:54 +0200 Subject: [PATCH 17/22] fix(starter): render root semantic workflows from .scaf assets --- template/.scaf/starter-post-copy.py.jinja | 27 ++++++++++++++++--- .../workflows/semantic-pull-request.yaml | 0 .../workflows/semantic-release.yaml.jinja | 0 3 files changed, 23 insertions(+), 4 deletions(-) rename template/{.github => .scaf}/workflows/semantic-pull-request.yaml (100%) rename template/{.github => .scaf}/workflows/semantic-release.yaml.jinja (100%) diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index 34d28b9..b17c96e 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -258,8 +258,31 @@ def render_root_task_runner() -> None: remove(runner_templates) +def render_root_semantic_workflows() -> None: + workflow_templates = PROJECT_ROOT / ".scaf" / "workflows" + root_workflows = PROJECT_ROOT / ".github" / "workflows" + root_workflows.mkdir(parents=True, exist_ok=True) + + workflow_files = [ + "semantic-release.yaml", + "semantic-pull-request.yaml", + ] + + for workflow_file in workflow_files: + source = workflow_templates / workflow_file + target = root_workflows / workflow_file + + if CI_PROVIDER == "github" and SEMANTIC_RELEASE and source.exists(): + shutil.copyfile(source, target) + else: + remove(target) + + remove(workflow_templates) + + def prune_starter_template() -> None: render_root_task_runner() + render_root_semantic_workflows() if TASK_RUNNER != "make": remove(TEMPLATE_ROOT / "Makefile") @@ -273,10 +296,6 @@ def prune_starter_template() -> None: if CI_PROVIDER != "gitlab": remove(TEMPLATE_ROOT / ".gitlab-ci.yml") - if CI_PROVIDER != "github" or not SEMANTIC_RELEASE: - remove(PROJECT_ROOT / ".github/workflows/semantic-release.yaml") - remove(PROJECT_ROOT / ".github/workflows/semantic-pull-request.yaml") - if not SEMANTIC_RELEASE: remove(TEMPLATE_ROOT / "package.json") remove(TEMPLATE_ROOT / "dependencies-init.txt") diff --git a/template/.github/workflows/semantic-pull-request.yaml b/template/.scaf/workflows/semantic-pull-request.yaml similarity index 100% rename from template/.github/workflows/semantic-pull-request.yaml rename to template/.scaf/workflows/semantic-pull-request.yaml diff --git a/template/.github/workflows/semantic-release.yaml.jinja b/template/.scaf/workflows/semantic-release.yaml.jinja similarity index 100% rename from template/.github/workflows/semantic-release.yaml.jinja rename to template/.scaf/workflows/semantic-release.yaml.jinja From 57846500309acb3a91e5052ab382f6ad05f9d9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:14:41 +0200 Subject: [PATCH 18/22] fix(starter): install pre-commit from project root --- template/.scaf/starter-post-copy.py.jinja | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index b17c96e..10264dd 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -194,9 +194,9 @@ def install_semantic_release_deps(init_file: pathlib.Path, dev_file: pathlib.Pat def run_template_init() -> None: - if shutil.which("pre-commit") and try_run(["git", "rev-parse", "--is-inside-work-tree"], cwd=TEMPLATE_ROOT): + if shutil.which("pre-commit") and try_run(["git", "rev-parse", "--is-inside-work-tree"], cwd=PROJECT_ROOT): try: - run(["pre-commit", "install"], cwd=TEMPLATE_ROOT) + run(["pre-commit", "install"], cwd=PROJECT_ROOT) except subprocess.CalledProcessError: print("pre-commit install failed; continuing") From bfa54f72a808e9f62148c478a6eb8941f9443d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:19:58 +0200 Subject: [PATCH 19/22] fix(ci): run starter semantic-release from template dir --- template/.scaf/workflows/semantic-release.yaml.jinja | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template/.scaf/workflows/semantic-release.yaml.jinja b/template/.scaf/workflows/semantic-release.yaml.jinja index fa82567..d122a7a 100644 --- a/template/.scaf/workflows/semantic-release.yaml.jinja +++ b/template/.scaf/workflows/semantic-release.yaml.jinja @@ -36,8 +36,10 @@ jobs: node-version: "lts/*" - run: npm install + working-directory: template - run: npx semantic-release + working-directory: template env: {% if copier__github_semantic_release_auth == "github_app" %} GITHUB_TOKEN: {% raw %}${{ steps.app-token.outputs.token }}{% endraw %} From bf2ffc0b9f82c2666640815619aeb3b831ca66ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:25:01 +0200 Subject: [PATCH 20/22] fix(starter): generate root semantic-release npm assets --- template/.releaserc.json.jinja | 14 +++++++++++++ template/.scaf/starter-post-copy.py.jinja | 21 ++++++++++++------- .../workflows/semantic-release.yaml.jinja | 2 -- template/CHANGELOG.md | 1 + template/dependencies-dev-init.txt.jinja | 11 ++++++++++ template/dependencies-init.txt | 0 template/package.json.jinja | 5 +++++ 7 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 template/.releaserc.json.jinja create mode 100644 template/CHANGELOG.md create mode 100644 template/dependencies-dev-init.txt.jinja create mode 100644 template/dependencies-init.txt create mode 100644 template/package.json.jinja diff --git a/template/.releaserc.json.jinja b/template/.releaserc.json.jinja new file mode 100644 index 0000000..9f42172 --- /dev/null +++ b/template/.releaserc.json.jinja @@ -0,0 +1,14 @@ +{ + "branches": ["main"], + "plugins": [ + ["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }], + ["@semantic-release/release-notes-generator", { "preset": "conventionalcommits" }], + ["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md", "changelogTitle": "# Changelog" }], +{% if copier__ci_provider == "github" %} + "@semantic-release/github", +{% else %} + "@semantic-release/gitlab", +{% endif %} + ["@semantic-release/git", { "assets": ["package.json", "CHANGELOG.md"], "message": "chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}" }] + ] +} diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index 10264dd..3ffe64f 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -159,9 +159,9 @@ def install_semantic_release_deps(init_file: pathlib.Path, dev_file: pathlib.Pat if shutil.which("npm"): if init_packages: - run(["npm", "install", *init_packages], cwd=TEMPLATE_ROOT) + run(["npm", "install", *init_packages], cwd=PROJECT_ROOT) if dev_packages: - run(["npm", "install", "--save-dev", *dev_packages], cwd=TEMPLATE_ROOT) + run(["npm", "install", "--save-dev", *dev_packages], cwd=PROJECT_ROOT) return if shutil.which("docker"): @@ -175,7 +175,7 @@ def install_semantic_release_deps(init_file: pathlib.Path, dev_file: pathlib.Pat "-w", "/app", "-v", - f"{TEMPLATE_ROOT}:/app", + f"{PROJECT_ROOT}:/app", "-e", "npm_config_cache=/tmp/.npm", "node:lts", @@ -186,7 +186,7 @@ def install_semantic_release_deps(init_file: pathlib.Path, dev_file: pathlib.Pat f"if [ -s {dev_file.name!r} ]; then xargs npm install --save-dev < {dev_file.name!r}; fi" ), ], - cwd=TEMPLATE_ROOT, + cwd=PROJECT_ROOT, ) return @@ -201,12 +201,12 @@ def run_template_init() -> None: print("pre-commit install failed; continuing") if SEMANTIC_RELEASE: - init_deps = TEMPLATE_ROOT / "dependencies-init.txt" - dev_deps = TEMPLATE_ROOT / "dependencies-dev-init.txt" + init_deps = PROJECT_ROOT / "dependencies-init.txt" + dev_deps = PROJECT_ROOT / "dependencies-dev-init.txt" if has_unrendered_jinja(init_deps) or has_unrendered_jinja(dev_deps): with tempfile.NamedTemporaryFile( - mode="w", dir=TEMPLATE_ROOT, prefix=".scaf-deps-init.", delete=False + mode="w", dir=PROJECT_ROOT, prefix=".scaf-deps-init.", delete=False ) as init_tmp: for line in read_packages(init_deps): if ("{" + "{") in line or ("{" + "%") in line: @@ -215,7 +215,7 @@ def run_template_init() -> None: init_tmp_path = pathlib.Path(init_tmp.name) with tempfile.NamedTemporaryFile( - mode="w", dir=TEMPLATE_ROOT, prefix=".scaf-deps-dev.", delete=False + mode="w", dir=PROJECT_ROOT, prefix=".scaf-deps-dev.", delete=False ) as dev_tmp: for line in read_packages(dev_deps): if ("{" + "{") in line or ("{" + "%") in line: @@ -297,6 +297,11 @@ def prune_starter_template() -> None: remove(TEMPLATE_ROOT / ".gitlab-ci.yml") if not SEMANTIC_RELEASE: + remove(PROJECT_ROOT / "package.json") + remove(PROJECT_ROOT / "dependencies-init.txt") + remove(PROJECT_ROOT / "dependencies-dev-init.txt") + remove(PROJECT_ROOT / ".releaserc.json") + remove(PROJECT_ROOT / "CHANGELOG.md") remove(TEMPLATE_ROOT / "package.json") remove(TEMPLATE_ROOT / "dependencies-init.txt") remove(TEMPLATE_ROOT / "dependencies-dev-init.txt") diff --git a/template/.scaf/workflows/semantic-release.yaml.jinja b/template/.scaf/workflows/semantic-release.yaml.jinja index d122a7a..fa82567 100644 --- a/template/.scaf/workflows/semantic-release.yaml.jinja +++ b/template/.scaf/workflows/semantic-release.yaml.jinja @@ -36,10 +36,8 @@ jobs: node-version: "lts/*" - run: npm install - working-directory: template - run: npx semantic-release - working-directory: template env: {% if copier__github_semantic_release_auth == "github_app" %} GITHUB_TOKEN: {% raw %}${{ steps.app-token.outputs.token }}{% endraw %} diff --git a/template/CHANGELOG.md b/template/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/template/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/template/dependencies-dev-init.txt.jinja b/template/dependencies-dev-init.txt.jinja new file mode 100644 index 0000000..a59ed91 --- /dev/null +++ b/template/dependencies-dev-init.txt.jinja @@ -0,0 +1,11 @@ +semantic-release +@semantic-release/commit-analyzer +@semantic-release/release-notes-generator +@semantic-release/changelog +@semantic-release/git +conventional-changelog-conventionalcommits +{% if copier__ci_provider == "github" %} +@semantic-release/github +{% else %} +@semantic-release/gitlab +{% endif %} diff --git a/template/dependencies-init.txt b/template/dependencies-init.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/package.json.jinja b/template/package.json.jinja new file mode 100644 index 0000000..9f399b7 --- /dev/null +++ b/template/package.json.jinja @@ -0,0 +1,5 @@ +{ + "name": "{{ copier__project_dash }}", + "version": "{{ copier__version }}", + "private": true +} From 0bfab289310eb3e99438932e1a98f960aefdf3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:34:20 +0200 Subject: [PATCH 21/22] fix(starter): avoid root/template semantic file collisions --- .../semantic-assets}/.releaserc.json.jinja | 0 .../{ => .scaf/semantic-assets}/CHANGELOG.md | 0 .../dependencies-dev-init.txt.jinja | 0 .../semantic-assets}/dependencies-init.txt | 0 .../semantic-assets}/package.json.jinja | 0 template/.scaf/starter-post-copy.py.jinja | 22 +++++++++++++++++++ 6 files changed, 22 insertions(+) rename template/{ => .scaf/semantic-assets}/.releaserc.json.jinja (100%) rename template/{ => .scaf/semantic-assets}/CHANGELOG.md (100%) rename template/{ => .scaf/semantic-assets}/dependencies-dev-init.txt.jinja (100%) rename template/{ => .scaf/semantic-assets}/dependencies-init.txt (100%) rename template/{ => .scaf/semantic-assets}/package.json.jinja (100%) diff --git a/template/.releaserc.json.jinja b/template/.scaf/semantic-assets/.releaserc.json.jinja similarity index 100% rename from template/.releaserc.json.jinja rename to template/.scaf/semantic-assets/.releaserc.json.jinja diff --git a/template/CHANGELOG.md b/template/.scaf/semantic-assets/CHANGELOG.md similarity index 100% rename from template/CHANGELOG.md rename to template/.scaf/semantic-assets/CHANGELOG.md diff --git a/template/dependencies-dev-init.txt.jinja b/template/.scaf/semantic-assets/dependencies-dev-init.txt.jinja similarity index 100% rename from template/dependencies-dev-init.txt.jinja rename to template/.scaf/semantic-assets/dependencies-dev-init.txt.jinja diff --git a/template/dependencies-init.txt b/template/.scaf/semantic-assets/dependencies-init.txt similarity index 100% rename from template/dependencies-init.txt rename to template/.scaf/semantic-assets/dependencies-init.txt diff --git a/template/package.json.jinja b/template/.scaf/semantic-assets/package.json.jinja similarity index 100% rename from template/package.json.jinja rename to template/.scaf/semantic-assets/package.json.jinja diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index 3ffe64f..0449e12 100644 --- a/template/.scaf/starter-post-copy.py.jinja +++ b/template/.scaf/starter-post-copy.py.jinja @@ -280,6 +280,27 @@ def render_root_semantic_workflows() -> None: remove(workflow_templates) +def render_root_semantic_assets() -> None: + semantic_assets = PROJECT_ROOT / ".scaf" / "semantic-assets" + asset_files = [ + "package.json", + "dependencies-init.txt", + "dependencies-dev-init.txt", + ".releaserc.json", + "CHANGELOG.md", + ] + + for asset_file in asset_files: + source = semantic_assets / asset_file + target = PROJECT_ROOT / asset_file + if SEMANTIC_RELEASE and source.exists(): + shutil.copyfile(source, target) + else: + remove(target) + + remove(semantic_assets) + + def prune_starter_template() -> None: render_root_task_runner() render_root_semantic_workflows() @@ -353,6 +374,7 @@ def main() -> None: initialized_repo = init_git_repo() maybe_create_repo() configure_git_remote() + render_root_semantic_assets() run_template_init() prune_starter_template() remove(PROJECT_ROOT / ".scaf/starter-post-copy.py") From 4d675a0c196af249f3aa59d93ff3efb2a6596e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roch=C3=A9=20Compaan?= Date: Mon, 9 Mar 2026 13:43:35 +0200 Subject: [PATCH 22/22] chore(template): ignore node_modules in starter and nested template --- template/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 template/.gitignore diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/template/.gitignore @@ -0,0 +1 @@ +node_modules/