-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-resources
executable file
·43 lines (35 loc) · 1.44 KB
/
compile-resources
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
#!/bin/bash
scripts=(julia-ci gitlab-ci-credential)
functions=(functions/*)
# Add an external resource file into a YAML file as a variable.
#
# Note that the variable names used should be unique enough to not conflict with any other
# variables that may be manually defined. We'll use the `__GCH_` (Gitlab Ci Helper) prefix
# for this purpose. These variable names should only be referenced internally in the
# gitlab-ci-helper repo as this supports future changes.
function embed_resource {
local type=$1
local file=$2
local filename=$(basename $file)
local name=$(echo -n "$filename" | tr -C '[[:alnum:]]' '_')
echo " __GCH_TYPE_$name: \"$type\""
if [[ "$name" != "$filename" ]]; then
echo " __GCH_FILENAME_$name: \"$filename\""
fi
echo " __GCH_CONTENT_$name: |"
# Indent entire file by 4-spaces, truncate blank lines, then escape any use of `$`
cat $file | sed 's/^/ /g' | sed 's/^[[:space:]]*$//g' | sed 's/\$/\$\$/g'
}
echo "---"
echo "# This file is machine-generated by \`$(basename $0)\`"
echo "variables:"
# Embed script files in YAML. These scripts will be available on the PATH
# (only in the current shell) once ci-setup has executed.
for path in "${scripts[@]}"; do
embed_resource script $path
done
# Embed BASH functions in YAML. These BASH functions will be available
# (only in the current shell) once ci-setup has executed.
for path in "${functions[@]}"; do
embed_resource function $path
done