forked from ad-m/github-push-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·50 lines (39 loc) · 1.21 KB
/
start.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
#!/bin/sh
set -e
INPUT_FORCE=${INPUT_FORCE:-false}
INPUT_FORCE_WITH_LEASE=${INPUT_FORCE_WITH_LEASE:-false}
INPUT_SSH=${INPUT_SSH:-false}
INPUT_TAGS=${INPUT_TAGS:-false}
INPUT_DIRECTORY=${INPUT_DIRECTORY:-'.'}
_FORCE_OPTION=''
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}
echo "Push to branch $INPUT_BRANCH";
[ -z "${INPUT_GITHUB_TOKEN}" ] && {
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
exit 1;
};
if ${INPUT_FORCE} && ${INPUT_FORCE_WITH_LEASE}; then
echo 'Please, specify only force or force_with_lease and not both.';
exit 1;
fi
if ${INPUT_FORCE}; then
_FORCE_OPTION='--force'
fi
if ${INPUT_FORCE_WITH_LEASE}; then
_FORCE_OPTION='--force-with-lease'
fi
if ${INPUT_TAGS}; then
_TAGS='--tags'
fi
cd ${INPUT_DIRECTORY}
if ${INPUT_SSH}; then
remote_repo="git@${INPUT_GITHUB_URL}:${REPOSITORY}.git"
else
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
fi
git config --local --add safe.directory ${INPUT_DIRECTORY}
if ${INPUT_FORCE_WITH_LEASE}; then
git push --follow-tags $_FORCE_OPTION $_TAGS;
else
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --verbose --follow-tags $_FORCE_OPTION $_TAGS;
fi