diff --git a/lib/mixins/Taskfile.yml b/lib/mixins/Taskfile.yml index feaae2b..b060bf4 100644 --- a/lib/mixins/Taskfile.yml +++ b/lib/mixins/Taskfile.yml @@ -2,21 +2,39 @@ version: "3" tasks: update-all: - desc: "Update a mixin across the components. Example: `task mixins:update-all -- context.tf`." + # Updates (by overwriting) every existing copy of the named mixin found + # recursively under the user's current directory with the current + # /mixins/ template. + # + # Directories opt in to a mixin by having a copy of it on disk; this task only + # touches files that already exist. It does NOT add the mixin to directories + # that don't already have it — adopt a mixin by copying it in, as it's an explicit choice. + # + # This intentionally searches the whole working directory so a single run + # keeps the mixin in sync across every consumer in the repo. + # + # `.terraform/`, `.terragrunt-cache/`, and the source `./mixins/` directory + # are pruned so we don't overwrite the mixin inside vendored modules. + desc: "Update (by overwriting) every existing copy of a mixin found recursively under the current directory with the current template. Picks up every consumer in the subtree. Does not add the mixin to directories that don't already have it. Example: `task mixins:update-all -- context.tf`." + dir: "{{.USER_WORKING_DIR}}" + vars: + REPO_ROOT: + sh: git rev-parse --show-toplevel + MIXIN_SRC: "{{.REPO_ROOT}}/mixins/{{.CLI_ARGS}}" preconditions: - - sh: test -f ./mixins/{{.CLI_ARGS}} - msg: "File does not exist: ./mixins/{{.CLI_ARGS}}" - - sh: test -d ./components && [ "$(ls -A ./components)" ] - msg: ./components/ directory is empty or does not exist. + - sh: test -f {{.MIXIN_SRC}} + msg: "File does not exist: {{.MIXIN_SRC}}" sources: - - ./mixins/{{.CLI_ARGS}} - generates: - - ./components/*/{{.CLI_ARGS}} + - "{{.MIXIN_SRC}}" cmds: - cmd: | - for comp in ./components/*; do - cp -v ./mixins/{{.CLI_ARGS}} $comp/{{.CLI_ARGS}} - done; + find . \ + \( -type d \( -name .terraform -o -name .terragrunt-cache \) \ + -o -path ./mixins \) -prune \ + -o -type f -name {{.CLI_ARGS}} -print \ + | while IFS= read -r dest; do + cp -v {{.MIXIN_SRC}} "$dest" + done silent: true pull-sops: