forked from jovrtn/github-action-wpengine-git-deploy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·45 lines (39 loc) · 1.57 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
#!/bin/sh -l
set -e
: ${WPENGINE_SITE_NAME?Required environment name variable not set.}
: ${WPENGINE_SSH_KEY_PRIVATE?Required secret not set.}
: ${WPENGINE_SSH_KEY_PUBLIC?Required secret not set.}
printf "\nSet git parameters:\n"
WPENGINE_HOST="git.wpengine.com"
WPENGINE_ENVIRONMENT_DEFAULT="development"
WPENGINE_ENV=${WPENGINE_ENVIRONMENT:-$WPENGINE_ENVIRONMENT_DEFAULT}
LOCAL_BRANCH_DEFAULT="main"
BRANCH=${LOCAL_BRANCH:-$LOCAL_BRANCH_DEFAULT}
printf "\nSet ssh keys:\n"
printf "\nHome: $HOME\n"
SSH_PATH="$HOME/.ssh"
mkdir "$SSH_PATH"
chmod 700 "$SSH_PATH"
KNOWN_HOSTS_PATH="$SSH_PATH/known_hosts"
WPENGINE_SSH_KEY_PRIVATE_PATH="$SSH_PATH/wpengine_key"
WPENGINE_SSH_KEY_PUBLIC_PATH="$SSH_PATH/wpengine_key.pub"
echo "$WPENGINE_SSH_KEY_PRIVATE" > "$WPENGINE_SSH_KEY_PRIVATE_PATH"
echo "$WPENGINE_SSH_KEY_PUBLIC" > "$WPENGINE_SSH_KEY_PUBLIC_PATH"
chmod 600 "$WPENGINE_SSH_KEY_PRIVATE_PATH"
chmod 644 "$WPENGINE_SSH_KEY_PUBLIC_PATH"
printf "\nKey scan:\n"
ssh-keyscan -t rsa "$WPENGINE_HOST" >> "$KNOWN_HOSTS_PATH"
chmod 644 "$KNOWN_HOSTS_PATH"
printf "\nGit configs, checkout, and push:\n"
git config core.sshCommand "ssh -i $WPENGINE_SSH_KEY_PRIVATE_PATH -o UserKnownHostsFile=$KNOWN_HOSTS_PATH"
git remote add $WPENGINE_SITE_NAME git@$WPENGINE_HOST:$WPENGINE_ENV/$WPENGINE_SITE_NAME.git
printf "\nLocal branches:\n"
git branch
printf "\nRemote branch:\n"
git branch -r
printf "\nGit Remote Show $WPENGINE_SITE_NAME:\n"
git remote show $WPENGINE_SITE_NAME
printf "\nGit status:\n"
git status
printf "\nPushing to WPE Site $WPENGINE_SITE_NAME\n"
git push -fu $WPENGINE_SITE_NAME $BRANCH:master