diff --git a/.github/workflows/template-render-tests.yaml b/.github/workflows/template-render-tests.yaml index 402c2c6..d90d7bd 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: "lts/*" + - name: Install copier run: pip install copier diff --git a/Makefile b/Makefile index 9eeabce..59292de 100644 --- a/Makefile +++ b/Makefile @@ -18,13 +18,22 @@ 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"; \ + 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/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"; \ + 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"; \ @@ -41,6 +50,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"; \ + (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 \ @@ -49,6 +59,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" @@ -66,13 +77,22 @@ 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"; \ + 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/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"; \ + 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"; \ @@ -86,6 +106,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"; \ + (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 \ @@ -94,6 +115,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/.github/workflows/template-correctness.yaml b/template/.github/workflows/template-correctness.yaml index f4aa1eb..c204c8c 100644 --- a/template/.github/workflows/template-correctness.yaml +++ b/template/.github/workflows/template-correctness.yaml @@ -18,28 +18,13 @@ jobs: with: python-version: '3.11' + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + - 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: bash ./scripts/test-template-render.sh 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/ 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/.scaf/semantic-assets/.releaserc.json.jinja b/template/.scaf/semantic-assets/.releaserc.json.jinja new file mode 100644 index 0000000..9f42172 --- /dev/null +++ b/template/.scaf/semantic-assets/.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/semantic-assets/CHANGELOG.md b/template/.scaf/semantic-assets/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/template/.scaf/semantic-assets/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/template/.scaf/semantic-assets/dependencies-dev-init.txt.jinja b/template/.scaf/semantic-assets/dependencies-dev-init.txt.jinja new file mode 100644 index 0000000..a59ed91 --- /dev/null +++ b/template/.scaf/semantic-assets/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/.scaf/semantic-assets/dependencies-init.txt b/template/.scaf/semantic-assets/dependencies-init.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/.scaf/semantic-assets/package.json.jinja b/template/.scaf/semantic-assets/package.json.jinja new file mode 100644 index 0000000..9f399b7 --- /dev/null +++ b/template/.scaf/semantic-assets/package.json.jinja @@ -0,0 +1,5 @@ +{ + "name": "{{ copier__project_dash }}", + "version": "{{ copier__version }}", + "private": true +} diff --git a/template/.scaf/starter-post-copy.py.jinja b/template/.scaf/starter-post-copy.py.jinja index e7096c7..0449e12 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 @@ -194,19 +194,19 @@ 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") 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: @@ -238,7 +238,73 @@ 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 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 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() + if TASK_RUNNER != "make": remove(TEMPLATE_ROOT / "Makefile") if TASK_RUNNER != "task": @@ -252,6 +318,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") @@ -303,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") 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/.scaf/workflows/semantic-pull-request.yaml b/template/.scaf/workflows/semantic-pull-request.yaml new file mode 100644 index 0000000..817c466 --- /dev/null +++ b/template/.scaf/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/.scaf/workflows/semantic-release.yaml.jinja b/template/.scaf/workflows/semantic-release.yaml.jinja new file mode 100644 index 0000000..fa82567 --- /dev/null +++ b/template/.scaf/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: "lts/*" + + - 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/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/README.md.jinja b/template/README.md.jinja index fe1ab7f..b23c307 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -24,4 +24,16 @@ 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 +{% 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..79fdc06 --- /dev/null +++ b/template/scripts/test-template-render.sh.jinja @@ -0,0 +1,88 @@ +#!/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__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" + -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/LICENSE" +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 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 c40151d..0f75bb5 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: "lts/*" + - name: Install copier run: pip install copier @@ -30,6 +35,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..49be435 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 %} @@ -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 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