A shareable package of CircleCI configuration to integrate with git-shallow-clone, written by guitarrapc
CommunityBuildUse CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1Add the orbs stanza below your version, invoking the orb:
1
2
orbs:
git-shallow-clone: guitarrapc/git-shallow-clone@2.8.0Use git-shallow-clone elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Simple git shallow clone instead of checkout. You can change depth and fetch_depth, but I do recommend set fetch_depth larger than 1. If you set fetch_depth 1, you will find build failed when new commit was pushed. Default value of `fetch_depth` is 10 to cover re-build after several commit. # No options will clone depth 1 and fetch depth 10. - git-shallow-clone/checkout # Clone the repository to specific path `src`. - git-shallow-clone/checkout: path: src # Set fetch_depth: 1 to minimize fetch time. - git-shallow-clone/checkout: fetch_depth: 1 # Change depth:5 for some reason. - git-shallow-clone/checkout: depth: 5 fetch_depth: 5 # Enable ssh key scan for github.com and bitbucket.org. Omit this parameter use embedded known ssh key by default. - git-shallow-clone/checkout: keyscan_github: true keyscan_bitbucket: true # Skip tag fetch. - git-shallow-clone/checkout: no_tags: true # Shallow clone then update submodules. - git-shallow-clone/checkout - run: git submodule update --init --recursive
1
2
3
4
5
6
7
version: '2.1'
orbs:
git-shallow-clone: guitarrapc/git-shallow-clone@x.y.z
workflows:
build:
jobs:
- git-shallow-clone/checkout
Advanced git shallow clone instead of checkout with clone_options and fetch_options. Make sure some options is exclusive each other, you should follow to official git documentation. e.g. `--depth N` cannot use with `--shallow-since`. # No options will clone depth 1 and fetch depth 10. - git-shallow-clone/checkout_advanced # Clone the repository to specific path `src`. - git-shallow-clone/checkout_advanced path: src # See verbose log on clone. - git-shallow-clone/checkout_advanced clone_options: '--depth 1 --verbose'. # Use --shallow-since for clone timing, but not for fetch timing. - git-shallow-clone/checkout_advanced clone_options: '--shallow-since "5 days ago"' # Use --shallow-since for fetch timing, but not for clone timing. - git-shallow-clone/checkout_advanced fetch_options: '--shallow-since "5 days ago"' # Use --no-tags to skip tag fetch. - git-shallow-clone/checkout_advanced fetch_options: '--depth 10 --no-tags' # Skip tag fetch. - git-shallow-clone/checkout_advanced fetch_options: '--depth 10 --no-tags' tag_fetch_options: '--no-tags' # Shallow clone then update submodules. - git-shallow-clone/checkout_advanced - run: git submodule update --init --recursive
1
2
3
4
5
6
7
8
9
version: '2.1'
orbs:
git-shallow-clone: guitarrapc/git-shallow-clone@x.y.z
workflows:
build:
jobs:
- git-shallow-clone/checkout_advanced:
clone_options: '--shallow-since "5 days ago"'
fetch_options: '--shallow-since "5 days ago"'
Provides git shallow clone instead of full clone. This command is for simple usage when you don't need options for clone, fetch and tag fetch.
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
depth Limit fetch depth to the specified number of commit from a remote branch history. Refer git fetch documentation for more information.
| Limit fetch depth to the specified number of commit from a remote branch history. Refer git fetch documentation for more information.
| No | 1 type: integer | integer |
fetch_depth Addtional fetch depth to the specified number of commit from a remote branch history. Pass more number then depth when you want to check futher commit history.
| Addtional fetch depth to the specified number of commit from a remote branch history. Pass more number then depth when you want to check futher commit history.
| No | 10 type: integer | integer |
keyscan_bitbucket Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
| Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
| No | false type: boolean | boolean |
keyscan_github Pass `true` to dynamically get ssh-rsa from `github.com`.
| Pass `true` to dynamically get ssh-rsa from `github.com`.
| No | false type: boolean | boolean |
no_tags true to add '--no-tags' when fetching. As git not offer tag depth, we only able to control fetch all tags or not. This enable you to stop fetch tags when you have vast numbers of tags during specified fetch depth. In other word, if you need tag then fetch specified tags manually when use 'without_tag: true'.
| true to add '--no-tags' when fetching. As git not offer tag depth, we only able to control fetch all tags or not. This enable you to stop fetch tags when you have vast numbers of tags during specified fetch depth. In other word, if you need tag then fetch specified tags manually when use 'without_tag: true'.
| No | false type: boolean | boolean |
path Checkout directory (default: job working_directory)
| Checkout directory (default: job working_directory)
| No | . type: string | string |
Provides git shallow clone instead of full clone. This command is for advaned usage when you need options for clone, fetch and tag fetch.
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
clone_options git clone options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"'
| git clone options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"'
| No | '--depth 1' type: string | string |
fetch_options git fetch options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"' you don't need set '--force' option as it already set by default. in case of tag, add '--no-tags' on this option and tag_fetch_options.
| git fetch options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"' you don't need set '--force' option as it already set by default. in case of tag, add '--no-tags' on this option and tag_fetch_options.
| No | '--depth 10' type: string | string |
keyscan_bitbucket Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
| Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
| No | false type: boolean | boolean |
keyscan_github Pass `true` to dynamically get ssh-rsa from `github.com`.
| Pass `true` to dynamically get ssh-rsa from `github.com`.
| No | false type: boolean | boolean |
path Checkout directory (default: job working_directory)
| Checkout directory (default: job working_directory)
| No | . type: string | string |
tag_fetch_options This option apply when git operation is tag. Use 'fetch_options' instead if pr and other git operation. Additional git fetch options you want to add specifically for tags such as '--tags' or '--no-tags'. Default value is '--tags'
| This option apply when git operation is tag. Use 'fetch_options' instead if pr and other git operation. Additional git fetch options you want to add specifically for tags such as '--tags' or '--no-tags'. Default value is '--tags'
| No | '--tags' type: string | string |
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Provides git shallow clone instead of full clone. Supporting trigger for tag, pull_request and push, works on Alpine, Debian, Ubuntu, and macOS.
What's shallow clone? - see https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---depthltdepthgt Provied commands: - checkout - checkout_advanced
requirement: git
display:
source_url: https://github.com/guitarrapc/git-shallow-clone-orb
commands:
checkout:
description: |
Provides git shallow clone instead of full clone. This command is for simple usage when you don't need options for clone, fetch and tag fetch.
parameters:
depth:
default: 1
description: |
Limit fetch depth to the specified number of commit from a remote branch history. Refer git fetch documentation for more information.
type: integer
fetch_depth:
default: 10
description: |
Addtional fetch depth to the specified number of commit from a remote branch history. Pass more number then depth when you want to check futher commit history.
type: integer
keyscan_bitbucket:
default: false
description: |
Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
type: boolean
keyscan_github:
default: false
description: |
Pass `true` to dynamically get ssh-rsa from `github.com`.
type: boolean
no_tags:
default: false
description: |
true to add '--no-tags' when fetching. As git not offer tag depth, we only able to control fetch all tags or not. This enable you to stop fetch tags when you have vast numbers of tags during specified fetch depth. In other word, if you need tag then fetch specified tags manually when use 'without_tag: true'.
type: boolean
path:
default: .
description: |
Checkout directory (default: job working_directory)
type: string
steps:
- run:
command: |
#!/bin/sh
set -ex
# Workaround old docker images with incorrect $HOME
# check https://github.com/docker/docker/issues/2968 for details
if [ "${HOME}" = "/" ]; then
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
fi
# known_hosts / id_rsa
export SSH_CONFIG_DIR=${SSH_CONFIG_DIR:-"${HOME}/.ssh"}
echo "Using SSH Config Dir '$SSH_CONFIG_DIR'"
git --version
mkdir -p "$SSH_CONFIG_DIR"
chmod 0700 "$SSH_CONFIG_DIR"
if [ -x "$(command -v ssh-keyscan)" ] && ([ "<< parameters.keyscan_github >>" == "true" ] || [ "<< parameters.keyscan_bitbucket >>" == "true" ]); then
if [ "<< parameters.keyscan_github >>" == "true" ]; then
ssh-keyscan -H github.com >> "$SSH_CONFIG_DIR/known_hosts"
fi
if [ "<< parameters.keyscan_bitbucket >>" == "true" ]; then
ssh-keyscan -H bitbucket.org >> "$SSH_CONFIG_DIR/known_hosts"
fi
fi
# see: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
if [ "<< parameters.keyscan_github >>" != "true" ]; then
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=
' >> "$SSH_CONFIG_DIR/known_hosts"
fi
# see: https://bitbucket.org/blog/ssh-host-key-changes
if [ "<< parameters.keyscan_bitbucket >>" != "true" ]; then
echo 'bitbucket.org ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPIQmuzMBuKdWeF4+a2sjSSpBK0iqitSQ+5BM9KhpexuGt20JpTVM7u5BDZngncgrqDMbWdxMWWOGtZ9UgbqgZE=
bitbucket.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIazEu89wgQZ4bqs3d63QSMzYVa0MuJ2e2gKTKqu+UUO
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQeJzhupRu0u0cdegZIa8e86EG2qOCsIsD1Xw0xSeiPDlCr7kq97NLmMbpKTX6Esc30NuoqEEHCuc7yWtwp8dI76EEEB1VqY9QJq6vk+aySyboD5QF61I/1WeTwu+deCbgKMGbUijeXhtfbxSxm6JwGrXrhBdofTsbKRUsrN1WoNgUa8uqN1Vx6WAJw1JHPhglEGGHea6QICwJOAr/6mrui/oB7pkaWKHj3z7d1IC4KWLtY47elvjbaTlkN04Kc/5LFEirorGYVbt15kAUlqGM65pk6ZBxtaO3+30LVlORZkxOh+LKL/BvbZ/iRNhItLqNyieoQj/uh/7Iv4uyH/cV/0b4WDSd3DptigWq84lJubb9t/DnZlrJazxyDCulTmKdOR7vs9gMTo+uoIrPSb8ScTtvw65+odKAlBj59dhnVp9zd7QUojOpXlL62Aw56U4oO+FALuevvMjiWeavKhJqlR7i5n9srYcrNV7ttmDw7kf/97P5zauIhxcjX+xHv4M=
' >> "$SSH_CONFIG_DIR/known_hosts"
fi
echo 'gitlab.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=
' >> "$SSH_CONFIG_DIR/known_hosts"
chmod 0600 "$SSH_CONFIG_DIR/known_hosts"
rm -f "$SSH_CONFIG_DIR/id_rsa"
(umask 077; touch "$SSH_CONFIG_DIR/id_rsa")
printf "%s" "$CHECKOUT_KEY" > "$SSH_CONFIG_DIR/id_rsa"
chmod 0600 "$SSH_CONFIG_DIR/id_rsa"
if (: "${CHECKOUT_KEY_PUBLIC?}") 2>/dev/null; then
rm -f "$SSH_CONFIG_DIR/id_rsa.pub"
printf "%s" "$CHECKOUT_KEY_PUBLIC" > "$SSH_CONFIG_DIR/id_rsa.pub"
fi
export GIT_SSH_COMMAND='ssh -i "$SSH_CONFIG_DIR/id_rsa" -o UserKnownHostsFile="$SSH_CONFIG_DIR/known_hosts"'
# use git+ssh instead of https
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true
# Define Tag args
if [ -n "$CIRCLE_TAG" ]; then
# only tags operation have default --tags. others will no tag options
clone_tag_args=
fetch_tag_args="--tags"
fi
if [ '<< parameters.no_tags >>' == 'true' ]; then
clone_tag_args="--no-tags"
fetch_tag_args="--no-tags"
fi
# Replace "~" in `$CIRCLE_WORKING_DIRECTORY` to `$HOME`
if [ "$0" == "/bin/bash" ]; then
working_directory=${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}
else
working_directory=$(echo "$CIRCLE_WORKING_DIRECTORY" | sed -e "s|^~|$HOME|g")
fi
# Checkout. SourceCaching? or not.
if [ -e "$working_directory/<< parameters.path >>/.git" ]; then
echo 'Fetching into existing repository'
existing_repo='true'
cd "$working_directory/<< parameters.path >>"
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
echo 'Cloning git repository'
existing_repo='false'
mkdir -p "$working_directory/<< parameters.path >>"
cd "$working_directory/<< parameters.path >>"
git clone ${clone_tag_args} --depth << parameters.depth >> $CIRCLE_REPOSITORY_URL .
fi
# NOTE: Original checkout fetch only if SourceCaching, but we fetch always for depth selection.
echo 'Fetching from remote repository'
if [ -n "$CIRCLE_TAG" ]; then
git fetch ${fetch_tag_args} --depth << parameters.fetch_depth >> --force --tags origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
elif echo $CIRCLE_BRANCH | grep -E ^pull\/[0-9]+/head$ > /dev/null; then
# pull request called from api. Input should be `pull/123/head` see detail for https://github.com/guitarrapc/git-shallow-clone-orb/issues/34
git fetch ${fetch_tag_args} --depth << parameters.fetch_depth >> --force origin "+refs/${CIRCLE_BRANCH}:remotes/origin/${CIRCLE_BRANCH}"
else
git fetch ${fetch_tag_args} --depth << parameters.fetch_depth >> --force origin +refs/heads/${CIRCLE_BRANCH}:refs/remotes/origin/${CIRCLE_BRANCH}
fi
# Check the commit ID of the checked out code
if [ -n "$CIRCLE_TAG" ]; then
echo 'Checking out tag'
git checkout --force "$CIRCLE_TAG"
git reset --hard "$CIRCLE_SHA1" # move to triggered SHA
elif [ -n "$CIRCLE_BRANCH" ] && [ "$CIRCLE_BRANCH" != 'HEAD' ]; then
echo 'Checking out branch'
git checkout --force -B "$CIRCLE_BRANCH"
git reset --hard "$CIRCLE_SHA1" # move to triggered SHA
git --no-pager log --no-color -n 1 --format='HEAD is now at %h %s'
fi
name: Checkout code shallow
checkout_advanced:
description: |
Provides git shallow clone instead of full clone. This command is for advaned usage when you need options for clone, fetch and tag fetch.
parameters:
clone_options:
default: --depth 1
description: |
git clone options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"'
type: string
fetch_options:
default: --depth 10
description: |
git fetch options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"' you don't need set '--force' option as it already set by default. in case of tag, add '--no-tags' on this option and tag_fetch_options.
type: string
keyscan_bitbucket:
default: false
description: |
Pass `true` to dynamically get ssh-rsa from `bitbucket.org`.
type: boolean
keyscan_github:
default: false
description: |
Pass `true` to dynamically get ssh-rsa from `github.com`.
type: boolean
path:
default: .
description: |
Checkout directory (default: job working_directory)
type: string
tag_fetch_options:
default: --tags
description: |
This option apply when git operation is tag. Use 'fetch_options' instead if pr and other git operation. Additional git fetch options you want to add specifically for tags such as '--tags' or '--no-tags'. Default value is '--tags'
type: string
steps:
- run:
command: |
#!/bin/sh
set -ex
# Workaround old docker images with incorrect $HOME
# check https://github.com/docker/docker/issues/2968 for details
if [ "${HOME}" = "/" ]; then
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
fi
# known_hosts / id_rsa
export SSH_CONFIG_DIR=${SSH_CONFIG_DIR:-"${HOME}/.ssh"}
echo "Using SSH Config Dir '$SSH_CONFIG_DIR'"
git --version
mkdir -p "$SSH_CONFIG_DIR"
chmod 0700 "$SSH_CONFIG_DIR"
if [ -x "$(command -v ssh-keyscan)" ] && ([ "<< parameters.keyscan_github >>" == "true" ] || [ "<< parameters.keyscan_bitbucket >>" == "true" ]); then
if [ "<< parameters.keyscan_github >>" == "true" ]; then
ssh-keyscan -H github.com >> "$SSH_CONFIG_DIR/known_hosts"
fi
if [ "<< parameters.keyscan_bitbucket >>" == "true" ]; then
ssh-keyscan -H bitbucket.org >> "$SSH_CONFIG_DIR/known_hosts"
fi
fi
# see: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
if [ "<< parameters.keyscan_github >>" != "true" ]; then
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl
github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=
github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=
' >> "$SSH_CONFIG_DIR/known_hosts"
fi
# see: https://bitbucket.org/blog/ssh-host-key-changes
if [ "<< parameters.keyscan_bitbucket >>" != "true" ]; then
echo 'bitbucket.org ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPIQmuzMBuKdWeF4+a2sjSSpBK0iqitSQ+5BM9KhpexuGt20JpTVM7u5BDZngncgrqDMbWdxMWWOGtZ9UgbqgZE=
bitbucket.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIazEu89wgQZ4bqs3d63QSMzYVa0MuJ2e2gKTKqu+UUO
bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDQeJzhupRu0u0cdegZIa8e86EG2qOCsIsD1Xw0xSeiPDlCr7kq97NLmMbpKTX6Esc30NuoqEEHCuc7yWtwp8dI76EEEB1VqY9QJq6vk+aySyboD5QF61I/1WeTwu+deCbgKMGbUijeXhtfbxSxm6JwGrXrhBdofTsbKRUsrN1WoNgUa8uqN1Vx6WAJw1JHPhglEGGHea6QICwJOAr/6mrui/oB7pkaWKHj3z7d1IC4KWLtY47elvjbaTlkN04Kc/5LFEirorGYVbt15kAUlqGM65pk6ZBxtaO3+30LVlORZkxOh+LKL/BvbZ/iRNhItLqNyieoQj/uh/7Iv4uyH/cV/0b4WDSd3DptigWq84lJubb9t/DnZlrJazxyDCulTmKdOR7vs9gMTo+uoIrPSb8ScTtvw65+odKAlBj59dhnVp9zd7QUojOpXlL62Aw56U4oO+FALuevvMjiWeavKhJqlR7i5n9srYcrNV7ttmDw7kf/97P5zauIhxcjX+xHv4M=
' >> "$SSH_CONFIG_DIR/known_hosts"
fi
echo 'gitlab.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=
' >> "$SSH_CONFIG_DIR/known_hosts"
chmod 0600 "$SSH_CONFIG_DIR/known_hosts"
rm -f "$SSH_CONFIG_DIR/id_rsa"
(umask 077; touch "$SSH_CONFIG_DIR/id_rsa")
printf "%s" "$CHECKOUT_KEY" > "$SSH_CONFIG_DIR/id_rsa"
chmod 0600 "$SSH_CONFIG_DIR/id_rsa"
if (: "${CHECKOUT_KEY_PUBLIC?}") 2>/dev/null; then
rm -f "$SSH_CONFIG_DIR/id_rsa.pub"
printf "%s" "$CHECKOUT_KEY_PUBLIC" > "$SSH_CONFIG_DIR/id_rsa.pub"
fi
# use git+ssh instead of https
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true
# Expand `$CIRCLE_WORKING_DIRECTORY`'s ~ to `$HOME`
if [ "$0" == "/bin/sh" ]; then
working_directory=$(echo "$CIRCLE_WORKING_DIRECTORY" | sed -e "s|^~|$HOME|g")
else
working_directory=${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}
fi
# Checkout. SourceCaching? or not.
if [ -e "$working_directory/<< parameters.path >>/.git" ]; then
echo 'Fetching into existing repository'
existing_repo='true'
cd "$working_directory/<< parameters.path >>"
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
echo 'Cloning git repository'
existing_repo='false'
mkdir -p "$working_directory/<< parameters.path >>"
cd "$working_directory/<< parameters.path >>"
git clone << parameters.clone_options >> $CIRCLE_REPOSITORY_URL .
fi
# NOTE: Original checkout fetch only if SourceCaching, but we fetch always for depth selection.
echo 'Fetching from remote repository'
if [ -n "$CIRCLE_TAG" ]; then
git fetch << parameters.tag_fetch_options >> << parameters.fetch_options >> --force --tags origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
elif echo $CIRCLE_BRANCH | grep -E ^pull\/[0-9]+/head$ > /dev/null; then
# pull request called from api. Input should be `pull/123/head` see detail for https://github.com/guitarrapc/git-shallow-clone-orb/issues/34
git fetch << parameters.tag_fetch_options >> << parameters.fetch_options >> --force origin "+refs/${CIRCLE_BRANCH}:remotes/origin/${CIRCLE_BRANCH}"
else
git fetch << parameters.fetch_options >> --force origin +refs/heads/${CIRCLE_BRANCH}:refs/remotes/origin/${CIRCLE_BRANCH}
fi
# Check the commit ID of the checked out code
if [ -n "$CIRCLE_TAG" ]; then
echo 'Checking out tag'
git checkout --force "$CIRCLE_TAG"
git reset --hard "$CIRCLE_SHA1" # move to triggered SHA
elif [ -n "$CIRCLE_BRANCH" ] && [ "$CIRCLE_BRANCH" != 'HEAD' ]; then
echo 'Checking out branch'
git checkout --force -B "$CIRCLE_BRANCH"
git reset --hard "$CIRCLE_SHA1" # move to triggered SHA
git --no-pager log --no-color -n 1 --format='HEAD is now at %h %s'
fi
name: Checkout code shallow
examples:
checkout:
description: |
Simple git shallow clone instead of checkout.
You can change depth and fetch_depth, but I do recommend set fetch_depth larger than 1.
If you set fetch_depth 1, you will find build failed when new commit was pushed.
Default value of `fetch_depth` is 10 to cover re-build after several commit.
# No options will clone depth 1 and fetch depth 10.
- git-shallow-clone/checkout
# Clone the repository to specific path `src`.
- git-shallow-clone/checkout:
path: src
# Set fetch_depth: 1 to minimize fetch time.
- git-shallow-clone/checkout:
fetch_depth: 1
# Change depth:5 for some reason.
- git-shallow-clone/checkout:
depth: 5
fetch_depth: 5
# Enable ssh key scan for github.com and bitbucket.org. Omit this parameter use embedded known ssh key by default.
- git-shallow-clone/checkout:
keyscan_github: true
keyscan_bitbucket: true
# Skip tag fetch.
- git-shallow-clone/checkout:
no_tags: true
# Shallow clone then update submodules.
- git-shallow-clone/checkout
- run: git submodule update --init --recursive
usage:
version: "2.1"
orbs:
git-shallow-clone: guitarrapc/git-shallow-clone@x.y.z
workflows:
build:
jobs:
- git-shallow-clone/checkout
checkout_advanced:
description: |
Advanced git shallow clone instead of checkout with clone_options and fetch_options.
Make sure some options is exclusive each other, you should follow to official git documentation.
e.g. `--depth N` cannot use with `--shallow-since`.
# No options will clone depth 1 and fetch depth 10.
- git-shallow-clone/checkout_advanced
# Clone the repository to specific path `src`.
- git-shallow-clone/checkout_advanced
path: src
# See verbose log on clone.
- git-shallow-clone/checkout_advanced
clone_options: '--depth 1 --verbose'.
# Use --shallow-since for clone timing, but not for fetch timing.
- git-shallow-clone/checkout_advanced
clone_options: '--shallow-since "5 days ago"'
# Use --shallow-since for fetch timing, but not for clone timing.
- git-shallow-clone/checkout_advanced
fetch_options: '--shallow-since "5 days ago"'
# Use --no-tags to skip tag fetch.
- git-shallow-clone/checkout_advanced
fetch_options: '--depth 10 --no-tags'
# Skip tag fetch.
- git-shallow-clone/checkout_advanced
fetch_options: '--depth 10 --no-tags'
tag_fetch_options: '--no-tags'
# Shallow clone then update submodules.
- git-shallow-clone/checkout_advanced
- run: git submodule update --init --recursive
usage:
version: "2.1"
orbs:
git-shallow-clone: guitarrapc/git-shallow-clone@x.y.z
workflows:
build:
jobs:
- git-shallow-clone/checkout_advanced:
clone_options: --shallow-since "5 days ago"
fetch_options: --shallow-since "5 days ago"