only validate changed files
Some checks failed
Validate Kubernetes Manifests / kubeconform (pull_request) Failing after 1m16s
Some checks failed
Validate Kubernetes Manifests / kubeconform (pull_request) Failing after 1m16s
This commit is contained in:
@@ -29,6 +29,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Get changed files
|
||||||
|
id: changed-files
|
||||||
|
uses: tj-actions/changed-files@v47
|
||||||
|
with:
|
||||||
|
files: |
|
||||||
|
**.yml
|
||||||
|
|
||||||
- name: Create kubeconform configuration
|
- name: Create kubeconform configuration
|
||||||
run: |
|
run: |
|
||||||
cat > /tmp/kubeconform-config.yaml << 'EOF'
|
cat > /tmp/kubeconform-config.yaml << 'EOF'
|
||||||
@@ -38,9 +45,13 @@ jobs:
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
- name: Validate Manifests
|
- name: Validate Manifests
|
||||||
|
if: steps.changed-files.outputs.any_changed == 'true'
|
||||||
|
env:
|
||||||
|
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
# Define schema mappings
|
set -o pipefail
|
||||||
|
|
||||||
declare -A SCHEMA_MAP=(
|
declare -A SCHEMA_MAP=(
|
||||||
["HelmRelease"]="helm.toolkit.fluxcd.io/helmrelease_v2.json"
|
["HelmRelease"]="helm.toolkit.fluxcd.io/helmrelease_v2.json"
|
||||||
["HelmRepository"]="source.toolkit.fluxcd.io/helmrepository_v1.json"
|
["HelmRepository"]="source.toolkit.fluxcd.io/helmrepository_v1.json"
|
||||||
@@ -50,24 +61,13 @@ jobs:
|
|||||||
["ClusterPolicy"]="nvidia.com/clusterpolicy_v1.json"
|
["ClusterPolicy"]="nvidia.com/clusterpolicy_v1.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create cache directory
|
EXIT_CODE=0
|
||||||
export KUBECONFORM_CACHE_DIR="/tmp/kubeconform-cache"
|
export KUBECONFORM_CACHE_DIR="/tmp/kubeconform-cache"
|
||||||
mkdir -p "$KUBECONFORM_CACHE_DIR"
|
mkdir -p "$KUBECONFORM_CACHE_DIR"
|
||||||
|
|
||||||
# Exit code tracking
|
|
||||||
EXIT_CODE=0
|
|
||||||
|
|
||||||
# Process all YAML files
|
|
||||||
while IFS= read -r file; do
|
while IFS= read -r file; do
|
||||||
|
[ -z "$file" ] && continue
|
||||||
echo "=== Validating: $file ==="
|
echo "=== Validating: $file ==="
|
||||||
|
|
||||||
# Skip excluded paths
|
|
||||||
if [[ "$file" == *".gitea/"* ]] || [[ "$file" == *"clusters/default/system-upgrade/"* ]]; then
|
|
||||||
echo "Skipping excluded file"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect resource kind
|
|
||||||
KIND=$(yq -r '.kind // ""' "$file" 2>/dev/null || echo "")
|
KIND=$(yq -r '.kind // ""' "$file" 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then
|
if [[ -n "$KIND" && -n "${SCHEMA_MAP[$KIND]}" ]]; then
|
||||||
@@ -75,6 +75,7 @@ jobs:
|
|||||||
SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
|
SCHEMA_URL="https://raw.githubusercontent.com/datreeio/CRDs-catalog/refs/heads/main/${SCHEMA_MAP[$KIND]}"
|
||||||
|
|
||||||
if ! /kubeconform \
|
if ! /kubeconform \
|
||||||
|
-config /tmp/kubeconform-config.yaml \
|
||||||
-schema-location "$SCHEMA_URL" \
|
-schema-location "$SCHEMA_URL" \
|
||||||
-cache "$KUBECONFORM_CACHE_DIR" \
|
-cache "$KUBECONFORM_CACHE_DIR" \
|
||||||
-output json \
|
-output json \
|
||||||
@@ -84,6 +85,7 @@ jobs:
|
|||||||
else
|
else
|
||||||
echo "Validating with default schemas"
|
echo "Validating with default schemas"
|
||||||
if ! /kubeconform \
|
if ! /kubeconform \
|
||||||
|
-config /tmp/kubeconform-config.yaml \
|
||||||
-schema-location default \
|
-schema-location default \
|
||||||
-cache "$KUBECONFORM_CACHE_DIR" \
|
-cache "$KUBECONFORM_CACHE_DIR" \
|
||||||
-output json \
|
-output json \
|
||||||
@@ -93,6 +95,6 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
done < <(find . -type f \( -name "*.yml" \) -print)
|
done <<< "${ALL_CHANGED_FILES}"
|
||||||
|
|
||||||
exit $EXIT_CODE
|
exit $EXIT_CODE
|
||||||
|
|||||||
Reference in New Issue
Block a user