-
Notifications
You must be signed in to change notification settings - Fork 118
/
check_tasks.sh
59 lines (58 loc) · 2.27 KB
/
check_tasks.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
#!/bin/bash
# iterate over all the task files to ensure
# - task name is appropriately prefiexed according to folder
# - folder/filename match task name
# - each task parameter has a description
exit_status=0
# shellcheck disable=SC2044
for file in $(find . -type f -name "*.yaml")
do
if [[ "$(yq r "$file" 'kind')" == "Task" ]]; then
# Only check non deprecated task
if [[ "$(yq r "$file" 'metadata.labels."tekton.dev/deprecated"')" != "true" ]]; then
# shellcheck disable=SC2001
file=$(echo "$file" | sed 's|^./||')
folder=$(dirname "$file")
# Check task only for non samples
if [[ "$folder" != *"sample"* ]]; then
if [ "$folder" == "cloudfoundry" ]; then
prefix="cf"
elif [ "$folder" == "container-registry" ]; then
prefix="icr"
elif [ "$folder" == "devops-insights" ]; then
prefix="doi"
elif [ "$folder" == "kubernetes-service" ]; then
prefix="iks"
else
prefix=$(echo "$folder" | tr -s '/' '-')
fi
fully_qualified_task_name="$(yq r "$file" 'metadata.name')"
task_name=${fully_qualified_task_name#"$prefix-"}
# Check task name
if [[ "$prefix-$task_name" != "$fully_qualified_task_name" ]]; then
echo "Task name in $file is not appropriate. it should be $prefix-$task_name and not $fully_qualified_task_name"
exit_status=1
fi
# Check file name
filename=$(basename -s .yaml "$file")
if [[ "task-$task_name" != "$filename" ]]; then
echo "File $file containing task $fully_qualified_task_name is not well-formed. $filename.yaml should be renamed to task-$task_name.yaml"
exit_status=1
fi
# Check if each Task parameters has a description
parameters=$(yq r --tojson "$file" | jq -r '.spec.params | .[] | select(has("description") | not) | .name')
# shellcheck disable=SC2236
if [[ ! -z "$parameters" ]]; then
echo "Task $fully_qualified_task_name (in $file) is missing description for parameter(s):"
for parameter in $parameters; do
echo "- $parameter"
done
exit_status=1
fi
fi
else
echo "Skipping $file as task is marked as deprecated"
fi
fi
done
exit $exit_status