-
Notifications
You must be signed in to change notification settings - Fork 83
/
operator_code_check.sh
82 lines (70 loc) · 3.36 KB
/
operator_code_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
#
# Copyright (c) 2012-2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
set -e
# PR_FILES_CHANGED store all Modified/Created files in Pull Request.
export PR_FILES_CHANGED=$(git --no-pager diff --name-only HEAD $(git merge-base HEAD master))
# transform_files function transform PR_FILES_CHANGED into a new array => FILES_CHANGED_ARRAY.
function transform_files() {
for files in ${PR_FILES_CHANGED}
do
FILES_CHANGED_ARRAY+=($files)
done
}
# check_che_types function check first if pkg/apis/org/v1/che_types.go file suffer modifications and
# in case of modification should exist also modifications in deploy/crds/* folder.
function check_che_types() {
# CHE_TYPES_FILE make reference to generated code by operator-sdk.
local CHE_TYPES_FILE='pkg/apis/org/v1/che_types.go'
# Export variables for cr/crds files.
local CR_CRD_FOLDER="deploy/crds/"
local CR_CRD_REGEX="\S*org_v1_che_crd.yaml"
if [[ " ${FILES_CHANGED_ARRAY[@]} " =~ " ${CHE_TYPES_FILE} " ]]; then
echo "[INFO] File ${CHE_TYPES_FILE} suffer modifications in PR. Checking if exist modifications for cr/crd files."
# The script should fail if deploy/crds folder didn't suffer any modification.
if [[ " ${FILES_CHANGED_ARRAY[@]} " =~ $CR_CRD_REGEX ]]; then
echo "[INFO] CR/CRD file modified: ${BASH_REMATCH}"
else
echo "[ERROR] Detected modification in ${CHE_TYPES_FILE} file, but cr/crd files didn't suffer any modification."
exit 1
fi
else
echo "[INFO] ${CHE_TYPES_FILE} didn't have any modification."
fi
}
#check_deploy_folder check first if files under deploy/* folder have modifications and in case of modification
# check if exist nightly files for kubernetes and openshift platform.
function check_deploy_folder() {
# Define deploy folder and regexp to search all under deploy/*
local CR_CRD_FOLDER="deploy/"
local CR_CRD_REGEX="\b$CR_CRD_FOLDER.*?\b"
# Define olm-catalog folder and regexp to check if exist nightly files for kubernetes
local OLM_KUBERNETES='olm/eclipse-che-preview-kubernetes/deploy/olm-catalog/eclipse-che-preview-kubernetes/'
local OLM_K8S="\b$OLM_KUBERNETES.*?\b"
# Define olm-catalog folder and regexp to check if exist nightly files for openshift
local OLM_OPENSHIFT='olm/eclipse-che-preview-openshift/deploy/olm-catalog/eclipse-che-preview-openshift/'
local OLM_OCP="\b$OLM_OPENSHIFT.*?\b"
# Checking if exist modifications in deploy folder
if [[ " ${FILES_CHANGED_ARRAY[@]} " =~ $CR_CRD_REGEX ]]; then
echo "[INFO] Deploy Folder suffer modifications"
if [[ " ${FILES_CHANGED_ARRAY[@]} " =~ $OLM_K8S && " ${FILES_CHANGED_ARRAY[@]} " =~ $OLM_OCP ]]; then
echo "[INFO] Nightly files for kubernetes and openshift platform was created."
else
echo "[ERROR] Nightly files for kubernetes and openshift platform not created."
exit 1
fi
else
echo "[INFO] ${CR_CRD_FOLDER} didn't have any modification...Skipping verification for nightly files creation."
fi
}
transform_files
check_che_types
check_deploy_folder