-
Notifications
You must be signed in to change notification settings - Fork 0
/
push_master.sh
executable file
·68 lines (52 loc) · 1.72 KB
/
push_master.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
#!/bin/bash
set -euo pipefail
echo ">>> Begin push_master.sh"
cd "$(dirname "$0")"
. .env.local
echo ">>> Local environment file is loaded."
REPO_NAME="gakumasu-diff"
ARTIFACT_DIR_NAME="cache/masterYaml"
VERSION_FILE="cache/master_version"
REPO_SSH="git@github.com:vertesan/gakumasu-diff.git"
old_version=$1
if [ ! -v SSH_KEY_PATH ]; then
echo ">>> SSH_KEY_PATH is not set, will be exiting."
exit 201
fi
if [ ! -f "$SSH_KEY_PATH" ]; then
echo ">>> $SSH_KEY_PATH does not exists, will be exiting."
exit 202
fi
if [ ! -e "$VERSION_FILE" ]; then
echo ">>> cache/master_version does not exist, will be exiting."
exit 203
fi
new_version=$(cat "$VERSION_FILE")
if [[ "$old_version" == "$new_version" ]]; then
echo ">>> Nothing updated, will be exiting."
exit 0
fi
# clone repository if does not exist
if [ ! -d "$REPO_NAME" ]; then
echo ">>> Cloning repo from remote..."
GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -i ${SSH_KEY_PATH}" git clone --depth 1 "$REPO_SSH" "$REPO_NAME"
fi
# Set git configurations
git -C "$REPO_NAME" config user.name vts-server
git -C "$REPO_NAME" config user.email 169537433+vts-server@users.noreply.github.com
git -C "$REPO_NAME" config core.sshCommand "ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i $SSH_KEY_PATH -F /dev/null"
# Copy database files to repository directory
cp $ARTIFACT_DIR_NAME/*.yaml $REPO_NAME
# Remove database files which no longer in use
for pPath in $REPO_NAME/*.yaml
do
pFile=$(basename "$pPath")
if [ ! -f $ARTIFACT_DIR_NAME/$pFile ]; then
rm -f "$REPO_NAME/$pFile"
fi
done
git -C "$REPO_NAME" add .
git -C "$REPO_NAME" commit -m "$new_version"
echo ">>> Pushing to remote repository..."
git -C "$REPO_NAME" push
echo ">>> push_master.sh completed."