Skip to content

Commit

Permalink
ci: validate-crd
Browse files Browse the repository at this point in the history
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 it will fail the ci

Signed-off-by: sadath-12 <sadathsadu2002@gmail.com>
  • Loading branch information
sadath-12 committed Jan 8, 2024
1 parent a250225 commit d89d947
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/validate-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Check CRD Version Update

on:
pull_request:
paths:
- 'pkg/k8s/apis/cilium.io/client/crds/v1alpha1/*.yaml'

jobs:
check-version:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}

- name: Get all changed files
id: changed-files
uses: jitterbit/get-changed-files@v1

- name: Check for CRD changes and version update
run: |
crd_changed=0
version_changed=0
for changed_file in ${{ steps.changed-files.outputs.all }}; do
if echo "$changed_file" | grep -q 'pkg/k8s/apis/cilium.io/client/crds/v1alpha1/'; then
crd_changed=1
fi
if echo "$changed_file" | grep -q 'pkg/k8s/apis/cilium.io/v1alpha1/register.go'; then
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=$(grep 'CustomResourceDefinitionSchemaVersion' $changed_file | awk -F'"' '{print $2}')
echo "old_version=$old_version"
echo "new_version=$new_version"
if [ "$old_version" != "$new_version" ]; then
version_changed=1
fi
fi
done
if [ "$crd_changed" -eq 1 ] && [ "$version_changed" -eq 0 ]; then
echo "CRD changed but version not updated"
exit 1
fi
if [ "$crd_changed" -eq 0 ] && [ "$version_changed" -eq 1 ]; then
echo "Version updated but CRD not changed"
exit 1
fi
echo "crd_changed=$crd_changed"
echo "version_changed=$version_changed"

0 comments on commit d89d947

Please sign in to comment.