This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·119 lines (100 loc) · 4.74 KB
/
entrypoint.sh
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
#! /bin/sh
# Helpers
# Make formatting consistent before diff
prettify() {
local temp_file
temp_file=$(mktemp) &&
jq -S . < "$1" > "$temp_file" &&
mv -- "$temp_file" "$1"
}
# Parce downloaded pipe/system config to get (in most cases) originally uploaded config file
get_original() {
local temp_file
temp_file=$(mktemp) &&
jq -S '.config|.original|del(."$audit")?|del(."_updated")?|del(."_deleted")?|del(."_hash")?|del(."_deleted")?|del(."_previous")?|del(."_ts")?' < "$1" > "$temp_file" &&
mv -- "$temp_file" "$1"
}
no_transient_decimal() {
folder_name="$1"
glob_expr="$2"
# Process all files in the specified folder that match the glob expression. Transform transient decimal to non-transient decimal
find "$folder_name" -name "$glob_expr" -type f -exec sed -i -r 's/"~f([-]?[0-9]+\.[0-9]+)"/\1/g' {} \;
}
if $INPUT_DOWNLOAD = "true"; then
# Make tmp directories
mkdir -p /tmp/sesam/DOWNLOAD/variables
# Download config from sesam node
echo "Downloading config from $INPUT_NODE"
curl "https://$INPUT_NODE/api/config" \
-H 'accept: application/zip' \
-H "authorization: bearer $INPUT_JWT" \
--compressed \
-o /tmp/sesam/download_config.zip
# Unzip config
unzip /tmp/sesam/download_config.zip -d /tmp/sesam/download_config
cp -r /tmp/sesam/download_config/* /tmp/sesam/DOWNLOAD
rm -rf /tmp/sesam/download_config /tmp/sesam/download_config.zip
# Download variables
echo "Downloading variables $INPUT_NODE"
curl "https://$INPUT_NODE/api/env" \
-H 'accept: application/json' \
-H "authorization: bearer $INPUT_JWT" \
--compressed \
-o /tmp/sesam/DOWNLOAD/variables/variables.json
# Download node metadata
echo "Downloading metadata from $INPUT_NODE"
curl "https://$INPUT_NODE/api/metadata" \
-H 'accept: application/json' \
-H "authorization: bearer $INPUT_JWT" \
--compressed \
-o /tmp/sesam/DOWNLOAD/node-metadata.conf.json
mkdir -p /tmp/sesam/tmp_download
mkdir -p /tmp/sesam/tmp_download/variables
mkdir -p /tmp/sesam/tmp_download/pipes
mkdir -p /tmp/sesam/tmp_download/systems
mv /tmp/sesam/DOWNLOAD/node-metadata.conf.json -t /tmp/sesam/tmp_download
mv /tmp/sesam/DOWNLOAD/variables -t /tmp/sesam/tmp_download
mv /tmp/sesam/DOWNLOAD/pipes -t /tmp/sesam/tmp_download
mv /tmp/sesam/DOWNLOAD/systems -t /tmp/sesam/tmp_download
else
echo "Only do diff, not downloading config from $INPUT_NODE"
mkdir -p /tmp/sesam/tmp_download
cp -R $INPUT_CONFIG_PATH_DOWNLOAD/* /tmp/sesam/tmp_download/
fi
# Copy only the files in whitelist to the upload diff folder
if [ -n "$INPUT_WHITELIST" ]; then
echo "Whitelisting files"
mkdir -p /tmp/sesam/tmp_upload
mkdir -p /tmp/sesam/tmp_upload/variables
mkdir -p /tmp/sesam/tmp_upload/pipes
mkdir -p /tmp/sesam/tmp_upload/systems
while read -r file;
do
cp $INPUT_CONFIG_PATH_LOCAL/$file /tmp/sesam/tmp_upload/$file
# echo $INPUT_CONFIG_PATH_LOCAL/$file /tmp/sesam/tmp_upload/$file
done < $INPUT_WHITELIST
cp -R $INPUT_CONFIG_PATH_LOCAL/variables/* /tmp/sesam/tmp_upload/variables/
else
echo "No whitelist, exiting"
exit 1
fi
# We are not interested in diffs that are not relevant and will change configs so we do not get false positives
# Transient values that are not relevant for the diff. That is e.g. -0.1234 and "~f-0.1234" is considered the same value.
no_transient_decimal /tmp/sesam/tmp_download/pipes/ "*.conf.json"
no_transient_decimal /tmp/sesam/tmp_upload/pipes/ "*.conf.json"
no_transient_decimal /tmp/sesam/tmp_download/systems/ "*.conf.json"
no_transient_decimal /tmp/sesam/tmp_upload/systems/ "*.conf.json"
# Check if there are differences between the downloaded config and the local config
echo '```diff' | tee -a $GITHUB_STEP_SUMMARY
git diff --diff-algorithm=histogram --no-index $@ -- /tmp/sesam/tmp_download/systems /tmp/sesam/tmp_upload/systems | tee -a $GITHUB_STEP_SUMMARY
git diff --diff-algorithm=histogram --no-index $@ -- /tmp/sesam/tmp_download/pipes /tmp/sesam/tmp_upload/pipes | tee -a $GITHUB_STEP_SUMMARY
# Prettify the node and variables json files in order to make the diff more relevant
prettify /tmp/sesam/tmp_download/variables/variables.json
prettify /tmp/sesam/tmp_upload/variables/variables.json
get_original /tmp/sesam/tmp_download/node-metadata.conf.json
prettify /tmp/sesam/tmp_upload/node-metadata.conf.json
git diff --diff-algorithm=histogram --no-index $@ -- /tmp/sesam/tmp_download/variables /tmp/sesam/tmp_upload/variables | tee -a $GITHUB_STEP_SUMMARY
git diff --diff-algorithm=histogram --no-index $@ -- /tmp/sesam/tmp_download/node-metadata.conf.json /tmp/sesam/tmp_upload/node-metadata.conf.json | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
# If there are differences, git exits with 1. We want to ignore this and give exit code 0 back to github actions
exit 0