-
Notifications
You must be signed in to change notification settings - Fork 42
/
entrypoint.sh
executable file
·77 lines (69 loc) · 3.1 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
#!/usr/bin/env bash
set -e
if [[ "${DEBUG}" -eq "true" ]]; then
set -x
fi
git config --global --add safe.directory /github/workspace
GIT_USERNAME=${INPUT_GIT_USERNAME:-${GIT_USERNAME:-"git"}}
REMOTE=${INPUT_REMOTE:-"$*"}
REMOTE_NAME=${INPUT_REMOTE_NAME:-"mirror"}
GIT_SSH_PRIVATE_KEY=${INPUT_GIT_SSH_PRIVATE_KEY}
GIT_SSH_PUBLIC_KEY=${INPUT_GIT_SSH_PUBLIC_KEY}
GIT_REF=${INPUT_GIT_REF}
GIT_PUSH_ARGS=${INPUT_GIT_PUSH_ARGS:-"--tags --force --prune"}
GIT_SSH_NO_VERIFY_HOST=${INPUT_GIT_SSH_NO_VERIFY_HOST}
GIT_SSH_KNOWN_HOSTS=${INPUT_GIT_SSH_KNOWN_HOSTS}
HAS_CHECKED_OUT="$(git rev-parse --is-inside-work-tree 2>/dev/null || /bin/true)"
if [[ "${HAS_CHECKED_OUT}" != "true" ]]; then
echo "WARNING: repo not checked out; attempting checkout" > /dev/stderr
echo "WARNING: this may result in missing commits in the remote mirror" > /dev/stderr
echo "WARNING: this behavior is deprecated and will be removed in a future release" > /dev/stderr
echo "WARNING: to remove this warning add the following to your yml job steps:" > /dev/stderr
echo " - uses: actions/checkout@v3" > /dev/stderr
if [[ "${SRC_REPO}" -eq "" ]]; then
echo "WARNING: SRC_REPO env variable not defined" > /dev/stderr
SRC_REPO="https://github.com/${GITHUB_REPOSITORY}.git" > /dev/stderr
echo "Assuming source repo is ${SRC_REPO}" > /dev/stderr
fi
git init > /dev/null
git remote add origin "${SRC_REPO}"
git fetch --all > /dev/null 2>&1
fi
git config --global credential.username "${GIT_USERNAME}"
if [[ "${GIT_SSH_PRIVATE_KEY}" != "" ]]; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "${GIT_SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
if [[ "${GIT_SSH_PUBLIC_KEY}" != "" ]]; then
echo "${GIT_SSH_PUBLIC_KEY}" > ~/.ssh/id_rsa.pub
chmod 600 ~/.ssh/id_rsa.pub
fi
chmod 600 ~/.ssh/id_rsa
if [[ "${GIT_SSH_KNOWN_HOSTS}" != "" ]]; then
echo "${GIT_SSH_KNOWN_HOSTS}" > ~/.ssh/known_hosts
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=~/.ssh/known_hosts"
else
if [[ "${GIT_SSH_NO_VERIFY_HOST}" != "true" ]]; then
echo "WARNING: no known_hosts set and host verification is enabled (the default)"
echo "WARNING: this job will fail due to host verification issues"
echo "Please either provide the GIT_SSH_KNOWN_HOSTS or GIT_SSH_NO_VERIFY_HOST inputs"
exit 1
else
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
fi
fi
else
git config --global core.askPass /cred-helper.sh
git config --global credential.helper cache
fi
git remote add ${REMOTE_NAME} "${REMOTE}"
if [[ "${INPUT_PUSH_ALL_REFS}" != "false" ]]; then
eval git push ${GIT_PUSH_ARGS} ${REMOTE_NAME} "\"refs/remotes/origin/*:refs/heads/*\""
else
if [[ "${HAS_CHECKED_OUT}" != "true" ]]; then
echo "FATAL: You must upgrade to using actions inputs instead of args: to push a single branch" > /dev/stderr
exit 1
else
eval git push -u ${GIT_PUSH_ARGS} ${REMOTE_NAME} "${GIT_REF}"
fi
fi