blob: 2a33b335acd7db9c5285ce9de74cac3abc138a17 [file] [log] [blame]
#!/usr/bin/env bash
set -o errexit
set -o pipefail
# Updates generated configs if source configs have been modified.
# Assume directory layout as created by infra manifest, and CWD is inside a
# config dir, like fuchsia-infra/config.
LUCICFG="../../fuchsia-infra/prebuilt/tools/lucicfg"
if [[ ! -x "${LUCICFG}" ]]; then
echo "Expected the following path to be an executable file, but it's not: ${LUCICFG}"
exit 1
fi
# FILES is an array where each element is a file path.
# We only handle added or modified files, hence the --diff-filter.
# https://git-scm.com/docs/git-diff#git-diff---diff-filterACDMRTUXB82308203
mapfile -t FILES < <(git diff --cached --name-only --diff-filter=AM)
SHOULD_GENERATE=false
for FILE in "${FILES[@]}"; do
if [[ "${FILE}" == *.star ]]; then
SHOULD_GENERATE=true
fi
done
if [[ "${SHOULD_GENERATE}" == true ]]; then
for TOP_LEVEL_STARLARK in $(ls *.star); do
"${LUCICFG}" generate "${TOP_LEVEL_STARLARK}"
done
git add generated/*.cfg
fi