-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
entrypoint.sh
executable file
·85 lines (71 loc) · 2.25 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
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
function checkout {
local REF=
local LOCAL_BRANCH=
local LOCAL_BRANCH_NAME=
local BASE_BRANCH=
if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
return
fi
LOCAL_BRANCH_NAME=$GITHUB_HEAD_REF
case $GITHUB_EVENT_NAME in
pull_request)
REF=$GITHUB_REF
LOCAL_BRANCH=$GITHUB_HEAD_REF
BASE_BRANCH=$GITHUB_BASE_REF
if [[ ! $LOCAL_BRANCH || ! $BASE_BRANCH ]]; then
echo "Missing head or base ref env variables; aborting"
exit 1
fi
LOCAL_BRANCH_NAME=pull/${LOCAL_BRANCH_NAME}
;;
push)
REF=${GITHUB_REF/refs\/heads\//}
LOCAL_BRANCH=${REF}
;;
tag)
REF=${GITHUB_REF/refs\/tags\//}
LOCAL_BRANCH=${REF}
;;
*)
echo "Unable to handle events of type $GITHUB_EVENT_NAME; aborting"
exit 1
esac
if [ -d ".git" ];then
echo "Updating and fetching from canonical repository"
if [[ $(git remote) =~ origin ]];then
git remote remove origin
fi
git remote add origin https://github.com/"${GITHUB_REPOSITORY}"
git fetch origin
else
echo "Cloning repository"
git clone https://github.com/"${GITHUB_REPOSITORY}" .
fi
if [[ "$REF" == "$LOCAL_BRANCH" ]];then
echo "Checking out ref ${REF}"
git checkout "$REF"
else
echo "Checking out branch ${BASE_BRANCH}"
git checkout "${BASE_BRANCH}"
echo "Fetching target ref ${REF}"
git fetch origin "${REF}":"${LOCAL_BRANCH_NAME}"
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
git checkout "${LOCAL_BRANCH_NAME}"
fi
}
git config --global --add safe.directory /github/workspace
checkout
DIFF=
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]];then
echo "Preparing file diff"
DIFF=$(git diff --name-only "$GITHUB_BASE_REF"...HEAD)
fi
if [[ "$DIFF" != "" ]];then
echo "Found changes in the following files:"
echo "${DIFF}"
fi
# This variable is deliberately unquoted so that it can be properly processed on the other side.
# shellcheck disable=SC2086
/action/main.js ${DIFF}