From ea0b42e7eb5b32cc2463f06b89af2d6bd883706e Mon Sep 17 00:00:00 2001 From: sadath-12 Date: Thu, 28 Dec 2023 14:42:36 +0530 Subject: [PATCH] CI: validate-crd If there is a change in the crd yaml files and if CustomResourceDefinitionSchemaVersion value is not updated accordingly in pkg/k8s/apis/cilium.io/v1alpha1/register.go or vice-versa . The CI will fail Signed-off-by: sadath-12 --- .github/workflows/validate-crd.yaml | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/validate-crd.yaml diff --git a/.github/workflows/validate-crd.yaml b/.github/workflows/validate-crd.yaml new file mode 100644 index 00000000000..9fa65ec97d1 --- /dev/null +++ b/.github/workflows/validate-crd.yaml @@ -0,0 +1,45 @@ +name: Check CRD version update + +on: + pull_request: + paths: + - 'pkg/k8s/apis/cilium.io/client/crds/v1alpha1/*.yaml' + - 'pkg/k8s/apis/cilium.io/v1alpha1/register.go' + +jobs: + check-version: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: Check for CRD changes and version update + run: | + crd_changed=0 + version_changed=0 + + # Check for CRD changes + crd_changes=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} -- pkg/k8s/apis/cilium.io/client/crds/v1alpha1/*.yaml) + if [ -n "$crd_changes" ]; then + crd_changed=1 + fi + + # Check for version variable changes + + old_version=$(git show ${{ github.event.pull_request.base.sha }}:pkg/k8s/apis/cilium.io/v1alpha1/register.go | grep 'CustomResourceDefinitionSchemaVersion' | awk -F'"' '{print $2}') + new_version=$(git show HEAD:pkg/k8s/apis/cilium.io/v1alpha1/register.go | grep 'CustomResourceDefinitionSchemaVersion' | awk -F'"' '{print $2}') + + echo "old_version=$old_version" + echo "new_version=$new_version" + + if [ "$old_version" != "$new_version" ]; then + version_changed=1 + fi + + if [ "$crd_changed" -eq 1 ] && [ "$version_changed" -eq 0 ]; then + echo "Changes to the files pkg/k8s/apis/cilium.io/client/crds/v1alpha1/*.yaml requires CustomResourceDefinitionSchemaVersion to be updated in pkg/k8s/apis/cilium.io/v1alpha1/register.go" + exit 1 + fi + + if [ "$crd_changed" -eq 0 ] && [ "$version_changed" -eq 1 ]; then + echo "CustomResourceDefinitionSchemaVersion in pkg/k8s/apis/cilium.io/v1alpha1/register.go to be updated only in case of modifying the files pkg/k8s/apis/cilium.io/client/crds/v1alpha1/*.yaml" + exit 1 + fi \ No newline at end of file