Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compare changes in current with master branch to get selectors #3826

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ HELMFILE_TEMPLATE_FLAGS ?=
# HELMFILE_USE_SELECTORS = true
HELMFILE_USE_SELECTORS ?= false
CLEAN_OUTPUT_DIR ?= $(if $(findstring true,$(HELMFILE_USE_SELECTORS)),,$(OUTPUT_DIR)/*/*/)
HELMFILE_GLOBAL_FLAGS += $(if $(findstring true,$(HELMFILE_USE_SELECTORS)),$(shell versionStream/src/get-selectors-and-clean.sh $(OUTPUT_DIR)),)
HELMFILE_GLOBAL_FLAGS += $(if $(findstring true,$(HELMFILE_USE_SELECTORS)),$(shell versionStream/src/get-selectors-and-clean.sh $(OUTPUT_DIR)) --allow-no-matching-release,)

.PHONY: clean
clean:
Expand Down
29 changes: 14 additions & 15 deletions src/get-selectors-and-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
OUTPUT_DIR=$1

SELECTOR=""
if ! git log -m -1 --name-only --pretty=format: | grep -qv "^helmfiles/"; then
changedNamespaces=$(git log -m -1 --name-only --pretty=format: | grep "^helmfiles/" | cut -d "/" -f 2 | sort -u)
if echo "$changedNamespaces" | grep -q ^jx$; then
>&2 echo jx namespace changed, no selectors added
else
for namespace in ${changedNamespaces}; do
SELECTOR="${SELECTOR} --selector namespace=${namespace}"
rm -rf ${OUTPUT_DIR}/cluster/namespaces/${namespace}.yaml
rm -rf ${OUTPUT_DIR}/cluster/resources/${namespace}
rm -rf ${OUTPUT_DIR}/customresourcedefinitions/${namespace}
rm -rf ${OUTPUT_DIR}/namespaces/${namespace}
done
>&2 echo helmfile with selector ${SELECTOR}
fi
defaultBranch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')

if git log -m HEAD ^"$defaultBranch" --name-only --pretty=format: | grep -q "^helmfiles/"; then
changedNamespaces=$(git log -m HEAD ^"$defaultBranch" --name-only --pretty=format: | grep "^helmfiles/" | cut -d "/" -f 2 | sort -u)
for namespace in ${changedNamespaces}; do
SELECTOR="${SELECTOR} --selector namespace=${namespace}"
rm -rf ${OUTPUT_DIR}/cluster/namespaces/${namespace}.yaml
rm -rf ${OUTPUT_DIR}/cluster/resources/${namespace}
rm -rf ${OUTPUT_DIR}/customresourcedefinitions/${namespace}
rm -rf ${OUTPUT_DIR}/namespaces/${namespace}
done
>&2 echo helmfile with selector ${SELECTOR}
fi

if [ -z "${SELECTOR}" ]; then
>&2 echo helmfile without selector
rm -rf ${OUTPUT_DIR}/*/*/
jx gitops repository create >&2
fi

jx gitops repository create >&2

echo ${SELECTOR}