This repository was archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
117 lines (102 loc) · 3.82 KB
/
action.yml
File metadata and controls
117 lines (102 loc) · 3.82 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: 'Checkout with reference'
description: 'Checkout source code with reference option'
inputs:
github_token:
description: 'GitHub token $github.token'
default: ${{ github.token }}
required: false
github_actor:
description: 'GitHub actor. $github.actor'
default: ${{ github.actor }}
required: false
github_repository:
description: 'GitHub repository. $github.repository'
default: ${{ github.repository }}
required: false
branch_name:
description: 'Specify branch_name for checking out'
required: false
sha:
description: 'Specify commit sha for checking out(default: $github.sha)'
required: false
reference_dir:
description: 'Reference repository directory.'
required: true
fetch_lfs:
description: 'Clone with fetching LFS .'
default: false
checkout_dir:
description: 'Name of directory to check out'
default: '.'
depth:
description: 'git clone --depth={} option'
default: ''
ignore_dubious_ownership:
description: 'Not used(deprecated)'
default: true
runs:
using: "composite"
steps:
- uses: actions/github-script@v7
id: script
with:
result-encoding: string
script: |
const actor = encodeURI('${{ inputs.github_actor }}')
const token = encodeURI('${{ inputs.github_token }}')
core.setOutput('actor', actor)
core.setOutput('token', token)
- shell: bash
if: ${{ !env.ACT }}
run: |
if [ -n "$RUNNER_DEBUG" ] || [ -n "$ACTIONS_STEP_DEBUG" ]; then
echo "Enable debug logging"
set -x
fi
echo $GITHUB_ACTION_PATH
source $GITHUB_ACTION_PATH/try.sh
try_till_success curl -s 'https://github.com' > /dev/null
GITHUB_ACTOR='${{ steps.script.outputs.actor }}'
GITHUB_TOKEN='${{ steps.script.outputs.token }}'
export __SHA=${{ inputs.sha || github.sha }}
if [ ! -z "${{ inputs.branch_name }}" ]; then
# Remove "refs/heads/" at head if exists it
__BRANCH=${{ inputs.branch_name }}
__BRANCH=${__BRANCH#refs/heads/}
# Override sha value if branch_name is presented.
__SHA=$(try_till_success /usr/bin/git ls-remote https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${{ inputs.github_repository }}.git | grep -E "\srefs/heads/${__BRANCH}$" | cut -f 1 )
fi
if ! ${{ inputs.fetch_lfs }}; then
export GIT_LFS_SKIP_SMUDGE=1
fi
DEPTH=''
if [ ! -z "${{ inputs.depth }}" ]; then
DEPTH=--depth=${{ inputs.depth }}
fi
if [ ! -z "${{ inputs.reference_dir }}" ]; then
REFERENCE_IF_ABLE="--reference-if-able=${{ inputs.reference_dir }}"
fi
try_till_success \
/usr/bin/git clone \
$DEPTH \
$REFERENCE_IF_ABLE \
https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${{ inputs.github_repository }}.git \
${{ inputs.checkout_dir }}
CHECKOUT_FULL_PATH="$(pwd)/${{ inputs.checkout_dir }}"
CHECKOUT_FULL_PATH="$(realpath $CHECKOUT_FULL_PATH)"
if [ $(git config --global --get-all safe.directory | grep -c "${CHECKOUT_FULL_PATH}$") -eq 0 ]; then
/usr/bin/git config --global --add safe.directory "${CHECKOUT_FULL_PATH}"
fi
pushd ${{ inputs.checkout_dir }}
if [ ! -z "$__BRANCH" ]; then
/usr/bin/git checkout -B $__BRANCH origin/$__BRANCH
else
try_till_success /usr/bin/git fetch $DEPTH origin $__SHA
/usr/bin/git reset --hard FETCH_HEAD
fi
/usr/bin/git config --local gc.auto 0
/usr/bin/git config --local user.name "${GITHUB_ACTOR}"
/usr/bin/git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com"
popd
unset GIT_LFS_SKIP_SMUDGE
unset __SHA