Skip to content

Commit 541713b

Browse files
rootroot
authored andcommitted
test_static_website
1 parent fb5bf5c commit 541713b

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
## Source path
4+
THUB_SRC=${1}
5+
if [ -z "${THUB_SRC}" ]; then
6+
echo 'ERROR: THUB_SRC variable is empty. Aborting...'
7+
exit 1
8+
fi
9+
10+
## Source files for build process
11+
THUB_COMPARE_PATH="${@:2}"
12+
if [ -z "${THUB_COMPARE_PATH}" ]; then
13+
echo 'ERROR: THUB_COMPARE_PATH variable is empty. Aborting...'
14+
exit 1
15+
fi
16+
17+
## Setup environmental variables
18+
[ -f .terrahub_build.env ] && . .terrahub_build.env
19+
20+
## Compare SHA256 sums from THUB_SRC file with files in THUB_COMPARE_PATH
21+
echo "THUB_BUILD_OK='${THUB_BUILD_OK}' ==> Comparing SHA256 sums."
22+
if [ "$(uname)" == "Darwin" ]; then
23+
THUB_SHA=$(find -s ${THUB_COMPARE_PATH} -path **/node_modules -prune -o -type f -exec shasum -a 256 {} \; | sort -k 2 | shasum -a 256 | cut -f 1 -d " ")
24+
else
25+
THUB_SHA=$(find ${THUB_COMPARE_PATH} -path **/node_modules -prune -o -type f -exec shasum -a 256 {} \; | sort -k 2 | shasum -a 256 | cut -f 1 -d " ")
26+
fi
27+
28+
## Checking if needs to skip SHA256 sums compare
29+
echo "export THUB_SHA=\"${THUB_SHA}\"" >> .terrahub_build.env
30+
echo "INFO: Current SHA256 => ${THUB_SHA}"
31+
if [ "${THUB_BUILD_OK}" == "true" ]; then
32+
echo "INFO: THUB_BUILD_OK='${THUB_BUILD_OK}' ==> Skipping comparing SHA256 sums."
33+
exit 0
34+
fi
35+
36+
## Checking if the project requires to be built
37+
THUB_COMPARE=$(head -n 1 ${THUB_SRC})
38+
echo "INFO: S3 Object SHA256 => ${THUB_COMPARE}"
39+
if [ "${THUB_SHA}" != "${THUB_COMPARE}" ]; then
40+
echo 'Build is required!'
41+
echo 'export THUB_BUILD_OK="true"' >> .terrahub_build.env
42+
else
43+
echo 'Build is NOT required.'
44+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
## Source path
4+
THUB_SRC=${1}
5+
if [ -z "${THUB_SRC}" ]; then
6+
echo 'ERROR: THUB_SRC variable is empty. Aborting...'
7+
exit 1
8+
fi
9+
10+
## S3 bucket name
11+
THUB_S3_PATH=${2-${THUB_S3_PATH}}
12+
if [ -z "${THUB_S3_PATH}" ]; then
13+
echo 'ERROR: THUB_S3_PATH variable is empty. Aborting...'
14+
exit 1
15+
fi
16+
17+
## Clean environmental variables
18+
> .terrahub_build.env
19+
20+
## Checking if THUB_S3_PATH file exists in S3
21+
gsutil --version > /dev/null 2>&1 || { echo >&2 'gsutil is missing. Aborting...'; exit 1; }
22+
THUB_CHECK_TYPE=$(gsutil ls ${THUB_S3_PATH}|| echo "")
23+
if [ -z "${THUB_CHECK_TYPE}" ]; then
24+
echo "INFO: ${THUB_S3_PATH} does NOT exist ==> First execution."
25+
echo 'export THUB_BUILD_OK="true"' >> .terrahub_build.env
26+
exit 0
27+
fi
28+
29+
## Downloading from S3
30+
echo 'INFO: Downloading THUB_SRC from THUB_S3_PATH'
31+
if [[ $THUB_CHECK_TYPE = *" PRE "* ]]; then
32+
gsutil rsync ${THUB_S3_PATH} ${THUB_SRC}
33+
else
34+
gsutil cp ${THUB_S3_PATH} ${THUB_SRC}
35+
fi
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
## Source path
4+
THUB_SRC=${1}
5+
if [ -z "${THUB_SRC}" ]; then
6+
echo 'ERROR: THUB_SRC variable is empty. Aborting...'
7+
exit 1
8+
fi
9+
10+
## Setup environmental variables
11+
[ -f .terrahub_build.env ] && . .terrahub_build.env
12+
13+
## Checking if THUB_BUILD_OK is true
14+
if [ "$THUB_BUILD_OK" == "true" ]; then
15+
## Checking if SHA256 sums exists
16+
if [ -z "${THUB_SHA}" ]; then
17+
echo "ERROR: THUB_SHA variable is empty. Aborting..."
18+
exit 1
19+
fi
20+
21+
## Write current SHA256 to THUB_SRC
22+
echo "${THUB_SHA}" > ${THUB_SRC}
23+
else
24+
echo "Build was NOT executed ==> SHA256 will NOT be updated."
25+
fi
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
## Source path
4+
THUB_SRC=${1}
5+
if [ -z "${THUB_SRC}" ]; then
6+
echo 'ERROR: THUB_SRC variable is empty. Aborting...'
7+
exit 1
8+
fi
9+
10+
## S3 bucket name
11+
THUB_S3_PATH=${2-${THUB_S3_PATH}}
12+
if [ -z "${THUB_S3_PATH}" ]; then
13+
echo 'ERROR: THUB_S3_PATH variable is empty. Aborting...'
14+
exit 1
15+
fi
16+
17+
## Setup environmental variables
18+
[ -f .terrahub_build.env ] && . .terrahub_build.env
19+
20+
## Checking if THUB_BUILD_OK is true
21+
if [ "${THUB_BUILD_OK}" == "true" ]; then
22+
## Sync THUB_SRC to THUB_S3_PATH
23+
gsutil --version > /dev/null 2>&1 || { echo >&2 'gsutil is missing. Aborting...'; exit 1; }
24+
if [[ -d "${THUB_SRC}" ]]; then
25+
gsutil rsync ${THUB_SRC} ${THUB_S3_PATH}
26+
elif [[ -f "${THUB_SRC}" ]]; then
27+
gsutil cp ${THUB_SRC} ${THUB_S3_PATH}
28+
else
29+
echo "ERROR: ${THUB_SRC} is not valid"
30+
exit 1
31+
fi
32+
else
33+
echo 'Build was NOT executed ==> Files will NOT be uploaded.'
34+
fi

0 commit comments

Comments
 (0)