-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
165 lines (154 loc) · 6.42 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Tutorial to use with: https://github.com/andry81-devops/github-action-extensions
#
name: git-checkout-extension
description: 'GitHub composite action extension of `actions/checkout` action'
branding:
icon: upload
color: purple
inputs:
# CAUTION:
# The `inputs` is derived from the https://github.com/actions/checkout action script.
#
repository:
default: ${{ github.repository }}
ref:
required: false
token:
default: ${{ github.token }}
ssh-key:
required: false
ssh-known-hosts:
required: false
ssh-strict:
default: true
persist-credentials:
default: true
path:
required: false
clean:
default: true
fetch-depth:
default: 1
lfs:
default: false
submodules:
default: false
set-safe-directory:
default: true
github-server-url:
required: false
# available: v3 | v2
actions--checkout-ref:
required: false
default: v3
mkdir-p:
default: ''
runs:
using: "composite"
steps:
- name: '[git-checkout-extension][01] check repository on existence and has a branch reference: `${{ inputs.repository }}`'
id: check-repo-exists-and-has-ref
#continue-on-error: true
shell: bash
run: |
### [git-checkout-extension][01] check repository on existence and has a branch reference: `${{ inputs.repository }}`
# CAUTION: must be with a token, otherwise will fail on a private repository
if [[ -n "${{ inputs.ref }}" ]]; then
# suppress not zero exit code
{ git ls-remote -q --exit-code "https://${{ inputs.token }}@github.com/${{ inputs.repository }}" "${{ inputs.ref }}" > /dev/null 2>&1; last_error=$?; } || (( 1 ))
else
# suppress not zero exit code
{ git ls-remote -q --exit-code "https://${{ inputs.token }}@github.com/${{ inputs.repository }}" > /dev/null 2>&1; last_error=$?; } || (( 1 ))
fi
if (( ! last_error )); then
echo "is-repo-exists-and-has-ref=true" >> "$GITHUB_OUTPUT"
else
echo "is-repo-exists-and-has-ref=false" >> "$GITHUB_OUTPUT"
fi
# CAUTION:
#
# Use copmarison with the string in the `if` expression to temporary workaround the issue:
#
# `Boolean inputs are not actually booleans` : https://github.com/actions/runner/issues/1483
#
- name: "[git-checkout-extension][02] if: ${{ (steps.check-repo-exists-and-has-ref.outputs.is-repo-exists-and-has-ref == 'true') && (inputs.actions--checkout-ref == 'v3') }}"
#if: ${{ steps.check-repo-exists-and-has-ref.conclusion == 'success' }}
if: ${{ (steps.check-repo-exists-and-has-ref.outputs.is-repo-exists-and-has-ref == 'true') && (inputs.actions--checkout-ref == 'v3') }}
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
token: ${{ inputs.token }}
ssh-key: ${{ inputs.ssh-key }}
ssh-known-hosts: ${{ inputs.ssh-known-hosts }}
ssh-strict: ${{ inputs.ssh-strict }}
persist-credentials: ${{ inputs.persist-credentials }}
path: ${{ inputs.path }}
clean: ${{ inputs.clean }}
fetch-depth: ${{ inputs.fetch-depth }}
lfs: ${{ inputs.lfs }}
submodules: ${{ inputs.submodules }}
set-safe-directory: ${{ inputs.set-safe-directory }}
github-server-url: ${{ inputs.github-server-url }}
- name: "[git-checkout-extension][03] if: ${{ (steps.check-repo-exists-and-has-ref.outputs.is-repo-exists-and-has-ref == 'true') && (inputs.actions--checkout-ref == 'v2') }}"
if: ${{ (steps.check-repo-exists-and-has-ref.outputs.is-repo-exists-and-has-ref == 'true') && (inputs.actions--checkout-ref == 'v2') }}
uses: actions/checkout@v2
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
token: ${{ inputs.token }}
ssh-key: ${{ inputs.ssh-key }}
ssh-known-hosts: ${{ inputs.ssh-known-hosts }}
ssh-strict: ${{ inputs.ssh-strict }}
persist-credentials: ${{ inputs.persist-credentials }}
path: ${{ inputs.path }}
clean: ${{ inputs.clean }}
fetch-depth: ${{ inputs.fetch-depth }}
lfs: ${{ inputs.lfs }}
submodules: ${{ inputs.submodules }}
set-safe-directory: ${{ inputs.set-safe-directory }}
- name: '[git-checkout-extension][04] working copy initialization: `${{ inputs.path }}`'
#if: ${{ steps.check-repo-exists-and-has-ref.conclusion != 'success' }}
if: ${{ steps.check-repo-exists-and-has-ref.outputs.is-repo-exists-and-has-ref != 'true' }}
shell: bash
run: |
### [git-checkout-extension][04] working copy initialization: `${{ inputs.path }}`
inputs_path='${{ inputs.path }}'
function call()
{
echo ">$@"
"$@"
}
if [[ ! -e "$GITHUB_WORKSPACE${inputs_path:+/}$inputs_path" ]]; then
call mkdir -p "$GITHUB_WORKSPACE${inputs_path:+/}$inputs_path" || exit
fi
if [[ ! -e "$GITHUB_WORKSPACE${inputs_path:+/}$inputs_path/.git" ]]; then
call pushd "$GITHUB_WORKSPACE${inputs_path:+/}$inputs_path" && {
call git init || exit
call git remote add origin "https://github.com/${{ inputs.repository }}" || exit
if [[ -n "${{ inputs.ref }}" ]]; then
call git branch -m "${{ inputs.ref }}" || exit
fi
call popd
}
fi
- name: '[git-checkout-extension][05] working copy directories allocation'
if: ${{ inputs.mkdir-p != '' }}
shell: bash
run: |
### [git-checkout-extension][05] working copy directories allocation
inputs_mkdir_p=(${{ inputs.mkdir-p }})
inputs_path='${{ inputs.path }}'
function call()
{
echo ">$@"
"$@"
}
call pushd "$GITHUB_WORKSPACE${inputs_path:+/}$inputs_path" && {
for arg in "${inputs_mkdir_p[@]}"; do
if [[ ! -e "$arg" ]]; then
call mkdir -p "$arg" || exit
fi
done
call popd
}