forked from dmnemec/copy_file_to_another_repo_action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·72 lines (60 loc) · 1.73 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
72
#!/bin/sh
set -e
set -x
if [ -z "$INPUT_SOURCE_FILE" ]
then
echo "Source file must be defined"
return 1
fi
if [ -z "$INPUT_GIT_SERVER" ]
then
INPUT_GIT_SERVER="github.com"
fi
if [ -z "$INPUT_DESTINATION_BRANCH" ]
then
INPUT_DESTINATION_BRANCH=main
fi
OUTPUT_BRANCH="$INPUT_DESTINATION_BRANCH"
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 config --global http.postBuffer 524288000
git clone --depth 1 --single-branch --branch $INPUT_DESTINATION_BRANCH "https://x-access-token:$API_TOKEN_GITHUB@$INPUT_GIT_SERVER/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"
if [ ! -z "$INPUT_RENAME" ]
then
echo "Setting new filename: ${INPUT_RENAME}"
DEST_COPY="$CLONE_DIR/$INPUT_DESTINATION_FOLDER/$INPUT_RENAME"
else
DEST_COPY="$CLONE_DIR/$INPUT_DESTINATION_FOLDER"
fi
echo "Copying contents to git repo"
mkdir -p $CLONE_DIR/$INPUT_DESTINATION_FOLDER
if [ -z "$INPUT_USE_RSYNC" ]
then
cp -R "$INPUT_SOURCE_FILE" "$DEST_COPY"
else
echo "rsync mode detected"
rsync -avrh "$INPUT_SOURCE_FILE" "$DEST_COPY"
fi
cd "$CLONE_DIR"
if [ ! -z "$INPUT_DESTINATION_BRANCH_CREATE" ]
then
echo "Creating new branch: ${INPUT_DESTINATION_BRANCH_CREATE}"
git checkout -b "$INPUT_DESTINATION_BRANCH_CREATE"
OUTPUT_BRANCH="$INPUT_DESTINATION_BRANCH_CREATE"
fi
if [ -z "$INPUT_COMMIT_MESSAGE" ]
then
INPUT_COMMIT_MESSAGE="Update from https://$INPUT_GIT_SERVER/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
fi
echo "Adding git commit"
git add .
if git status | grep -q "Changes to be committed"
then
git commit --message "$INPUT_COMMIT_MESSAGE"
echo "Pushing git commit"
git push -u origin HEAD:"$OUTPUT_BRANCH"
else
echo "No changes detected"
fi