forked from moovfinancial/moov-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·70 lines (56 loc) · 1.98 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
#!/bin/sh
set -e
set -x
export INPUT_DESTINATION_HEAD_BRANCH=$INPUT_HEAD_BRANCH
if [ -z "$INPUT_SOURCE_FOLDER" ]
then
echo "Source folder must be defined"
return -1
fi
if [ $INPUT_DESTINATION_HEAD_BRANCH == "main" ] || [ $INPUT_DESTINATION_HEAD_BRANCH == "master"]
then
echo "Destination head branch cannot be 'main' nor 'master'"
return -1
fi
if [ -z "$INPUT_PULL_REQUEST_REVIEWERS" ]
then
PULL_REQUEST_REVIEWERS=$INPUT_PULL_REQUEST_REVIEWERS
else
PULL_REQUEST_REVIEWERS='-r '$INPUT_PULL_REQUEST_REVIEWERS
fi
NODE_DIR=$(pwd)
CLONE_DIR=$(mktemp -d)
PR_URL="https://github.com/moovfinancial/moov-node/pull/$INPUT_PULL_REQUEST_NUMBER"
echo "Setting git variables"
export GITHUB_TOKEN=$API_TOKEN_GITHUB
git config --global user.email "$INPUT_USER_EMAIL"
git config --global user.name "$INPUT_USER_NAME"
echo "Cloning destination git repository"
git clone "https://$INPUT_USER_NAME:[email protected]/$INPUT_DESTINATION_REPO.git" "$CLONE_DIR"
cd "$CLONE_DIR"
echo "Creating Branch if not exist"
git checkout $INPUT_DESTINATION_HEAD_BRANCH || git checkout -b $INPUT_DESTINATION_HEAD_BRANCH
git pull origin $INPUT_DESTINATION_HEAD_BRANCH || echo "New branch, no pull needed"
echo "Copying contents to git repo"
mkdir -p $CLONE_DIR/$INPUT_DESTINATION_FOLDER
cp -r ${NODE_DIR}/${INPUT_SOURCE_FOLDER} "${CLONE_DIR}/${INPUT_DESTINATION_FOLDER}"
echo "Adding git commit"
git add content/node/
if git status | grep -oq "content/node/"
then
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
echo "Pushing git commit"
git push origin $INPUT_DESTINATION_HEAD_BRANCH
echo "Creating a pull request"
if [ $(gh pr list -H $INPUT_DESTINATION_HEAD_BRANCH | wc -l) -eq 0 ]
then
gh pr create -t "Auto PR from moov-node changes" \
-b "Syncing changes from [moov-node PR]($PR_URL)" \
-B "main" \
-H $INPUT_DESTINATION_HEAD_BRANCH
else
echo "PR Already Created"
fi
else
echo "No changes detected"
fi