forked from operator-framework/community-operators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators-env
executable file
·52 lines (46 loc) · 1.66 KB
/
operators-env
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
#!/usr/bin/env bash
set -e
# Exports a variable containing a space-delimited list of each operator
# with changes in a PR and the latest CSV version for that operator in the form:
# "xxxxx-operators/operator1:v0.0.1 xxxxx-operators/operator2:v0.0.1"
unset OP_PATH
unset OP_VER
declare -A OP_TYPES
OP_TYPES=(
["upstream"]="upstream-community-operators"
["openshift"]="community-operators"
)
DIR="$(cd "$(dirname ${BASH_SOURCE[0]})" && pwd)"
for f in "$(cd "$(dirname ${BASH_SOURCE[0]})/.." && pwd)"/lib/*; do
. "$f"
done
# Remove duplicates.
declare -A SEEN
for op_distro in "${!OP_TYPES[@]}"; do
OP_TYPE_VAR="OPERATORS_${op_distro^^}"
declare $OP_TYPE_VAR=""
for op_type in ${OP_TYPES[$op_distro]}; do
for file in $(git diff master --name-only 2>&1); do
# Run on operator packages with file deletions but still exist.
if [[ ! -e "$file" && ! -d "$(dirname "$file")" ]]; then
continue
fi
if echo "$file" | grep -q "^$op_type"; then
OP_PATH="$(echo "$file" | awk -F'/' '{ print $1"/"$2 }')"
if [[ -n "${SEEN[$OP_PATH]}" ]]; then
continue
fi
SEEN[$OP_PATH]="seen"
PKG_FILE="$(find "$OP_PATH" -name "*.package.yaml" -print -quit)"
# Get latest CSV version for the changed operator.
OP_VER="$(yq r --tojson "$PKG_FILE" "channels" \
| jq ".[] | .currentCSV" | sort -V | tail -1 \
| sed -E "s,"[a-zA-Z0-9\-]+\.?v?${SEMVER_REGEX}",\1,")"
declare $OP_TYPE_VAR="${!OP_TYPE_VAR}${!OP_TYPE_VAR:+" "}${OP_PATH}:${OP_VER}"
fi
done
done
echo "export OP_PATH=$OP_PATH"
echo "export OP_VER=$OP_VER"
echo "export $OP_TYPE_VAR=\"${!OP_TYPE_VAR}\";"
done