-
Notifications
You must be signed in to change notification settings - Fork 5
/
entrypoint.sh
executable file
·71 lines (57 loc) · 2.04 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh -l
echo "🚀 Igniting...3 2 1"
echo "⚙️ Changing the gears"
GIT_USER_EMAIL="${INPUT_GIT_USER_EMAIL:-'[email protected]'}"
GIT_USER_NAME="${INPUT_GIT_USER_NAME:-'GitHub Action'}"
git config --global user.email "$GIT_USER_EMAIL"
git config --global user.name "$GIT_USER_NAME"
ACCESS_TOKEN="$INPUT_ACCESS_TOKEN"
TARGET_REPO="$INPUT_TARGET_REPO"
TARGET_BRANCH="${INPUT_TARGET_BRANCH:-main}"
CLEANUP_COMMAND="$INPUT_CLEANUP_COMMAND"
SRC_DIR="$INPUT_SRC_DIR"
TARGET_DIR="$INPUT_TARGET_DIR"
PRECOMMIT_COMMAND="$INPUT_PRECOMMIT_COMMAND"
# If access token is provided, use it
if [ ! -z "$ACCESS_TOKEN" ]; then
REPO_PATH="https://[email protected]/$TARGET_REPO.git"
else
# otherwise it's assumed that SSH is already set up
REPO_PATH="[email protected]:$TARGET_REPO.git"
fi
echo "⬇️ Cloning $TARGET_REPO"
CLONE_DIR="__${TARGET_REPO}__clone__"
cd $GITHUB_WORKSPACE
# Ensure that the clone path is clean
rm -rf $CLONE_DIR/*
git clone -b $TARGET_BRANCH $REPO_PATH $CLONE_DIR
echo "🧹 Housekeeping"
cd $GITHUB_WORKSPACE/$CLONE_DIR
eval "$CLEANUP_COMMAND"
echo "⏳ Copying files from $SRC_DIR"
# Make sure the directory exists after clean up
mkdir -p $GITHUB_WORKSPACE/$CLONE_DIR/$TARGET_DIR
# If the source is a directory
if [ -d "$GITHUB_WORKSPACE/$SRC_DIR" ]; then
cp -r $GITHUB_WORKSPACE/$SRC_DIR/* $GITHUB_WORKSPACE/$CLONE_DIR/$TARGET_DIR
else
cp -r $GITHUB_WORKSPACE/$SRC_DIR $GITHUB_WORKSPACE/$CLONE_DIR/$TARGET_DIR
fi
echo "🟡 Running pre-commit command"
cd $GITHUB_WORKSPACE/$CLONE_DIR
eval "$PRECOMMIT_COMMAND"
SOURCE_COMMIT="${GITHUB_REPOSITORY}@${GITHUB_SHA}"
DEFAULT_COMMIT_MSG="Deployed from $SOURCE_COMMIT"
COMMIT_MSG="${INPUT_COMMIT_MSG:-$DEFAULT_COMMIT_MSG}"
cd $GITHUB_WORKSPACE/$CLONE_DIR
# Commit if there is anything to
if [ -n "$(git status --porcelain)" ]; then
echo "☑️ Committing changes"
git add .
git commit -m "$COMMIT_MSG"
echo "🚀 Pushing the changes"
git push -f origin $TARGET_BRANCH
else
echo "🤷🏻♂️ No changes to push"
fi
echo "✅ All done"