-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentrypoint.sh
executable file
·52 lines (42 loc) · 1.49 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
#!/bin/sh -l
set -e
if [ ! -f "${INPUT_SOURCE}" ] && [ ! -d "${INPUT_SOURCE}" ]; then
echo "No source specified"
exit 1
fi
# set up some directories
CALLING_DIR=$(pwd)
WORKING_DIR=$(mktemp -d)
# set up the github deploy key
mkdir -p ~/.ssh
echo "${INPUT_DEPLOY_KEY}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# set up git
git config --global user.name "${INPUT_GIT_USERNAME}"
git config --global user.email "${INPUT_GIT_EMAIL}"
ssh-keyscan -H github.com > ~/.ssh/known_hosts
GIT_SSH='ssh -i /github/home/.ssh/id_rsa -o UserKnownHostsFile=/github/home/.ssh/known_hosts'
# clone the repo into our working directory and cd to it
GIT_SSH_COMMAND=$GIT_SSH git clone [email protected]:$INPUT_DESTINATION_REPO.git $WORKING_DIR
cd $WORKING_DIR
# checkout the destination branch, creating it if it doesn't exist
git checkout $INPUT_DESTINATION_BRANCH || git checkout -b $INPUT_DESTINATION_BRANCH
# ensure destination directory exists, and is emptied if appropriate
mkdir -p $INPUT_DESTINATION_FOLDER
cd $INPUT_DESTINATION_FOLDER
if [ "${INPUT_DELETE_DESTINATION}" = "true" ]; then
git rm -rf .
fi
# do the copy
if [ -f $CALLING_DIR/$INPUT_SOURCE ]; then
cp -a $CALLING_DIR/$INPUT_SOURCE .
elif [ -d $CALLING_DIR/$INPUT_SOURCE ]; then
cp -a $CALLING_DIR/$INPUT_SOURCE/* .
fi
# create the commit
git add .
git commit -m "${INPUT_COMMIT_MESSAGE}" || echo
GIT_SSH_COMMAND=$GIT_SSH git push -u origin $INPUT_DESTINATION_BRANCH
# output the commit hash
echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
exit 0