Skip to content

Commit aaeb378

Browse files
committed
Update Tekton task versions
1 parent 6f9cc6a commit aaeb378

1 file changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env bash
2+
set -e -u -o pipefail
3+
4+
declare -r SCRIPT_NAME=$(basename "$0")
5+
declare -r SCRIPT_DIR=$(cd $(dirname "$0") && pwd)
6+
7+
log() {
8+
local level=$1; shift
9+
echo -e "$level: $@"
10+
}
11+
12+
13+
err() {
14+
log "ERROR" "$@" >&2
15+
}
16+
17+
info() {
18+
log "INFO" "$@"
19+
}
20+
21+
die() {
22+
local code=$1; shift
23+
local msg="$@"; shift
24+
err $msg
25+
exit $code
26+
}
27+
28+
usage() {
29+
local msg="$1"
30+
cat <<-EOF
31+
Error: $msg
32+
33+
USAGE:
34+
$SCRIPT_NAME DEST_DIR
35+
36+
Example:
37+
$SCRIPT_NAME cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/stepactions
38+
EOF
39+
exit 1
40+
}
41+
42+
#declare -r CATALOG_VERSION="release-v0.7"
43+
44+
declare -r TEKTON_CATALOG="https://raw.githubusercontent.com/tektoncd/catalog"
45+
declare -A TEKTON_CATALOG_TASKS=(
46+
# Need to remove version param
47+
["git-clone"]="0.9"
48+
["kn"]="0.2"
49+
["kn-apply"]="0.2"
50+
["skopeo-copy"]="0.3"
51+
["tkn"]="0.4"
52+
# Those tasks are managed directly in the repository
53+
# ["buildah"]="0.1"
54+
# ["openshift-client"]="0.2"
55+
)
56+
declare -r TEKTON_ECOSYSTEM="https://raw.githubusercontent.com/openshift-pipelines/tektoncd-catalog"
57+
declare -A TEKTON_ECOSYSTEM_TASKS=(
58+
['task-buildah-ns']="0.8.0"
59+
['task-buildah']="0.8.0"
60+
['task-git-cli']="0.4.1"
61+
['task-git-clone']='0.4.1'
62+
['task-kn-apply']='0.3.0'
63+
['task-kn']='0.3.0'
64+
['task-maven']="0.4.0"
65+
['task-openshift-client']="0.3.0"
66+
['task-s2i-dotnet']='0.8.0'
67+
['task-s2i-go']='0.8.0'
68+
['task-s2i-java']='0.8.0'
69+
['task-s2i-nodejs']='0.8.0'
70+
['task-s2i-perl']='0.8.0'
71+
['task-s2i-php']='0.8.0'
72+
['task-s2i-python']='0.8.0'
73+
['task-s2i-ruby']='0.8.0'
74+
['task-skopeo-copy']='0.8.0'
75+
['task-tkn']='0.3.0'
76+
['task-opc']='0.3.0'
77+
)
78+
declare -A TEKTON_ECOSYSTEM_STEPACTIONS=(
79+
['stepaction-git-clone']='0.4.1'
80+
['cache-upload']='0.2.0'
81+
['cache-fetch']='0.2.0'
82+
)
83+
84+
download_task() {
85+
local task_path="$1"; shift
86+
local task_url="$1"; shift
87+
88+
info "downloading ... $t from $task_url"
89+
# validate url
90+
curl --output /dev/null --silent --head --fail "$task_url" || return 1
91+
92+
93+
cat <<-EOF > "$task_path"
94+
# auto generated by script/update-tasks.sh
95+
# DO NOT EDIT: use the script instead
96+
# source: $task_url
97+
#
98+
---
99+
$(curl -sLf "$task_url")
100+
EOF
101+
102+
# NOTE: helps when the original and the generated need to compared
103+
# curl -sLf "$task_url" -o "$task_path.orig"
104+
105+
}
106+
107+
108+
get_tasks() {
109+
local dest_dir="$1"; shift || true
110+
local catalog="$1"; shift || true
111+
local catalog_version="$1"; shift || true
112+
local type="$1"; shift || true
113+
local -n resources="$1"
114+
115+
info "Downloading resources from catalog $catalog to $dest_dir directory"
116+
117+
for t in ${!resources[@]} ; do
118+
# task filenames do not follow a naming convention,
119+
# some are taskname.yaml while others are taskname-task.yaml
120+
# so, try both before failing
121+
local task_url=""
122+
if [[ "$type" == "ecosystem_tasks" ]]; then
123+
task_url="$catalog/$catalog_version/tasks/$t/${resources[$t]}/${t}.yaml"
124+
elif [[ "$type" == 'ecosystem_stepactions' ]];then
125+
task_url="$catalog/$catalog_version/stepactions/$t/${resources[$t]}/${t}.yaml"
126+
fi
127+
128+
mkdir -p "$dest_dir/$t/"
129+
local task_path="$dest_dir/$t/$t-task.yaml"
130+
131+
download_task "$task_path" "$task_url" ||
132+
die 1 "Failed to download $t"
133+
done
134+
}
135+
136+
create_dir_or_die() {
137+
local dest_dir="$1"; shift
138+
mkdir -p "$dest_dir" || die 1 "failed to create ${dest_dir}"
139+
echo $dest_dir created
140+
}
141+
142+
main() {
143+
local type=${2:-"default"}
144+
145+
case "$type" in
146+
"ecosystem_tasks")
147+
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/tasks'}
148+
resources=TEKTON_ECOSYSTEM_TASKS
149+
branch="p"
150+
catalog="$TEKTON_ECOSYSTEM"
151+
;;
152+
"ecosystem_stepactions")
153+
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/stepactions'}
154+
resources=TEKTON_ECOSYSTEM_STEPACTIONS
155+
branch="p"
156+
catalog="$TEKTON_ECOSYSTEM"
157+
;;
158+
*)
159+
echo "Invalid type specified: $type"
160+
return 1
161+
;;
162+
esac
163+
164+
[[ -z "$dest_dir" ]] && usage "missing destination directory"
165+
shift
166+
167+
[[ ! -d "$dest_dir" ]] && create_dir_or_die "$dest_dir" || echo "$dest_dir" exists
168+
169+
get_tasks "$dest_dir" $catalog $branch $type $resources
170+
return $?
171+
}
172+
173+
main "$@"

0 commit comments

Comments
 (0)