Skip to content

Commit 53ffc69

Browse files
authored
Merge pull request #24 from guitarrapc/feat/tests
feat: add no_tags to git-shallow-clone/checkout, add test and examples.
2 parents 69073fb + 3239753 commit 53ffc69

File tree

5 files changed

+113
-16
lines changed

5 files changed

+113
-16
lines changed

.circleci/config.yml

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,50 @@ jobs:
2727
steps:
2828
- git-shallow-clone/checkout
2929
integration-test-checkout_advanced:
30+
docker:
31+
- image: cimg/base:stable
32+
steps:
33+
- git-shallow-clone/checkout_advanced
34+
integration-test-checkout_advanced_fetchoptions:
3035
docker:
3136
- image: cimg/base:stable
3237
steps:
3338
- git-shallow-clone/checkout_advanced:
3439
clone_options: '--shallow-since "5 days ago"'
3540
fetch_options: '--shallow-since "5 days ago"'
41+
integration-test-checkout_advanced_notags:
42+
docker:
43+
- image: cimg/base:stable
44+
steps:
45+
- git-shallow-clone/checkout_advanced:
46+
clone_options: "--depth 1"
47+
fetch_options: "--depth 1000 --no-tags"
48+
tag_fetch_options: "--no-tags"
49+
# should be no tags
50+
- run: |
51+
set -e
52+
git tag --list
53+
count=$(git tag --list | wc -l)
54+
if [ $count -ne 0 ]; then exit 1; fi
55+
integration-test-checkout_advanced_tags:
56+
docker:
57+
- image: cimg/base:stable
58+
steps:
59+
- git-shallow-clone/checkout_advanced:
60+
clone_options: "--depth 1"
61+
fetch_options: "--depth 1000"
62+
# should be all tags in fetch depth
63+
- run: |
64+
set -e
65+
git tag --list
66+
count=$(git tag --list | wc -l)
67+
if [ $count -eq 0 ]; then exit 1; fi
3668
integration-test-checkout_alpine:
3769
docker:
3870
- image: circleci/redis:alpine3.13
3971
steps:
4072
- run: apk update && apk add openssh git # openssh is required
4173
- git-shallow-clone/checkout
42-
integration-test-checkout_macos:
43-
macos:
44-
xcode: 13.0.0
45-
steps:
46-
- git-shallow-clone/checkout
4774
integration-test-checkout_depth:
4875
docker:
4976
- image: cimg/base:stable
@@ -69,12 +96,42 @@ jobs:
6996
steps:
7097
- git-shallow-clone/checkout:
7198
keyscan_github: true
99+
integration-test-checkout_macos:
100+
macos:
101+
xcode: 13.0.0
102+
steps:
103+
- git-shallow-clone/checkout
104+
integration-test-checkout_notags:
105+
docker:
106+
- image: cimg/base:stable
107+
steps:
108+
- git-shallow-clone/checkout:
109+
fetch_depth: 1000
110+
no_tags: true
111+
# should be no tags
112+
- run: |
113+
set -e
114+
git tag --list
115+
count=$(git tag --list | wc -l)
116+
if [ $count -ne 0 ]; then exit 1; fi
72117
integration-test-checkout_path:
73118
docker:
74119
- image: cimg/base:stable
75120
steps:
76121
- git-shallow-clone/checkout:
77122
path: src
123+
integration-test-checkout_tags:
124+
docker:
125+
- image: cimg/base:stable
126+
steps:
127+
- git-shallow-clone/checkout:
128+
fetch_depth: 1000
129+
# should be all tags in fetch depth
130+
- run: |
131+
set -e
132+
git tag --list
133+
count=$(git tag --list | wc -l)
134+
if [ $count -eq 0 ]; then exit 1; fi
78135
79136
workflows:
80137
# Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
@@ -107,13 +164,18 @@ workflows:
107164
# Run any integration tests defined within the `jobs` key.
108165
- integration-test-checkout
109166
- integration-test-checkout_advanced
167+
- integration-test-checkout_advanced_fetchoptions
168+
- integration-test-checkout_advanced_notags
169+
- integration-test-checkout_advanced_tags
110170
- integration-test-checkout_alpine
111-
- integration-test-checkout_macos
112171
- integration-test-checkout_depth
113172
- integration-test-checkout_fetchdepth
114173
- integration-test-checkout_keyscan_bitbucket
115174
- integration-test-checkout_keyscan_github
175+
- integration-test-checkout_macos
176+
- integration-test-checkout_notags
116177
- integration-test-checkout_path
178+
- integration-test-checkout_tags
117179

118180
# Publish a semver version of the orb. relies on
119181
# the commit subject containing the text "[semver:patch|minor|major|skip]"
@@ -129,13 +191,18 @@ workflows:
129191
requires:
130192
- integration-test-checkout
131193
- integration-test-checkout_advanced
194+
- integration-test-checkout_advanced_fetchoptions
195+
- integration-test-checkout_advanced_notags
196+
- integration-test-checkout_advanced_tags
132197
- integration-test-checkout_alpine
133-
- integration-test-checkout_macos
134198
- integration-test-checkout_depth
135199
- integration-test-checkout_fetchdepth
136200
- integration-test-checkout_keyscan_bitbucket
137201
- integration-test-checkout_keyscan_github
202+
- integration-test-checkout_macos
203+
- integration-test-checkout_notags
138204
- integration-test-checkout_path
205+
- integration-test-checkout_tags
139206
filters:
140207
branches:
141208
only:

src/commands/checkout.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ parameters:
88
default: 1
99
fetch_depth:
1010
description: >
11-
Addtional fetch depth fetch depth to the specified number of commit from a remote branch history.
11+
Addtional fetch depth to the specified number of commit from a remote branch history.
1212
Pass more number then depth when you want to check futher commit history.
1313
type: integer
1414
default: 10
@@ -27,6 +27,14 @@ parameters:
2727
Checkout directory (default: job’s working_directory)
2828
type: string
2929
default: .
30+
no_tags:
31+
description: >
32+
true to add '--no-tags' when fetching.
33+
As git not offer tag depth, we only able to control fetch all tags or not.
34+
This enable you to stop fetch tags when you have vast numbers of tags during specified fetch depth.
35+
In other word, if you need tag then fetch specified tags manually when use 'without_tag: true'.
36+
type: boolean
37+
default: false
3038
steps:
3139
- run:
3240
name: Checkout code shallow
@@ -76,18 +84,29 @@ steps:
7684
git clone --depth << parameters.depth >> $CIRCLE_REPOSITORY_URL "<< parameters.path >>"
7785
cd "<< parameters.path >>"
7886
87+
# Define Tag Fetch args
88+
if [ -n "$CIRCLE_TAG" ]
89+
then
90+
# only tags operation have default --tags. others will no tag options
91+
tag_args="--tags"
92+
fi
93+
if [ '<< parameters.no_tags >>' == 'true' ]
94+
then
95+
tag_args="--no-tags"
96+
fi
97+
7998
# Fetch remote and check the commit ID of the checked out code
8099
if [ -n "$CIRCLE_TAG" ]
81100
then
82101
# tag
83-
git fetch --tags --depth << parameters.fetch_depth >> --force origin "refs/tags/${CIRCLE_TAG}"
102+
git fetch ${tag_args} --depth << parameters.fetch_depth >> --force origin "+refs/tags/${CIRCLE_TAG}:refs/tags/${CIRCLE_TAG}"
84103
elif [[ $(echo $CIRCLE_BRANCH | grep -E ^pull\/[0-9]+$) ]] # sh version of bash `elif [[ "$CIRCLE_BRANCH" =~ ^pull\/[0-9]+$ ]]`
85104
then
86105
# pull request
87-
git fetch --depth << parameters.fetch_depth >> --force origin "${CIRCLE_BRANCH}/head:remotes/origin/${CIRCLE_BRANCH}"
106+
git fetch ${tag_args} --depth << parameters.fetch_depth >> --force origin "${CIRCLE_BRANCH}/head:remotes/origin/${CIRCLE_BRANCH}"
88107
else
89108
# others
90-
git fetch --depth=<< parameters.fetch_depth >> --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
109+
git fetch ${tag_args} --depth=<< parameters.fetch_depth >> --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
91110
fi
92111
93112
# Check the commit ID of the checked out code

src/commands/checkout_advanced.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
description: |
2-
checkout by git shallow clone with git options. Support Alpine, Ubuntu, Debian and others.
3-
eval is used in step, Fish shell is not supported.
2+
checkout by git shallow clone with git options. Support Alpine, Ubuntu, Debian and others.
3+
eval is used in step, Fish shell is not supported.
44
parameters:
55
clone_options:
66
type: string
@@ -12,14 +12,15 @@ parameters:
1212
default: "--depth 10"
1313
description: >
1414
git fetch options you want to add such as '--depth 1 --verbose' and '--depth 1 --shallow-since "5 days ago"'
15-
you donot beed set '--force' option as it already set by default.
16-
in case of tag, '-t' sat by default in tag_fetch_options
15+
you don't need set '--force' option as it already set by default.
16+
in case of tag, add '--no-tags' on this option and tag_fetch_options.
1717
tag_fetch_options:
1818
type: string
1919
default: "--tags"
2020
description: >
21+
This option apply when git operation is tag. Use 'fetch_options' instead if pr and other git operation.
2122
Additional git fetch options you want to add specifically for tags such as '--tags' or '--no-tags'.
22-
Default value is --tags
23+
Default value is '--tags'
2324
keyscan_github:
2425
description: >
2526
Pass `true` to dynamically get ssh-rsa from `github.com`.

src/examples/checkout.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ description: |
2121
# clone the repository to src
2222
- git-shallow-clone/checkout:
2323
path: src
24+
# skip tag fetch on `PR`, `PUSH` and fetch only single tag on `TAG`
25+
- git-shallow-clone/checkout:
26+
no_tags: true
2427
2528
usage:
2629
version: 2.1

src/examples/checkout_advanced.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ description: |
1212
# use --shallow-since for fetch timing, but not for clone timing.
1313
- git-shallow-clone/checkout_advanced
1414
fetch_options: '--shallow-since "5 days ago"'
15+
# use --no-tags to skip tag fetch on `PR` and `PUSH`.
16+
- git-shallow-clone/checkout_advanced
17+
fetch_options: '--depth 10 --no-tags'
18+
# use --no-tags to fetch single tag on git `TAG`.
19+
- git-shallow-clone/checkout_advanced
20+
fetch_options: '--depth 10 --no-tags' # you can omit this.
21+
tag_fetch_options: '--no-tags'
1522
1623
usage:
1724
version: 2.1

0 commit comments

Comments
 (0)