-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.sh
57 lines (41 loc) · 1.3 KB
/
action.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
#!/bin/bash
# Pull changes from another repository
set -u # script fails if trying to access to an undefined variable
####### Inputs
SOURCE_REPO_NAME="$1"
SOURCE_FOLDER_PATH="$2"
SOURCE_BRANCH="$3"
TARGET_BRANCH="$4"
GITHUB_USERNAME="$5"
GITHUB_EMAIL="$6"
#######
SOURCE_REPO_URL="https://github.com/$SOURCE_REPO_NAME.git"
echo "Check if repo $SOURCE_REPO_URL exists"
git ls-remote "$SOURCE_REPO_URL" -q
if [[ $? -ne 0 ]]
then
echo "The repository $SOURCE_REPO_NAME does not exist."
exit 1
fi
echo "Update git configuration"
git config user.name "$GITHUB_USERNAME"
git config user.email "$GITHUB_EMAIL"
echo "Get latest files for $SOURCE_FOLDER_PATH"
BRANCH_WITH_CHANGES="source/$SOURCE_BRANCH"
git remote add -f source "$SOURCE_REPO_URL"
git fetch source
git checkout -b upstream "$BRANCH_WITH_CHANGES"
echo "Squelching git filter-branch warning"
export FILTER_BRANCH_SQUELCH_WARNING=1
git filter-branch --prune-empty --subdirectory-filter "$SOURCE_FOLDER_PATH" "$BRANCH_WITH_CHANGES"
git checkout "$TARGET_BRANCH"
echo "Check if the example has changed"
if git diff "$TARGET_BRANCH".."$BRANCH_WITH_CHANGES" --exit-code -- ':!.github'
then
echo "The example has not changed"
else
echo "Merging changes..."
git reset --hard "$BRANCH_WITH_CHANGES"
echo "Pushing changes..."
git push -f
fi