-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-action.bash
executable file
·58 lines (54 loc) · 1.84 KB
/
deploy-action.bash
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
#!/bin/bash
set -e
# Remove trailing slashes from path variables:
ACTION_PATH=${ACTION_PATH%/}
ACTION_TRANSFER_PATH=${ACTION_TRANSFER_PATH%/}
# Initiate SSH environment for remote connection:
mkdir -p ~/.ssh
ssh-keyscan -t rsa "$ACTION_HOSTNAME" >> ~/.ssh/known_hosts
ssh_key_path=~/.ssh/action_rsa
echo "$ACTION_SSH_KEY" > "$ssh_key_path"
chmod g-rw,o-rw "$ssh_key_path"
cd "$GITHUB_WORKSPACE"
# Pass in required variables to post-transfer script:
full_transfer_path="$ACTION_TRANSFER_PATH/$GITHUB_SHA"
action_dir="$(dirname -- "${BASH_SOURCE[0]}")"
{
echo "#!/bin/bash"; \
declare -p \
ACTION_PATH \
ACTION_PATH_OWNER \
GITHUB_REF_NAME \
full_transfer_path \
; \
cat "$action_dir"/remote-post-transfer.bash;
} > ./post-transfer.bash
chmod +x ./post-transfer.bash
# Archive directory and pipe over SSH:
dir_size_human=$(du -sbh --exclude "./.git" | grep -o "[0-9]*")
echo "Transferring $dir_size_human bytes to $ACTION_HOSTNAME..."
tar -czf - --exclude-vcs . | \
ssh \
-i "$ssh_key_path" \
-p "$ACTION_PORT" \
"$ACTION_USER"@"$ACTION_HOSTNAME" \
"rm -rf $full_transfer_path && mkdir -p $full_transfer_path && cd $full_transfer_path && tar -xzf - && mv ./post-transfer.bash $ACTION_POST_TRANSFER_SCRIPT && echo $ACTION_POST_TRANSFER_SCRIPT_PREFIX $ACTION_POST_TRANSFER_SCRIPT && $ACTION_POST_TRANSFER_SCRIPT_PREFIX $ACTION_POST_TRANSFER_SCRIPT"
echo "Transfer complete"
deployed_dir="$ACTION_PATH/$GITHUB_REF_NAME"
if [ -n "$ACTION_AFTER_COMMAND" ]
then
echo "Running after command: $ACTION_AFTER_COMMAND"
ssh \
-i "$ssh_key_path" \
-p "$ACTION_PORT" \
"$ACTION_USER"@"$ACTION_HOSTNAME" \
"cd $deployed_dir && $ACTION_AFTER_COMMAND"
fi
if [ -n "$ACTION_PATH_OWNER" ]
then
ssh \
-i "$ssh_key_path" \
-p "$ACTION_PORT" \
"$ACTION_USER"@"$ACTION_HOSTNAME" \
"$ACTION_POST_TRANSFER_SCRIPT_PREFIX $ACTION_POST_TRANSFER_SCRIPT CHOWN"
fi