diff --git a/Makefile b/Makefile index 5807017093c..c070e85f157 100644 --- a/Makefile +++ b/Makefile @@ -93,9 +93,9 @@ test-process-coverage: test-cleanup-azure-resources: # Delete the resource groups that match the pattern for rgname in `az group list --query "[*].[name]" -o table | grep '^${TEST_RESOURCE_PREFIX}' `; do \ - echo "$$rgname will be deleted"; \ - az group delete --name $$rgname --no-wait --yes; \ - done + echo "$$rgname will be deleted"; \ + az group delete --name $$rgname --no-wait --yes; \ + done # Build the docker image docker-build: @@ -144,6 +144,10 @@ delete: validate-copyright-headers: @./scripts/validate-copyright-headers.sh +# Validate cainjection files: +validate-cainjection-files: + @./scripts/validate-cainjection-files.sh + # Generate manifests for helm and package them up helm-chart-manifests: manifests mkdir charts/azure-service-operator/templates/generated diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6f9d40f2332..3e3828d6e0a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -48,6 +48,12 @@ variables: steps: - checkout: self # self represents the repo where the initial Pipelines YAML file was found lfs: "true" + + - script: | + make validate-copyright-headers + make validate-cainjection-files + displayName: 'Validate Source' + continueOnError: 'false' - task: GoTool@0 displayName: Get Go 1.13.7 @@ -89,14 +95,7 @@ steps: go mod download make install-test-dependencies workingDirectory: '$(System.DefaultWorkingDirectory)' - - - task: Bash@3 - inputs: - targetType: 'inline' - script: 'make validate-copyright-headers' - workingDirectory: '$(System.DefaultWorkingDirectory)' - displayName: 'Validate Copyright Headers' - + - script: | set -e export PATH=$PATH:$(go env GOPATH)/bin diff --git a/devops/azure-pipelines.yaml b/devops/azure-pipelines.yaml index 915f16c6374..ae7eba1b6dc 100644 --- a/devops/azure-pipelines.yaml +++ b/devops/azure-pipelines.yaml @@ -28,6 +28,12 @@ steps: - checkout: self # self represents the repo where the initial Pipelines YAML file was found lfs: "true" +- script: | + make validate-copyright-headers + make validate-cainjection-files + displayName: 'Validate Source' + continueOnError: 'false' + - script: | set -x ls -l /usr/local/go* @@ -99,12 +105,6 @@ steps: # REQUEUE_AFTER: $(REQUEUE_AFTER) # workingDirectory: '$(MODULE_PATH)' -- script: | - make validate-copyright-headers - continueOnError: 'false' - displayName: 'Validate Copyright Headers' - workingDirectory: '$(MODULE_PATH)' - - script: | set -e GO111MODULE="on" go get sigs.k8s.io/kind@v0.7.0 diff --git a/scripts/validate-cainjection-files.sh b/scripts/validate-cainjection-files.sh new file mode 100755 index 00000000000..6611d7d9cd6 --- /dev/null +++ b/scripts/validate-cainjection-files.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +invalid_files=$(grep -L "cert-manager.io" ./config/crd/patches/cainjection*.yaml) + +# using a subshell to not modify the IFS variable that determines how the expression "${arr[*]}" is output +# this workaround allows us to reject an array containing empty elements +(IFS='' ; [[ -n "${invalid_files[*]}" ]] ); is_empty=$? + +# fail validation if the array is not empty +if [[ $is_empty -eq 0 ]]; then + echo "Validation check failed for the following files:" + for file in $invalid_files; do + echo " $file" + done + echo "Run the following command to fix the files:" + echo " sed -i '' 's/certmanager.k8s.io/cert-manager.io/' ./config/crd/patches/cainjection*.yaml" + exit 1 +fi