|
1
|
#!/bin/bash |
|
2
|
|
|
3
|
IS_CI="${CI:-false}" |
|
4
|
GREP_PATTERN=$1 |
|
5
|
|
|
6
|
if [ "$IS_CI" = true ]; then |
|
7
|
git config --local url."https://github.com/".insteadOf git@github.com: |
|
8
|
git config --local user.name "Medusajs Bot" |
|
9
|
git config --local user.email "core@medusa-commerce.com" |
|
10
|
|
|
11
|
git fetch origin |
|
12
|
git merge --no-edit origin/master |
|
13
|
|
|
14
|
if [ $? -ne 0 ]; then |
|
15
|
echo "Branch has conflicts with master, rolling back test." |
|
16
|
git merge --abort |
|
17
|
fi |
|
18
|
|
|
19
|
git config --local --unset user.name |
|
20
|
git config --local --unset user.email |
|
21
|
git config --local --unset url."https://github.com/".insteadOf |
|
22
|
fi |
|
23
|
|
|
24
|
# Make sure that we are diffing towards the right branch, in github actions this is different |
|
25
|
# depending on whether or not we are creating a pull request or not. |
|
26
|
[ ! -z ${GITHUB_BASE_REF} ] && HAS_BASE=true || HAS_BASE=false |
|
27
|
[ HAS_BASE = true ] && COMPARE="${GITHUB_BASE_REF#refs/heads/}" || COMPARE="develop" |
|
28
|
FILES_COUNT="$(git diff-tree --no-commit-id --name-only -r origin/"$COMPARE" | grep -E "$GREP_PATTERN" -c)" |
|
29
|
|
|
30
|
if [ "$IS_CI" = true ]; then |
|
31
|
# reset to previous state |
|
32
|
git reset --hard $GITHUB_SHA |
|
33
|
fi |
|
34
|
|
|
35
|
if [ "$FILES_COUNT" -eq 0 ]; then |
|
36
|
echo "0 files matching '$GREP_PATTERN'; exiting and marking successful." |
|
37
|
exit 0 |
|
38
|
else |
|
39
|
echo "$FILES_COUNT file(s) matching '$GREP_PATTERN'; continuing." |
|
40
|
fi |