forked from crykn/copy_folder_to_another_repo_action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·50 lines (41 loc) · 1.18 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
#!/bin/sh
set -e
set -x
if [ -z "$INPUT_SOURCE_FOLDER" ]
then
echo "Source folder must be defined"
return -1
fi
if [ -z "$INPUT_DESTINATION_BRANCH" ]
then
INPUT_DESTINATION_BRANCH=master
fi
OUTPUT_BRANCH="$INPUT_DESTINATION_BRANCH"
if [ -z "$INPUT_COMMIT_MSG" ]
then
INPUT_COMMIT_MSG="Update $INPUT_DESTINATION_FOLDER."
fi
CLONE_DIR=$(mktemp -d)
echo "Cloning destination git repository"
git config --global user.email "$INPUT_USER_EMAIL"
git config --global user.name "$INPUT_USER_NAME"
git clone --single-branch --branch $INPUT_DESTINATION_BRANCH "https://$API_TOKEN_GITHUB@github.com/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"
if [ ! -z "$INPUT_DESTINATION_BRANCH_CREATE" ]
then
git checkout -b "$INPUT_DESTINATION_BRANCH_CREATE"
OUTPUT_BRANCH="$INPUT_DESTINATION_BRANCH_CREATE"
fi
echo "Copying contents to git repo"
rm -rf $CLONE_DIR/$INPUT_DESTINATION_FOLDER/
cp -a $INPUT_SOURCE_FOLDER/. $CLONE_DIR/$INPUT_DESTINATION_FOLDER/
cd "$CLONE_DIR"
echo "Adding git commit"
git add .
if git status | grep -q "Changes to be committed"
then
git commit --message "$INPUT_COMMIT_MSG"
echo "Pushing git commit"
git push -u origin HEAD:$OUTPUT_BRANCH
else
echo "No changes detected"
fi