Skip to content

Commit f8d4489

Browse files
authored
Merge pull request #60 from guitarrapc/feature/add_workingdir
ci: add working-directory test
2 parents 79f2c2a + 4d8635c commit f8d4489

File tree

3 files changed

+129
-11
lines changed

3 files changed

+129
-11
lines changed

.circleci/test-deploy.yml

+107-3
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,63 @@ jobs:
1414
steps:
1515
- checkout
1616
- run: git tag --list
17+
# test checkout result
18+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
1719
# Define one or more jobs which will utilize your orb's commands and parameters to validate your changes.
1820
integration-test-checkout:
1921
docker:
2022
- image: cimg/base:stable
2123
steps:
2224
- git-shallow-clone/checkout
25+
# test checkout result
26+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
2327
integration-test-checkout_advanced:
2428
docker:
2529
- image: cimg/base:stable
2630
steps:
2731
- git-shallow-clone/checkout_advanced
32+
# test checkout result
33+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
2834
integration-test-checkout_advanced_alpine:
2935
docker:
3036
- image: circleci/redis:6.2.1-alpine
3137
steps:
3238
- run: apk update && apk add openssh git # openssh is required
3339
- git-shallow-clone/checkout_advanced
40+
# test checkout result
41+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
3442
integration-test-checkout_advanced_fetchoptions:
3543
docker:
3644
- image: cimg/base:stable
3745
steps:
3846
- git-shallow-clone/checkout_advanced:
3947
clone_options: "--depth 100 --single-branch"
4048
fetch_options: "--depth 5"
49+
# test checkout result
50+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
51+
integration-test-checkout_advanced_keyscan_bitbucket:
52+
docker:
53+
- image: cimg/base:stable
54+
steps:
55+
- git-shallow-clone/checkout_advanced:
56+
keyscan_bitbucket: true
57+
# test checkout result
58+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
59+
integration-test-checkout_advanced_keyscan_github:
60+
docker:
61+
- image: cimg/base:stable
62+
steps:
63+
- git-shallow-clone/checkout_advanced:
64+
keyscan_github: true
65+
# test checkout result
66+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
4167
integration-test-checkout_advanced_macos:
4268
macos:
4369
xcode: 15.0.0 # see: https://circleci.com/docs/using-macos/
4470
steps:
4571
- git-shallow-clone/checkout_advanced
72+
# test checkout result
73+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
4674
integration-test-checkout_advanced_notags:
4775
docker:
4876
- image: cimg/base:stable
@@ -65,6 +93,16 @@ jobs:
6593
exit 1
6694
fi
6795
fi
96+
# test checkout result
97+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
98+
integration-test-checkout_advanced_path:
99+
docker:
100+
- image: cimg/base:stable
101+
steps:
102+
- git-shallow-clone/checkout_advanced:
103+
path: src
104+
# test checkout result
105+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "./src/.git" ] && echo "git checkout is correct" || exit 1
68106
integration-test-checkout_advanced_sourcecaching:
69107
docker:
70108
- image: cimg/base:stable
@@ -79,6 +117,8 @@ jobs:
79117
key: *source-cache
80118
paths:
81119
- ".git"
120+
# test checkout result
121+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
82122
integration-test-checkout_advanced_tags:
83123
docker:
84124
- image: cimg/base:stable
@@ -92,42 +132,65 @@ jobs:
92132
git tag --list
93133
count=$(git tag --list | wc -l)
94134
if [ $count -eq 0 ]; then exit 1; fi
135+
# test checkout result
136+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
137+
integration-test-checkout_advanced_workingdir:
138+
docker:
139+
- image: cimg/base:stable
140+
working_directory: ~/test-working-directory
141+
steps:
142+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ "$(pwd)" == "$HOME/test-working-directory" ] && echo "working directory is correct" || exit 1
143+
- git-shallow-clone/checkout_advanced
144+
# test checkout result. checkout should be clone to `working_directory`.
145+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "$HOME/test-working-directory/.git" ] && echo "git checkout is correct" || exit 1
95146
integration-test-checkout_alpine:
96147
docker:
97148
- image: circleci/redis:6.2.1-alpine
98149
steps:
99150
- run: apk update && apk add openssh git # openssh is required
100151
- git-shallow-clone/checkout
152+
# test checkout result
153+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
101154
integration-test-checkout_depth:
102155
docker:
103156
- image: cimg/base:stable
104157
steps:
105158
- git-shallow-clone/checkout:
106159
depth: 5
107160
fetch_depth: 10
161+
# test checkout result
162+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
108163
integration-test-checkout_fetchdepth:
109164
docker:
110165
- image: cimg/base:stable
111166
steps:
112167
- git-shallow-clone/checkout:
113168
fetch_depth: 1
169+
# test checkout result
170+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
114171
integration-test-checkout_keyscan_bitbucket:
115172
docker:
116173
- image: cimg/base:stable
117174
steps:
118175
- git-shallow-clone/checkout:
119176
keyscan_bitbucket: true
177+
# test checkout result
178+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
120179
integration-test-checkout_keyscan_github:
121180
docker:
122181
- image: cimg/base:stable
123182
steps:
124183
- git-shallow-clone/checkout:
125184
keyscan_github: true
185+
# test checkout result
186+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
126187
integration-test-checkout_macos:
127188
macos:
128189
xcode: 15.0.0 # see: https://circleci.com/docs/using-macos/
129190
steps:
130191
- git-shallow-clone/checkout
192+
# test checkout result
193+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
131194
integration-test-checkout_notags:
132195
docker:
133196
- image: cimg/base:stable
@@ -149,12 +212,16 @@ jobs:
149212
exit 1
150213
fi
151214
fi
215+
# test checkout result
216+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
152217
integration-test-checkout_path:
153218
docker:
154219
- image: cimg/base:stable
155220
steps:
156221
- git-shallow-clone/checkout:
157222
path: src
223+
# test checkout result
224+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "./src/.git" ] && echo "git checkout is correct" || exit 1
158225
integration-test-checkout_sourcechching:
159226
docker:
160227
- image: cimg/base:stable
@@ -169,6 +236,8 @@ jobs:
169236
key: *source-cache
170237
paths:
171238
- ".git"
239+
# test checkout result
240+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
172241
integration-test-checkout_tags:
173242
docker:
174243
- image: cimg/base:stable
@@ -181,6 +250,17 @@ jobs:
181250
git tag --list
182251
count=$(git tag --list | wc -l)
183252
if [ $count -eq 0 ]; then exit 1; fi
253+
# test checkout result
254+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1
255+
integration-test-checkout_workingdir:
256+
docker:
257+
- image: cimg/base:stable
258+
working_directory: ~/test-working-directory
259+
steps:
260+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ "$(pwd)" == "$HOME/test-working-directory" ] && echo "working directory is correct" || exit 1
261+
- git-shallow-clone/checkout
262+
# test checkout result. checkout should be clone to `working_directory`.
263+
- run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "$HOME/test-working-directory/.git" ] && echo "git checkout is correct" || exit 1
184264
integration-test-api-dispatch:
185265
docker:
186266
- image: cimg/base:stable
@@ -203,22 +283,32 @@ workflows:
203283
# Run any integration tests defined within the `jobs` key.
204284
- normal-checkout:
205285
filters: *filters
206-
- integration-test-checkout:
207-
filters: *filters
286+
# ---- checkout_advanced ----
208287
- integration-test-checkout_advanced:
209288
filters: *filters
210289
- integration-test-checkout_advanced_alpine:
211290
filters: *filters
212291
- integration-test-checkout_advanced_fetchoptions:
213292
filters: *filters
293+
- integration-test-checkout_advanced_keyscan_bitbucket:
294+
filters: *filters
295+
- integration-test-checkout_advanced_keyscan_github:
296+
filters: *filters
214297
# - integration-test-checkout_advanced_macos:
215298
# filters: *filters
216299
- integration-test-checkout_advanced_notags:
217300
filters: *filters
301+
- integration-test-checkout_advanced_path:
302+
filters: *filters
218303
- integration-test-checkout_advanced_sourcecaching:
219304
filters: *filters
220305
- integration-test-checkout_advanced_tags:
221306
filters: *filters
307+
- integration-test-checkout_advanced_workingdir:
308+
filters: *filters
309+
# ---- checkout_advanced ----
310+
- integration-test-checkout:
311+
filters: *filters
222312
- integration-test-checkout_alpine:
223313
filters: *filters
224314
- integration-test-checkout_depth:
@@ -239,6 +329,9 @@ workflows:
239329
filters: *filters
240330
- integration-test-checkout_tags:
241331
filters: *filters
332+
- integration-test-checkout_workingdir:
333+
filters: *filters
334+
# ---- api ----
242335
- integration-test-api-dispatch:
243336
filters: *filters
244337
context: api
@@ -250,13 +343,20 @@ workflows:
250343
pub-type: production
251344
requires:
252345
- orb-tools/pack
253-
- integration-test-checkout
346+
# ---- checkout_advanced ----
254347
- integration-test-checkout_advanced
255348
- integration-test-checkout_advanced_alpine
256349
- integration-test-checkout_advanced_fetchoptions
350+
- integration-test-checkout_advanced_keyscan_bitbucket
351+
- integration-test-checkout_advanced_keyscan_github
257352
#- integration-test-checkout_advanced_macos
258353
- integration-test-checkout_advanced_notags
354+
- integration-test-checkout_advanced_path
355+
- integration-test-checkout_advanced_sourcecaching
259356
- integration-test-checkout_advanced_tags
357+
- integration-test-checkout_advanced_workingdir
358+
# ---- checkout ----
359+
- integration-test-checkout
260360
- integration-test-checkout_alpine
261361
- integration-test-checkout_depth
262362
- integration-test-checkout_fetchdepth
@@ -265,7 +365,11 @@ workflows:
265365
#- integration-test-checkout_macos
266366
- integration-test-checkout_notags
267367
- integration-test-checkout_path
368+
- integration-test-checkout_sourcechching
268369
- integration-test-checkout_tags
370+
- integration-test-checkout_workingdir
371+
# ---- api ----
372+
- integration-test-api-dispatch
269373
context: orb-publisher
270374
filters:
271375
branches:

src/commands/checkout.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,24 @@ steps:
113113
fetch_tag_args="--no-tags"
114114
fi
115115
116+
# Replace "~" in `$CIRCLE_WORKING_DIRECTORY` to `$HOME`
117+
if [ "$0" == "/bin/bash" ]; then
118+
working_directory=${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}
119+
else
120+
working_directory=$(echo "$CIRCLE_WORKING_DIRECTORY" | sed -e "s|^~|$HOME|g")
121+
fi
122+
116123
# Checkout. SourceCaching? or not.
117-
if [ -e "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>/.git" ]; then
124+
if [ -e "$working_directory/<< parameters.path >>/.git" ]; then
118125
echo 'Fetching into existing repository'
119126
existing_repo='true'
120-
cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
127+
cd "$working_directory/<< parameters.path >>"
121128
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
122129
else
123130
echo 'Cloning git repository'
124131
existing_repo='false'
125-
mkdir -p "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
126-
cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
132+
mkdir -p "$working_directory/<< parameters.path >>"
133+
cd "$working_directory/<< parameters.path >>"
127134
git clone ${clone_tag_args} --depth << parameters.depth >> $CIRCLE_REPOSITORY_URL .
128135
fi
129136

src/commands/checkout_advanced.yml

+11-4
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,24 @@ steps:
9999
git config --global url."ssh://[email protected]".insteadOf "https://github.com" || true
100100
git config --global gc.auto 0 || true
101101
102+
# Expand `$CIRCLE_WORKING_DIRECTORY`'s ~ to `$HOME`
103+
if [ "$0" == "/bin/sh" ]; then
104+
working_directory=$(echo "$CIRCLE_WORKING_DIRECTORY" | sed -e "s|^~|$HOME|g")
105+
else
106+
working_directory=${CIRCLE_WORKING_DIRECTORY/#\~/$HOME}
107+
fi
108+
102109
# Checkout. SourceCaching? or not.
103-
if [ -e "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>/.git" ]; then
110+
if [ -e "$working_directory/<< parameters.path >>/.git" ]; then
104111
echo 'Fetching into existing repository'
105112
existing_repo='true'
106-
cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
113+
cd "$working_directory/<< parameters.path >>"
107114
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
108115
else
109116
echo 'Cloning git repository'
110117
existing_repo='false'
111-
mkdir -p "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
112-
cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>"
118+
mkdir -p "$working_directory/<< parameters.path >>"
119+
cd "$working_directory/<< parameters.path >>"
113120
git clone << parameters.clone_options >> $CIRCLE_REPOSITORY_URL .
114121
fi
115122

0 commit comments

Comments
 (0)