diff --git a/changes/53726-gitops-template-duplicate-fleet-check b/changes/53726-gitops-template-duplicate-fleet-check new file mode 100644 index 00000000000..c9953cef372 --- /dev/null +++ b/changes/53726-gitops-template-duplicate-fleet-check @@ -0,0 +1 @@ +- Fixed the duplicate fleet name check in the GitOps `gitops.sh` that `fleetctl new` generates: it never stopped the run, because `set -e` ignores a command starting with `!`. This applies the same fix #53469 made to Fleet's own GitOps action. diff --git a/cmd/fleetctl/fleetctl/templates/new/.github/fleet-gitops/gitops.sh b/cmd/fleetctl/fleetctl/templates/new/.github/fleet-gitops/gitops.sh index 45caa6c81c1..23f469bc1b5 100755 --- a/cmd/fleetctl/fleetctl/templates/new/.github/fleet-gitops/gitops.sh +++ b/cmd/fleetctl/fleetctl/templates/new/.github/fleet-gitops/gitops.sh @@ -32,7 +32,10 @@ fi if compgen -G "$FLEET_GITOPS_DIR"/fleets/*.yml > /dev/null; then # Validate that every fleet has a unique name. # This is a limited check that assumes all per-fleet .yml files contain the phrase: `name: ` - ! perl -nle 'print $1 if /^name:\s*(.+)$/' "$FLEET_GITOPS_DIR"/fleets/*.yml | sort | uniq -d | grep . -cq + if [ -n "$(perl -nle 'print $1 if /^name:\s*(.+)$/' "$FLEET_GITOPS_DIR"/fleets/*.yml | sort | uniq -d)" ]; then + echo "Error: duplicate fleet names found" >&2 + exit 1 + fi fi args=()