forked from TheXTech/checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
42 lines (36 loc) · 1.21 KB
/
action.yml
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
name: 'Checkout'
description: 'Checks out correct branch or pull request merge'
branding:
icon: 'download'
color: 'blue'
runs:
using: 'composite'
steps:
- shell: bash
run: |
retry() {
for i in {1..10}; do
if "$@"; then
return 0
else
sleep "${i}"
fi
done
"$@"
}
wd=$(pwd)
git version
git config --global --add safe.directory "${wd}"
git config --global advice.detachedHead false
git init -b _initial_branch
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
git config --local gc.auto 0
if [[ "${GITHUB_REF}" == "refs/heads/"* ]]; then
branch="${GITHUB_REF#refs/heads/}"
remote_ref="refs/remotes/origin/${branch}"
retry git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "+${GITHUB_SHA}:${remote_ref}"
retry git checkout --force -B "${branch}" "${remote_ref}"
else
retry git fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "+${GITHUB_SHA}:${GITHUB_REF}"
retry git checkout --force "${GITHUB_REF}"
fi