Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/openshift/fetch-tektoncd-catalog-tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ declare -A TEKTON_ECOSYSTEM_TASKS=(
['task-git-clone']='0.4.1'
['task-kn-apply']='0.3.0'
['task-kn']='0.3.0'
['task-maven']="0.4.0"
['task-maven']='0.4.1'
['task-openshift-client']="0.3.0"
['task-s2i-dotnet']='0.8.0'
['task-s2i-go']='0.8.0'
Expand Down
173 changes: 173 additions & 0 deletions hack/openshift/fetch-tektoncd-catalog-tasks.sh.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#!/usr/bin/env bash
set -e -u -o pipefail

declare -r SCRIPT_NAME=$(basename "$0")
declare -r SCRIPT_DIR=$(cd $(dirname "$0") && pwd)

log() {
local level=$1; shift
echo -e "$level: $@"
}


err() {
log "ERROR" "$@" >&2
}

info() {
log "INFO" "$@"
}

die() {
local code=$1; shift
local msg="$@"; shift
err $msg
exit $code
}

usage() {
local msg="$1"
cat <<-EOF
Error: $msg

USAGE:
$SCRIPT_NAME DEST_DIR

Example:
$SCRIPT_NAME cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/stepactions
EOF
exit 1
}

#declare -r CATALOG_VERSION="release-v0.7"

declare -r TEKTON_CATALOG="https://raw.githubusercontent.com/tektoncd/catalog"
declare -A TEKTON_CATALOG_TASKS=(
# Need to remove version param
["git-clone"]="0.9"
["kn"]="0.2"
["kn-apply"]="0.2"
["skopeo-copy"]="0.3"
["tkn"]="0.4"
# Those tasks are managed directly in the repository
# ["buildah"]="0.1"
# ["openshift-client"]="0.2"
)
declare -r TEKTON_ECOSYSTEM="https://raw.githubusercontent.com/openshift-pipelines/tektoncd-catalog"
declare -A TEKTON_ECOSYSTEM_TASKS=(
['task-buildah-ns']="0.8.0"
['task-buildah']="0.8.0"
['task-git-cli']="0.4.1"
['task-git-clone']='0.4.1'
['task-kn-apply']='0.3.0'
['task-kn']='0.3.0'
['task-maven']="0.4.0"
['task-openshift-client']="0.3.0"
['task-s2i-dotnet']='0.8.0'
['task-s2i-go']='0.8.0'
['task-s2i-java']='0.8.0'
['task-s2i-nodejs']='0.8.0'
['task-s2i-perl']='0.8.0'
['task-s2i-php']='0.8.0'
['task-s2i-python']='0.8.0'
['task-s2i-ruby']='0.8.0'
['task-skopeo-copy']='0.8.0'
['task-tkn']='0.3.0'
['task-opc']='0.3.0'
)
declare -A TEKTON_ECOSYSTEM_STEPACTIONS=(
['stepaction-git-clone']='0.4.1'
['cache-upload']='0.2.0'
['cache-fetch']='0.2.0'
)

download_task() {
local task_path="$1"; shift
local task_url="$1"; shift

info "downloading ... $t from $task_url"
# validate url
curl --output /dev/null --silent --head --fail "$task_url" || return 1


cat <<-EOF > "$task_path"
# auto generated by script/update-tasks.sh
# DO NOT EDIT: use the script instead
# source: $task_url
#
---
$(curl -sLf "$task_url")
EOF

# NOTE: helps when the original and the generated need to compared
# curl -sLf "$task_url" -o "$task_path.orig"

}


get_tasks() {
local dest_dir="$1"; shift || true
local catalog="$1"; shift || true
local catalog_version="$1"; shift || true
local type="$1"; shift || true
local -n resources="$1"

info "Downloading resources from catalog $catalog to $dest_dir directory"

for t in ${!resources[@]} ; do
# task filenames do not follow a naming convention,
# some are taskname.yaml while others are taskname-task.yaml
# so, try both before failing
local task_url=""
if [[ "$type" == "ecosystem_tasks" ]]; then
task_url="$catalog/$catalog_version/tasks/$t/${resources[$t]}/${t}.yaml"
elif [[ "$type" == 'ecosystem_stepactions' ]];then
task_url="$catalog/$catalog_version/stepactions/$t/${resources[$t]}/${t}.yaml"
fi

mkdir -p "$dest_dir/$t/"
local task_path="$dest_dir/$t/$t-task.yaml"

download_task "$task_path" "$task_url" ||
die 1 "Failed to download $t"
done
}

create_dir_or_die() {
local dest_dir="$1"; shift
mkdir -p "$dest_dir" || die 1 "failed to create ${dest_dir}"
echo $dest_dir created
}

main() {
local type=${2:-"default"}

case "$type" in
"ecosystem_tasks")
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/tasks'}
resources=TEKTON_ECOSYSTEM_TASKS
branch="p"
catalog="$TEKTON_ECOSYSTEM"
;;
"ecosystem_stepactions")
dest_dir=${1:-'cmd/openshift/operator/kodata/tekton-addon/addons/06-ecosystem/stepactions'}
resources=TEKTON_ECOSYSTEM_STEPACTIONS
branch="p"
catalog="$TEKTON_ECOSYSTEM"
;;
*)
echo "Invalid type specified: $type"
return 1
;;
esac

[[ -z "$dest_dir" ]] && usage "missing destination directory"
shift

[[ ! -d "$dest_dir" ]] && create_dir_or_die "$dest_dir" || echo "$dest_dir" exists

get_tasks "$dest_dir" $catalog $branch $type $resources
return $?
}

main "$@"