From 419c185ea6c1ba4bd067df089341b1d058f51710 Mon Sep 17 00:00:00 2001 From: Dafydd Jones Date: Thu, 18 Apr 2024 20:43:35 +0100 Subject: [PATCH] chore: initial bootstrapped template --- .copier-answers.yml | 4 ++ .github/renovate.json5 | 31 ++++++++++ .github/workflows/main.yml | 62 +++++++++++++++++++ .pre-commit-config.yaml | 20 ++++++ bin/copier | 10 +++ copier.yaml | 2 + template/.github/renovate.json5 | 31 ++++++++++ ... _copier_conf.answers_file }}.copier-jinja | 2 + test/GenerateProject/catalogue.tt | 5 ++ test/GenerateProject/options.tt | 1 + test/GenerateProject/stderr.tt | 8 +++ test/GenerateProject/stdout.tt | 2 + test/config.tt | 20 ++++++ test/options.tt | 1 + test/testsuite.tt | 1 + 15 files changed, 200 insertions(+) create mode 100644 .copier-answers.yml create mode 100644 .github/renovate.json5 create mode 100644 .github/workflows/main.yml create mode 100644 .pre-commit-config.yaml create mode 100755 bin/copier create mode 100644 copier.yaml create mode 100644 template/.github/renovate.json5 create mode 100644 template/{{ _copier_conf.answers_file }}.copier-jinja create mode 100644 test/GenerateProject/catalogue.tt create mode 100644 test/GenerateProject/options.tt create mode 100644 test/GenerateProject/stderr.tt create mode 100644 test/GenerateProject/stdout.tt create mode 100644 test/config.tt create mode 100644 test/options.tt create mode 100644 test/testsuite.tt diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 0000000..0b5dcd8 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,4 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: v2.0.5 +_src_path: gh:dafyddj/copier-bootstrap +template_name: copier-packer-build diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 0000000..a9b318a --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,31 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "enabledManagers": [ + "custom.regex", + "git-submodules", + ], + "extends": [ + "config:recommended", + ], + // `copier` template updates + // There are two conditions that we need to account for + // * a "clean" `.copier-answers.yml` file + // * update needed but not yet applied (and further updates could appear in this condition) + // `renovate` needs to be able to match both conditions for PRs to work properly + // We make a hacky use of the otherwise unused field `currentDigest` to hold the current copier template version + "customManagers": [ + { + "customType": "regex", + "fileMatch": ["^.copier-answers.yml$"], + "matchStrings": [ + "_commit: (?\\S+)\\n_src_path: gh:(?\\S+)\\n", + "_commit: (?\\S+) # __copier_update_needed (?\\S+)\\n_src_path: gh:(?\\S+)\\n", + ], + "datasourceTemplate": "github-tags", + "autoReplaceStringTemplate": "_commit: {{#if currentDigest}}{{{currentDigest}}}{{else}}{{{currentValue}}}{{/if}} # __copier_update_needed {{{newValue}}}\n_src_path: gh:{{{depName}}}\n", + }, + ], + "git-submodules": { + "enabled": true + }, +} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..0197c54 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,62 @@ +name: Test & release + +on: + pull_request: + push: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }} + +jobs: + pre-commit: + name: Run `pre-commit` + runs-on: ubuntu-latest + env: + # renovate: datasource=github-releases depName=actions/python-versions extractVersion=^(?\S+)-\d+$ + PYTHON_VERSION: 3.12.3 + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 + test: + name: Run approval tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + fetch-depth: 0 # `copier` prefers full-history clones + submodules: true + - name: Debug on runner (When re-run with "Enable debug logging" checked) + if: runner.debug + uses: mxschmitt/action-tmate@b3db6e16e597d92037c8647e54acc5d2b1b48dee # v3.18 + with: + detached: true + - name: Install test dependencies + run: | + pipx install copier + pipx install texttest + - name: Run `texttest` + run: texttest -b + results: + name: Collect results + needs: + - pre-commit + - test + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - uses: codfish/semantic-release-action@b0e57c976bf8f74b2454f59a30e4a1b5f11727b4 # v3.3.0 + with: + plugins: | + [ "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/github" + ] + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..892f563 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + - id: check-merge-conflict + args: [--assume-in-merge] + - id: check-yaml + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.2 + hooks: + - id: check-github-workflows + name: Check GitHub workflows with check-jsonschema + args: ["--verbose"] + - id: check-renovate + name: Check Renovate config with check-jsonschema + additional_dependencies: [json5==0.9.14] + args: ["--verbose"] diff --git a/bin/copier b/bin/copier new file mode 100755 index 0000000..6f29511 --- /dev/null +++ b/bin/copier @@ -0,0 +1,10 @@ +#!/bin/bash + +# Check if the copier binary exists +if ! [ -x "$(command -v copier)" ]; then + echo "Error: 'copier' binary not found or not executable" + exit 1 +fi + +# Call the copier binary with all command line arguments +copier "$@" diff --git a/copier.yaml b/copier.yaml new file mode 100644 index 0000000..823b7c8 --- /dev/null +++ b/copier.yaml @@ -0,0 +1,2 @@ +_subdirectory: template +_templates_suffix: .copier-jinja diff --git a/template/.github/renovate.json5 b/template/.github/renovate.json5 new file mode 100644 index 0000000..a9b318a --- /dev/null +++ b/template/.github/renovate.json5 @@ -0,0 +1,31 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "enabledManagers": [ + "custom.regex", + "git-submodules", + ], + "extends": [ + "config:recommended", + ], + // `copier` template updates + // There are two conditions that we need to account for + // * a "clean" `.copier-answers.yml` file + // * update needed but not yet applied (and further updates could appear in this condition) + // `renovate` needs to be able to match both conditions for PRs to work properly + // We make a hacky use of the otherwise unused field `currentDigest` to hold the current copier template version + "customManagers": [ + { + "customType": "regex", + "fileMatch": ["^.copier-answers.yml$"], + "matchStrings": [ + "_commit: (?\\S+)\\n_src_path: gh:(?\\S+)\\n", + "_commit: (?\\S+) # __copier_update_needed (?\\S+)\\n_src_path: gh:(?\\S+)\\n", + ], + "datasourceTemplate": "github-tags", + "autoReplaceStringTemplate": "_commit: {{#if currentDigest}}{{{currentDigest}}}{{else}}{{{currentValue}}}{{/if}} # __copier_update_needed {{{newValue}}}\n_src_path: gh:{{{depName}}}\n", + }, + ], + "git-submodules": { + "enabled": true + }, +} diff --git a/template/{{ _copier_conf.answers_file }}.copier-jinja b/template/{{ _copier_conf.answers_file }}.copier-jinja new file mode 100644 index 0000000..69141bb --- /dev/null +++ b/template/{{ _copier_conf.answers_file }}.copier-jinja @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +{{ _copier_answers|to_nice_yaml -}} diff --git a/test/GenerateProject/catalogue.tt b/test/GenerateProject/catalogue.tt new file mode 100644 index 0000000..b40f0db --- /dev/null +++ b/test/GenerateProject/catalogue.tt @@ -0,0 +1,5 @@ +The following new files/directories were created: + +----.copier-answers.yml +----.github +--------renovate.json5 diff --git a/test/GenerateProject/options.tt b/test/GenerateProject/options.tt new file mode 100644 index 0000000..c12a490 --- /dev/null +++ b/test/GenerateProject/options.tt @@ -0,0 +1 @@ +$TEXTTEST_ROOT/.. . diff --git a/test/GenerateProject/stderr.tt b/test/GenerateProject/stderr.tt new file mode 100644 index 0000000..0f3352e --- /dev/null +++ b/test/GenerateProject/stderr.tt @@ -0,0 +1,8 @@ +/opt/homebrew/Cellar/copier/9.2.0/libexec/lib/python3.12/site-packages/copier/vcs.py:202: DirtyLocalWarning: Dirty template changes included automatically. + warn( + +Copying from template version 0.0.0.post2.dev0+2261517 + identical . + create .copier-answers.yml + create .github + create .github/renovate.json5 diff --git a/test/GenerateProject/stdout.tt b/test/GenerateProject/stdout.tt new file mode 100644 index 0000000..139597f --- /dev/null +++ b/test/GenerateProject/stdout.tt @@ -0,0 +1,2 @@ + + diff --git a/test/config.tt b/test/config.tt new file mode 100644 index 0000000..dccb650 --- /dev/null +++ b/test/config.tt @@ -0,0 +1,20 @@ +# Full path to the System Under Test (or Java Main Class name) +executable:${TEXTTEST_ROOT}/../bin/copier + +# Naming scheme to use for files for stdin,stdout and stderr +filename_convention_scheme:standard + +# Expanded name to use for application +full_name:copier-packer-build + +create_catalogues:true + +[run_dependent_text] +stderr:Copying from template version +stderr:DirtyLocalWarning{LINES 2} +stderr:No git tags found in template; using HEAD as ref +stderr:create +stderr:conflict +stderr:identical +stderr:overwrite +stderr:skip diff --git a/test/options.tt b/test/options.tt new file mode 100644 index 0000000..5d21c55 --- /dev/null +++ b/test/options.tt @@ -0,0 +1 @@ +copy --defaults --vcs-ref=HEAD diff --git a/test/testsuite.tt b/test/testsuite.tt new file mode 100644 index 0000000..fd29e61 --- /dev/null +++ b/test/testsuite.tt @@ -0,0 +1 @@ +GenerateProject