Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions lib/mixins/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <repo>/mixins/<file> 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:
Expand Down
Loading