-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
460 lines (409 loc) · 19.8 KB
/
action.yaml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
name: System Requirements
description: 'System Requirements (DevOps)'
####----------------------------------------------------------------------------
inputs:
update-system:
description: 'Updating the Operating System State'
required: false
default: true
upgrade-system:
description: 'Upgrading the Operating System State'
required: false
default: false
update-python-version:
description: 'Updating the current Python Version'
required: false
default: true
update-pip-version:
description: 'Updating the current PIP Version'
required: false
default: true
install-default-tools:
description: 'Installing Default Toolset (DevOps)'
required: false
default: false
install-custom-tools:
description: 'Installing Custom Toolset (DevOps)'
required: false
default: false
install-python-requirements:
description: 'Installing Python Requirements'
required: false
default: false
install-awscli-cli:
description: 'Installing AWS CLI Tool (latest)'
required: false
default: false
install-terraform-cli:
description: 'Installing HashiCorp Terraform CLI'
required: false
default: false
awscli-download:
description: 'AWS CLI Download Domain'
required: false
default: 'awscli.amazonaws.com'
awscli-package:
description: 'AWS CLI Package (Linux)'
required: false
default: 'awscli-exe-linux-x86_64.zip'
terraform-version:
description: 'Terraform CLI Version (latest)'
required: false
default: latest
debuger-mode:
description: 'Enabling Shell Debugger'
required: false
default: false
verbose-mode:
description: 'Enabling Verbosity'
required: false
default: false
####----------------------------------------------------------------------------
## outputs:
####----------------------------------------------------------------------------
runs:
using: "composite"
steps:
- name: System Release
id: system-release
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
completion="Skipping ...! " ;
####--------------------------------------------------------------------
completion="Completed! " ;
####--------------------------------------------------------------------
echo -e ;
cat /etc/os-release ;
export system_platform="$(
cat /etc/os-release \
| egrep '^NAME=".*$' \
| sed -e 's|"||g' -e 's|^NAME=||' \
| tr '[[:upper:]]' '[[:lower:]]'
)" ;
echo "SYSTEM_PLATFORM=${system_platform}" >> ${GITHUB_ENV} ;
echo -e ;
if [[ ${system_platform} == 'ubuntu' ]]; then
echo -en "Installing LSB Release ... " ;
sudo apt-get install --yes lsb-release 1>/dev/null ;
echo -e "done." ;
echo -en "Installing Dos2Unix ... " ;
sudo apt-get install --yes dos2unix 1>/dev/null ;
echo -e "done." ;
fi;
echo -e ;
####--------------------------------------------------------------------
- name: Updating Operating System
id: updating-operating-system
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function update_system () {
local message="Updating Operating System (latest)" ;
if [[ "${{ inputs.update-system }}" == true ]]; then
echo -en "\n${message} ..." ;
if [[ ${{ env.SYSTEM_PLATFORM }} == 'ubuntu' ]]; then
sudo apt-get update --yes 2>&1>/dev/null ;
fi;
echo -e " done." ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias update-system='update_system' ;
update_system ;
####--------------------------------------------------------------------
- name: Upgrading Operating System
id: upgrading-operating-system
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function upgrade_system () {
local message="Upgrading Operating System (latest)" ;
if [[ "${{ inputs.upgrade-system }}" == true ]]; then
echo -en "\n${message} ..." ;
if [[ ${{ env.SYSTEM_PLATFORM }} == 'ubuntu' ]]; then
sudo apt-get upgrade --yes 2>&1>/dev/null ;
fi;
echo -e " done." ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias upgrade-system='upgrade_system' ;
upgrade_system ;
####--------------------------------------------------------------------
- name: Linking Python (Latest)
id: linking-python3
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function linking_python3 () {
local message="Linking Python (latest: 3.x)" ;
if [[ "${{ inputs.update-python-version }}" == true ]]; then
echo -en "\n${message} ... " ;
cd /usr/bin ;
sudo ln -fs python3 python ;
python --version ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias linking-python3='linking_python3' ;
linking_python3 ;
echo -e ;
####--------------------------------------------------------------------
- name: Python PIP3 (Latest)
id: python-pip3
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function python_pip3 () {
local message="Install/Upgrade python3-pip" ;
if [[ "${{ inputs.update-pip-version }}" == true ]]; then
echo -en "\n${message} ... " ;
if [[ ${{ env.SYSTEM_PLATFORM }} == 'ubuntu' ]]; then
sudo apt install python3-pip --yes ;
fi;
python -m pip install --upgrade pip ;
pip --version ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias python-pip3='python_pip3' ;
python_pip3 ;
echo -e ;
####--------------------------------------------------------------------
- name: Python Requirements
id: python-requirements
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function python_requirements () {
local message="Installing Python Requirements" ;
local requirements_listing="/tmp/requirements.list" ;
local requirements="${{ inputs.install-python-requirements }}" ;
if [[ ( "${#requirements}" -gt 0 ) && ( "${requirements}" != false ) ]]; then
declare -a requirements=(
${{ inputs.install-python-requirements }}
) ;
if [[ "${#requirements[@]}" -gt 0 ]]; then
echo -e ${requirements[@]} \
| tr '[[:blank:]]' '\n' \
| sed '/^$/d' \
| sort -n | uniq - \
| dos2unix \
> "${requirements_listing}" ;
if [ -f "${requirements_listing}" ]; then
echo -e "\nRequirements:\n\n$( cat "${requirements_listing}" )" ;
if [[ $( wc -w "${requirements_listing}" | awk '{print $1}' ) -gt 0 ]]; then
echo -e "\n${message} ..." ;
pip install -r "${requirements_listing}" ;
else echo -e "Warning: "${requirements_listing}" is empty! " ;
fi;
else echo -e "Warning: "${requirements_listing}" was not found";
fi;
fi ;
else echo -e "\nSkip: ${message}! " ;
fi;
return 0;
}; ## alias python-requirements='python_requirements' ;
python_requirements ;
echo -e ;
####--------------------------------------------------------------------
- name: Installing Toolset
id: installing-toolset
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function install_toolset () {
local message="Install Toolset" ;
local default="${{ inputs.install-default-tools }}" ;
[[ ${default} == false ]] && default='' ;
local custom="${{ inputs.install-custom-tools }}" ;
[[ ${custom} == false ]] && custom='' ;
local packages_listing="/tmp/packages.list" ;
declare -a packages=( "${default}\n${custom}" ) ;
if [[ ( "${#packages}" -gt 0 ) && ( "${packages}" != false ) ]]; then
echo -e ${packages[@]} \
| tr '[[:blank:]]\,\;' '\n' \
| sed '/^$/d' \
| sort -n | uniq - \
| dos2unix \
> "${packages_listing}" ;
if [ -f "${packages_listing}" ]; then
echo -e "\nPackages:\n\n$( cat "${packages_listing}" | sed '/^$/d' )" ;
if [[ $( wc -w "${packages_listing}" | awk '{print $1}' ) -gt 0 ]]; then
declare -a packages=($( cat "${packages_listing}" )) ;
if [[ ${{ env.SYSTEM_PLATFORM }} == 'ubuntu' ]]; then
for package in ${packages[@]}; do
sudo apt-get install --yes ${package} 1>/dev/null;
apt info ${package} ;
done ;
fi ;
else echo -e "Warning: "${packages_listing}" is empty! " ;
fi ;
else echo -e "Warning: "${packages_listing}" was not found! " ;
fi ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias install-toolset='install_toolset' ;
install_toolset ;
####--------------------------------------------------------------------
- name: Installing AWS CLI
id: installing-aws-cli
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function install_awscli () {
aws --version >/dev/null 2>&1 && {
echo -e >&2 "\nAWS CLI is Installed ... Ok! " ;
which aws ;
aws --version ;
} ;
if [[ "${{ inputs.install-awscli-cli }}" == true ]]; then
## Installing AWS CLI (latest):
if [[ "${{ inputs.install-awscli-cli }}" == true ]]; then
awscli_download=${{ inputs.awscli-download }} ;
awscli_package=${{ inputs.awscli-package }} ;
echo -e "\nUpgrading AWS-CLI to version 2.0.40" ;
## https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
cd /tmp ;
wget --quiet "https://${awscli_download}/${awscli_package}" \
--directory-prefix=/tmp/ --output-document=awscliv2.zip ;
unzip awscliv2.zip 1>/dev/null ;
ls -l /usr/local/bin/aws ;
sudo ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update ;
# aws --version ;
fi;
else echo -e "\nSkip: Installing AWS CLI (latest)! " ;
fi ;
return 0;
}; ## alias install-awscli='install_awscli' ;
install_awscli ;
echo -e ;
####--------------------------------------------------------------------
- name: Installing Terraform CLI
id: installing-terraform-cli
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function install_terraform_cli () {
## Reference -> https://developer.hashicorp.com/terraform/downloads
local target_terraform_version=${{ inputs.terraform-version }} ;
local message="Installing HashiCorp Terraform CLI (${target_terraform_version})" ;
## Evaluating if Terraform is installed:
terraform --version >/dev/null 2>&1 && {
current_terraform_version="$(
terraform --version -json | jq '.terraform_version' --raw-output
)" ;
whereis_terraform="$( which terraform )" ;
if [[ "${current_terraform_version}" != "${{ inputs.terraform-version }}" ]]; then
echo -e "Isolating exiting Terraform ${current_terraform_version} binary [ ${whereis_terraform} ] ..." ;
terraform_backup="${whereis_terraform}-v${current_terraform_version}" ;
if [[ ! -f "${terraform_backup}" ]]; then
mv -v "${whereis_terraform}" "${terraform_backup}" ;
fi ;
else echo -e "Warning: Terraform ${{ inputs.terraform-version }} is already installed! " ;
echo -e "\nSkip: ${message}! " ;
return 0 ;
fi ;
} ;
## Processing installation
echo -e "${message}" ;
export USR_LOCAL_BIN="/usr/local/bin" ;
mkdir -p ${USR_LOCAL_BIN} ;
local domain_name="hashicorp.com" ;
local releases="releases.${domain_name}" ;
if [[ "${{ inputs.install-terraform-cli }}" != false ]]; then
if [[ "${{ inputs.terraform-version }}" == 'latest' ]]; then
case ${{ env.SYSTEM_PLATFORM }} in
'ubuntu' ) echo -e "Platform: ${{ env.SYSTEM_PLATFORM }}" ;
local hashicorp_keyring="/usr/share/keyrings/hashicorp-archive-keyring.gpg" ;
repository="https://apt.${releases}" ;
wget --quiet -O- ${repository}/gpg | sudo gpg --dearmor -o ${hashicorp_keyring} ;
echo "deb [signed-by=${hashicorp_keyring}] ${repository} $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/hashicorp.list ;
sudo apt update --yes 1>/dev/null ;
## sudo apt upgrade --yes 1>/dev/null ;
sudo apt install --yes terraform 1>/dev/null ;
cd ${USR_LOCAL_BIN}/ && ln -s $( which terraform ) . && cd - ;
ls -al ${USR_LOCAL_BIN}/terraform ;
;;
'centos/rhel' ) repository="https://rpm.${releases}/RHEL/hashicorp.repo" ;
sudo yum install --yes yum-utils ;
sudo yum-config-manager --add-repo ${repository} ;
sudo yum update --yes ;
## sudo yum upgrade --yes ;
sudo yum --yes install terraform ;
;;
'fedora' ) repository="https://rpm.${releases}/fedora/hashicorp.repo" ;
sudo dnf install --yes dnf-plugins-core ;
sudo dnf config-manager --add-repo ${repository} ;
sudo dnf update --yes ;
## sudo dnf upgrade --yes ;
sudo dnf --yes install terraform ;
;;
'amazon' ) repository="https://rpm.${releases}/AmazonLinux/hashicorp.repo" ;
sudo yum install --yes yum-utils shadow-utils ;
sudo yum-config-manager --add-repo ${repository} ;
sudo yum update --yes ;
## sudo yum upgrade --yes ;
sudo yum --yes install terraform ;
;;
esac ;
else ## Terraform Package details:
terraform_download="${releases}/terraform" ;
terraform_platform='linux_amd64' ;
terraform_package="terraform_${target_terraform_version}_${terraform_platform}.zip" ;
terraform_source="${terraform_download}/${target_terraform_version}/${terraform_package}" ;
echo -e "\nTerraform Source: ${terraform_source}" ;
## Fetching Terraform package:
wget --quiet https://${terraform_source} -P /tmp/ ;
ls -al /tmp/${terraform_package} ;
unzip /tmp/${terraform_package} ;
chmod 0754 ./terraform ;
sudo mv ./terraform ${USR_LOCAL_BIN}/ ;
fi ;
else echo -e "\nSkip: ${message}! " ;
fi ;
return 0;
}; ## alias install-terraform-cli='install_terraform_cli' ;
install_terraform_cli ;
####--------------------------------------------------------------------
- name: Display System Environment
id: system-environment
shell: bash
run: |
## Enabling Debuger-mode:
[[ ${{ inputs.debuger-mode }} == true ]] && set -x ;
####--------------------------------------------------------------------
function system_environment () {
if [[ "${{ inputs.verbose-mode }}" == true ]]; then
echo -e "System Path:" ;
echo $PATH | tr ':' '\n' ;
echo -e "\nEnvironment variables:" ;
env ;
fi ;
return 0;
}; alias system-environment='system_environment' ;
system_environment ;
####--------------------------------------------------------------------
echo -e "\n${completion}\n" ;
####--------------------------------------------------------------------