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

chore: refactor and improve badge verification task #249

Merged
merged 12 commits into from
Sep 26, 2024
30 changes: 17 additions & 13 deletions tasks/badge.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/defenseunicorns/uds-cli/main/tasks.schema.json

variables:
- name: CHART_PATH
description: Relative path to the directory with the uds-config chart
Expand All @@ -8,6 +10,9 @@ variables:
- name: COMMON_ZARF
description: Whether or not there is a common zarf.yaml file
default: "true"
- name: PACKAGE_DIR
description: Base directory where packages are located, relative to the root of the repository
default: ./
justinthelaw marked this conversation as resolved.
Show resolved Hide resolved

tasks:
- name: verify-badge
Expand All @@ -20,7 +25,6 @@ tasks:
# Functions

WARNINGS=0

ERRORS=0

gh_notice() {
Expand Down Expand Up @@ -65,13 +69,14 @@ tasks:
gh_group "📃 Setup"

# Default values for vars, maru-runner issue workaround

CHART_PATH=${CHART_PATH:-chart/}
gh_notice " ℹ️ Chart Path: $CHART_PATH"
GROUP_NAME=${GROUP_NAME:-package}
gh_notice " ℹ️ Group Name: $GROUP_NAME"
COMMON_ZARF=${COMMON_ZARF:-true}
gh_notice " ℹ️ Common Zarf: $COMMON_ZARF"
PACKAGE_DIR=${PACKAGE_DIR:-"./"}
justinthelaw marked this conversation as resolved.
Show resolved Hide resolved
gh_notice " ℹ️ Package Directory: $PACKAGE_DIR"

# Cover when GOBIN isn't set
export GOBIN=/tmp/gobin
Expand All @@ -84,10 +89,10 @@ tasks:
fi

if [[ "${COMMON_ZARF}" == "true" ]]; then
NAMESPACE=$(yq '.components[].charts[].namespace' common/zarf.yaml | uniq)
NAMESPACE=$(uds zarf tools yq '.components[].charts[].namespace' "${PACKAGE_DIR}common/zarf.yaml" | uniq)
justinthelaw marked this conversation as resolved.
Show resolved Hide resolved
else
gh_warning " ⚠️ There is no common zarf.yaml file"
NAMESPACE=$(yq '.components[].charts[].namespace' zarf.yaml | uniq)
NAMESPACE=$(uds zarf tools yq '.components[].charts[].namespace' "${PACKAGE_DIR}zarf.yaml" | uniq)
fi
gh_notice " ℹ️ Namespace: $NAMESPACE"

Expand All @@ -105,7 +110,7 @@ tasks:

gh_notice " ℹ️ Validating uds-config chart..."
printf "\033[A"
if ${GOBIN}/kubectl-validate <(helm template chart ${CHART_PATH} | grep -v '^ *#' | perl -p0e 's/---[\s---]*---/---/sg') &> /tmp/validate-output; then
if ${GOBIN}/kubectl-validate <(helm template "${PACKAGE_DIR}${CHART_PATH}" | grep -v '^ *#' | perl -p0e 's/---[\s---]*---/---/sg') &> /tmp/validate-output; then
gh_notice " ✅ uds-config chart is valid"
else
gh_error " ❌ uds-config chart is invalid"
Expand Down Expand Up @@ -136,7 +141,6 @@ tasks:
## Must deploy and operate successfully with Istio injection enabled in the namespace.

POD_COUNT=$(kubectl get pods -n "${NAMESPACE}" --no-headers | wc -l)

POD_SIDECAR_COUNT=$(kubectl get pods -n "${NAMESPACE}" -o json | jq '.items[].spec.containers[] | select(.name=="istio-proxy") | length' | wc -l)

if [ "$POD_COUNT" -ne "$POD_SIDECAR_COUNT" ]; then
Expand Down Expand Up @@ -305,15 +309,15 @@ tasks:
## Should expose all configuration (uds.dev CRs, additional Secrets/ConfigMaps, etc) through a Helm chart (ideally in a chart or charts directory).

if [ "${COMMON_ZARF}" == "true" ]; then
COMMON_ZARF_MANIFEST_COUNT=$(cat common/zarf.yaml | yq '.components[] | select(.manifests != null) | length' | wc -l)
COMMON_ZARF_MANIFEST_COUNT=$(cat "${PACKAGE_DIR}common/zarf.yaml" | uds zarf tools yq '.components[] | select(.manifests != null) | length' | wc -l)
if [ "$COMMON_ZARF_MANIFEST_COUNT" -gt 0 ]; then
gh_error " ❌ Manifests present in common/zarf.yaml"
else
gh_notice " ✅ No manifests present in common/zarf.yaml"
fi
fi

MAIN_ZARF_MANIFEST_COUNT=$(cat zarf.yaml | yq '.components[] | select(.manifests != null) | length' | wc -l)
MAIN_ZARF_MANIFEST_COUNT=$(cat "${PACKAGE_DIR}zarf.yaml" | uds zarf tools yq '.components[] | select(.manifests != null) | length' | wc -l)
if [ "$MAIN_ZARF_MANIFEST_COUNT" -gt 0 ]; then
gh_error " ❌ Manifests present in zarf.yaml"
else
Expand All @@ -322,7 +326,7 @@ tasks:

## Should implement or allow for multiple flavors (ideally with common definitions in a common directory)

ZARF_COMPONENTS_FLAVOR_COUNT=$(cat zarf.yaml | yq '.components[] | select(.only.flavor != null) | length' | wc -l)
ZARF_COMPONENTS_FLAVOR_COUNT=$(cat "${PACKAGE_DIR}zarf.yaml" | uds zarf tools yq '.components[] | select(.only.flavor != null) | length' | wc -l)
if [ "$ZARF_COMPONENTS_FLAVOR_COUNT" -eq 0 ]; then
gh_error " ❌ No flavors defined in zarf.yaml"
else
Expand All @@ -335,8 +339,8 @@ tasks:

## Must implement Journey Testing to cover the basic user flows and features of the application, especially where an application interacts with an external service / interface.

if [ -d "tests" ]; then
if [ "$(ls -A tests)" ]; then
if [ -d "${PACKAGE_DIR}tests" ]; then
if [ "$(ls -A ${PACKAGE_DIR}tests)" ]; then
gh_notice " ✅ Tests folder exists and has files"
else
gh_error " ❌ Tests folder exists but is empty"
Expand All @@ -351,8 +355,8 @@ tasks:

# Must be consistently versioned across flavors - this can take many forms but flavors should differ in image bases/builds not application versions.

ZARF_PKG_VERSION=$(yq '.metadata.version' zarf.yaml | cut -d '-' -f1)
IMAGE_WITH_ZARF_VERSION_COUNT=$(cat zarf.yaml | yq '.components[].images' | grep -o "${ZARF_PKG_VERSION}" | wc -l)
ZARF_PKG_VERSION=$(uds zarf tools yq '.metadata.version' "${PACKAGE_DIR}zarf.yaml" | cut -d '-' -f1)
IMAGE_WITH_ZARF_VERSION_COUNT=$(cat "${PACKAGE_DIR}zarf.yaml" | uds zarf tools yq '.components[].images' | grep -o "${ZARF_PKG_VERSION}" | wc -l)

if [ "$IMAGE_WITH_ZARF_VERSION_COUNT" -ge "$ZARF_COMPONENTS_FLAVOR_COUNT" ]; then
gh_notice " ✅ Version is consistent across flavors and package"
Expand Down
Loading