-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.dist.yml
186 lines (174 loc) · 7.32 KB
/
Taskfile.dist.yml
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
# https://taskfile.dev
#
# Do not edit this file, instead use Taskfile.project.yml.
#
version: '3'
dotenv: ['.env']
vars:
DIR_TASKFILES: Taskfile.d
FILE_TASK_START: "task-start-{{.TASK}}.txt"
FILE_TASK_START1: "task-start-{{.TASK}}1.txt"
TT_GIT_REPO: https://gitlab.com/op_so/task/task-templates/-/raw
includes:
00:
taskfile: Taskfile.project.yml
optional: true
# BEGIN-INCLUDES-TEMPLATES
RUN_00:00-install-templates_TO_UPDATE:
taskfile: RUN_00:00-install-templates_TO_UPDATE.yml
optional: true
# END-INCLUDES-TEMPLATES
tasks:
install-templates:
desc: "[CORE] Download/update tasks templates. Arguments: [PROXY|P=http://proxy:8080] [PROXY_CREDENTIALS|PC=username:password] (*)"
summary: |
[CORE] Download/update tasks templates.
Usage: task install-templates [PROXY|P=http://proxy_url:proxy_port] [PROXY_CREDENTIALS|PC=username:password]
Arguments:
PROXY | P Proxy URL (optional)
PROXY_CREDENTIALS | PC Proxy credentials username:password (optional)
Requirements:
- wget or curl
vars:
PROXY: '{{default .P .PROXY}}'
D_PROXY: '{{default .TASK_PROXY .PROXY}}'
PROXY_CREDENTIALS: '{{default .PC .PROXY_CREDENTIALS}}'
TASK_TEMPLATES:
sh: task 00:00-get-list-templates
FILE: '{{default .F .FILE}}'
D_FILE: '{{default "Taskfile.yml" .FILE}}'
BEGIN: " # BEGIN-INCLUDES-TEMPLATES"
PATTERN_BEGIN: "^{{.BEGIN}}"
END: "# END-INCLUDES-TEMPLATES"
cmds:
- date > {{.FILE_TASK_START}}
- defer: rm -f {{.FILE_TASK_START}}
- mkdir -p "{{.DIR_TASKFILES}}"
- if [ -z "{{.TASK_TEMPLATES}}" ]; then echo "Error TASK_TEMPLATES variable is empty in Taskfile.project.yml file" && exit 1; else echo "Download templates -> {{.TASK_TEMPLATES}}"; fi
- |
line_include_template_begin=$(grep -Fn '{{.BEGIN}}' "{{.D_FILE}}" | head -n 1 | cut -d ':' -f 1)
line_delete_begin=$(expr $line_include_template_begin + 1)
line_include_template_end=$(grep -Fn '{{.END}}' "{{.D_FILE}}" | head -n 1 | cut -d ':' -f 1)
line_delete_end=$(expr $line_include_template_end - 1)
if [ $line_delete_end -ge $line_delete_begin ]; then
sed -i'.bu' "${line_delete_begin},${line_delete_end}d" "{{.D_FILE}}"
fi
- defer: rm -f "{{.D_FILE}}".bu
- |
includes="{{.BEGIN}}"
for t in $(echo "{{.TASK_TEMPLATES}}" | tr "," " "); do
if echo "$t" | grep -q "\[" 2>/dev/null; then
task=$(echo "$t" | cut -d '[' -f 1)
else
task="$t"
fi
includes="$includes\\n ${task}:\\n taskfile: {{.DIR_TASKFILES}}/${task}.yml\\n optional: true"
done
sed -i'.bu' "s={{.PATTERN_BEGIN}}=${includes}=g" "{{.D_FILE}}"
- |
templates_list=$(task 00:00-get-list-templates)
for t in $(echo "{{.TASK_TEMPLATES}}" | tr "," " "); do
if echo "$t" | grep -q "\[" 2>/dev/null; then
task=$(echo "$t" | cut -d '[' -f 1)
v=$(echo "$t" | sed -e 's/.*\[\(.*\)\]/\1/')
version="v${v}"
else
task="$t"
version="main"
fi
echo "Download template: $task version: $version"
task download-template TEMPLATE=${task}.yml VERSION=$version PROXY={{.D_PROXY}} PROXY_CREDENTIALS={{.PROXY_CREDENTIALS}}
done
- echo "Install templates Start $(cat {{.FILE_TASK_START}}) - End $(date)"
silent: true
usage:
desc: "[CORE] Show the usage of a task. Arguments: TSK|T=task-name [FILE|F=Taskfile.dist.yml] (*)"
summary: |
[CORE] Show the usage of a task.
Usage: task [-t Taskfile.dist.yml] usage TSK|T=<task-name> [FILE|F=Taskfile.dist.yml]
Arguments:
TSK | T Name of the task (required)
FILE | F Taskfile path (optional, by default Taskfile.yml)
vars:
TSK: '{{default .T .TSK}}'
FILE: '{{default .F .FILE}}'
D_FILE: '{{default "Taskfile.yml" .FILE}}'
cmds:
- |
if [ ! -f "{{.D_FILE}}" ]; then
echo "{{.D_FILE}} does not exist!"
exit 1
fi
- task -t "{{.D_FILE}}" --summary "{{.TSK}}" | sed '/^dependencies:$/,$d' | sed '/^commands:$/,$d'
preconditions:
- sh: test -n "{{.TSK}}" || test -n "{{.T}}"
msg: "TSK|T argument is required"
silent: true
default:
desc: "[CORE] List of available tasks. Arguments: [FILE|F=Taskfile.project.yml] (*)"
summary: |
[CORE] Show the list of available tasks.
Usage: task [FILE|F=Taskfile.project.yml]
Arguments:
FILE | F Taskfile project path (optional, by default Taskfile.project.yml)
vars:
FILE: '{{default .F .FILE}}'
D_FILE: '{{default "Taskfile.project.yml" .FILE}}'
cmds:
- |
if [ -d "{{.DIR_TASKFILES}}" ]; then
for template in {{.DIR_TASKFILES}}/*.yml
do
template_name=$(basename "$template")
printf "\033[0;33m[ %s: ]\033[0m " "${template_name%.yml}" && task --list -t "$template" || true
echo ""
done
fi
- |
if [ ! -z "{{.D_FILE}}" ]; then
printf "\033[0;33m[ %s: ]\033[0m " "00" && task --list -t "{{.D_FILE}}" || true
fi
- echo ""
- echo " <task install-templates [PROXY|P=http://proxy:8080]> to install or update templates (Variable TASK_TEMPLATES in Taskfile.project.yml file)."
- echo " (*) <task usage TSK=task-name> will show the usage of the task."
silent: true
download-template:
cmds:
- |
if [ -x "$(command -v curl)" ]; then
if [ -z "{{.PROXY}}" ]; then
curl --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
else
if [ -z "{{.PROXY_CREDENTIALS}}" ]; then
echo "Proxy: {{.PROXY}}"
curl -x "{{.PROXY}}" --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
else
echo "Proxy with auth: {{.PROXY}}"
curl -U "{{.PROXY_CREDENTIALS}}" -x "{{.PROXY}}" --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}" --proxy-anyauth
fi
fi
else
if [ -z "{{.PROXY}}" ]; then
wget -cq -O "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
else
if [ -z "{{.PROXY_CREDENTIALS}}" ]; then
proxy={{.PROXY}}
echo "Proxy: $proxy"
else
proto=$(echo {{.PROXY}} | sed -e's,^\(.*://\).*,\1,g')
url=$(echo {{.PROXY}} | sed -e's,^.*://\(.*\),\1,g')
proxy="${proto}{{.PROXY_CREDENTIALS}}@${url}"
echo "Proxy: ${proto}****:****@${url}"
fi
export use_proxy=on && export http_proxy=$proxy && export https_proxy=$proxy && wget -cq -O "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
fi
fi
preconditions:
- sh: test -n "{{.TEMPLATE}}"
msg: "TEMPLATE argument is required"
- sh: test -n "{{.VERSION}}"
msg: "VERSION argument is required"
- sh: command -v curl || command -v wget
msg: "curl or wget are not installed"
silent: true