Skip to content

feat: deprecate hopic bilingual #28

feat: deprecate hopic bilingual

feat: deprecate hopic bilingual #28

name: Validate mandatory fields
on:
pull_request:
paths:
- 'dns-records/*.yaml'
jobs:
validate-mandatory-fields:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate mandatory fields
id: validate-mandatory-fields
run: |
yaml_files=()
error_occurred=false
required_fields=(
apiVersion
kind
metadata.name
metadata.namespace
metadata.annotations.sourceCodeRepository
metadata.labels.controlled-by
metadata.labels.project-name
metadata.labels.project-id
spec.name
spec.type
spec.ttl
spec.managedZoneRef.external
spec.rrdatas
)
# Find changed YAML files
yaml_files=($(git diff --name-only HEAD^..HEAD))
# Check if there are any YAML files to process
if [ "${#yaml_files[@]}" -eq 0 ]; then
echo "No YAML files to process after filtering. Exiting cleanly."
exit 0
fi
# Checks if file contains all mandatory fields
validate_file() {
local file="$1"
local current_field
for field in "${required_fields[@]}"; do
current_field=$(yq e ".$field // \"\"" "$file")
if [ -z "$current_field" ]; then
echo "::error file=$file::Error in file '$file': Required field '$field' is missing or an empty string."
error_occurred=true
fi
done
}
for file in "${yaml_files[@]}"; do
if [ -f "$file" ]; then
validate_file "$file"
else
echo "File $file has been deleted or is not accessible."
fi
done
# Exit with error if any validation failed
if [ "$error_occurred" = true ]; then
exit 1
fi
shell: bash