Skip to content

Commit

Permalink
Create validate-namespace.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
tcaky committed May 15, 2024
1 parent 70b2f01 commit e5ab805
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/validate-namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Validate config-control Namespace

on:
paths:
- 'dns-records/**/*.yaml'
- 'dns-records/**/*.yml'

jobs:
validate-namespace:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Validate namespace
id: validate-namespace
run: |
files_with_namespace=()
yaml_files=()
EXPECTED_NAMESPACE='config-control'
# Find yml/yaml files that have been changed
changed_files=$(git diff --name-only HEAD^..HEAD)
echo "Changed Files"
echo "$changed_files"
if [ -n "$changed_files" ]; then
while IFS= read -r file; do
if [[ "$file" =~ \.y(a)?ml$ ]]; then
yaml_files+=("$file")
fi
done < <(echo "$changed_files")
echo -e "\nFound yaml files:"
for file in "${yaml_files[@]}"; do
echo "$file"
done
else
echo -e "\nNo YAML files were changed."
exit 0
fi
# Check if there are any YAML files to process
if [ ${#yaml_files[@]} -eq 0 ]; then
echo -e "\nNo YAML files to process after filtering. Exiting cleanly."
exit 0
fi
# Find yaml files that have .metadata.namespace defined
for file in "${yaml_files[@]}"; do
if [ -f "$file" ]; then # Ensure the file still exists in the repository
NAMESPACE=$(yq e '.metadata.namespace // ""' "$file")
if [ "$NAMESPACE" != "$EXPECTED_NAMESPACE" ]; then
echo "::error file=$FILE::Namespace is '$NAMESPACE', expected '$EXPECTED_NAMESPACE'"
exit 1
else
echo "Namespace validation passed"
fi
else
echo "File $file has been deleted or is not accessible."
fi
done
shell: bash
- name: Install yq
uses: mikefarah/yq@v4

0 comments on commit e5ab805

Please sign in to comment.