forked from NxtLvLSoftware/git-subtree-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·52 lines (40 loc) · 1.23 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
# Key scan for github.com
ssh-keyscan github.com > /root/.ssh/known_hosts
# Set ssh key for subtree
echo "${INPUT_DEPLOY_KEY}" >> /root/.ssh/subtree
chmod 0600 /root/.ssh/subtree
# Generate sha256 of the downstream repo name
SPLIT_DIR=$(echo -n "${INPUT_REPO}" | sha256sum)
SPLIT_DIR="${SPLIT_DIR::-3}"
# Get subtree repository into split directory
git init --bare "${SPLIT_DIR}"
# Create the subtree split branch
git subtree split --prefix="${INPUT_PATH}" -b split
# Check for force push to remote
if [ "$INPUT_FORCE" == "true" ]; then
PUSH_ARGS="-f"
fi
# Resolve downstream branch.
# If not set then use the event github ref, if the ref isn't set default to master.
if [ "$INPUT_BRANCH" == "" ]; then
if [ -z "$GITHUB_REF" ] || [ "$GITHUB_REF" == "" ]; then
INPUT_BRANCH="master"
else
INPUT_BRANCH="$GITHUB_REF"
fi
fi
# Push to the subtree directory
git push "${PUSH_ARGS}" "${SPLIT_DIR}" split:"$INPUT_BRANCH"
cd "${SPLIT_DIR}"
git remote add origin subtree:"${INPUT_REPO}"
git push -u "${PUSH_ARGS}" origin "$INPUT_BRANCH"
# Tag the subtree repository
if [ "$INPUT_TAG" != "false" ]; then
if [ "$INPUT_TAG" == "true" ]; then
INPUT_TAG="${GITHUB_REF}"
fi
git tag $(basename "${INPUT_TAG}")
git push --tags
fi