|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The KCP Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This script ensures that the generated client code checked into git is up-to-date |
| 18 | +# with the generator. If it is not, re-generate the configuration to update it. |
| 19 | + |
| 20 | +set -o errexit |
| 21 | +set -o nounset |
| 22 | +set -o pipefail |
| 23 | + |
| 24 | +TARGET_REF=${PULL_BASE_REF:-main} |
| 25 | + |
| 26 | +find config/root-phase0 -name 'apiresourceschema-*.yaml' | while read schema |
| 27 | +do |
| 28 | + if ! git diff --exit-code ${TARGET_REF} -- ${schema} 2>&1 >/dev/null; then |
| 29 | + current_name=$(yq '.metadata.name' ${schema}) |
| 30 | + previous_name=$(git show ${TARGET_REF}:${schema} | yq '.metadata.name') |
| 31 | + |
| 32 | + if [ "${current_name}" == "${previous_name}" ]; then |
| 33 | + echo "${schema} has changed in comparison to '${TARGET_REF}', but object name is the same (${current_name} == ${previous_name})." |
| 34 | + echo "This is not valid as APIResourceSchemas are immutable." |
| 35 | + echo "Please run \`make crds\` without modifying APIResourceSchema files manually." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + fi |
| 39 | +done |
0 commit comments