Skip to content

Merge pull request #4 from fluxcd/update-operator-0.45.1 #2

Merge pull request #4 from fluxcd/update-operator-0.45.1

Merge pull request #4 from fluxcd/update-operator-0.45.1 #2

name: validate-catalog
on:
push:
branches:
- main
pull_request:
paths:
- 'catalog.yaml'
- 'plugins/*.yaml'
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Validate catalog
run: |
failed=0
# Validate catalog apiVersion and kind
api=$(yq '.apiVersion' catalog.yaml)
kind=$(yq '.kind' catalog.yaml)
if [ "$api" != "cli.fluxcd.io/v1beta1" ]; then
echo "ERROR: catalog.yaml has invalid apiVersion: $api"
failed=1
fi
if [ "$kind" != "PluginCatalog" ]; then
echo "ERROR: catalog.yaml has invalid kind: $kind"
failed=1
fi
# Every plugin file must have a corresponding catalog entry
for file in plugins/*.yaml; do
name=$(basename "$file" .yaml)
# Validate plugin apiVersion and kind
papi=$(yq '.apiVersion' "$file")
pkind=$(yq '.kind' "$file")
if [ "$papi" != "cli.fluxcd.io/v1beta1" ]; then
echo "ERROR: $file has invalid apiVersion: $papi"
failed=1
fi
if [ "$pkind" != "Plugin" ]; then
echo "ERROR: $file has invalid kind: $pkind"
failed=1
fi
entry=$(yq ".plugins[] | select(.name == \"$name\")" catalog.yaml)
if [ -z "$entry" ]; then
echo "ERROR: plugin '$name' not found in catalog.yaml"
failed=1
fi
done
# Every catalog entry must have a corresponding plugin file
count=$(yq '.plugins | length' catalog.yaml)
for ((i=0; i<count; i++)); do
name=$(yq ".plugins[$i].name" catalog.yaml)
if [ ! -f "plugins/${name}.yaml" ]; then
echo "ERROR: catalog entry '$name' has no matching plugins/${name}.yaml"
failed=1
fi
# Required catalog fields
for field in description homepage source license; do
val=$(yq ".plugins[$i].$field" catalog.yaml)
if [ "$val" = "null" ] || [ -z "$val" ]; then
echo "ERROR: catalog entry '$name' missing required field '$field'"
failed=1
fi
done
# Name must not collide with builtins
for reserved in bootstrap build check completion create debug delete diff envsubst events export get help install list logs migrate plugin pull push reconcile resume stats suspend tag trace tree uninstall version; do
if [ "$name" = "$reserved" ]; then
echo "ERROR: catalog entry '$name' collides with built-in command"
failed=1
fi
done
done
if [ "$failed" -ne 0 ]; then
exit 1
fi
echo "Catalog validation passed"