Skip to content

Commit

Permalink
Working Through Path Expansion Issues / Sub-Clone Working Directory (#9)
Browse files Browse the repository at this point in the history
* feat: try to work around some path expansion stuff

* fix: cleanup working directory

* feat: larger test set / cleanup

* fix: forgot to include new files

* fix: eval circleci working directory before attemping to mkdir

* wip: disable $HOME test for android

* feat: make sure our working directory is where we expect

* feat: no $HOME interpolation
  • Loading branch information
Lucas Kacher authored Sep 11, 2020
1 parent 2e7ea9b commit 8eaa930
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ workflows:
test-config-location: src/tests/default_shallow_checkout.yml
- test/local-test-build:
test-config-location: src/tests/default_shallow_checkout_full.yml
- test/local-test-build:
test-config-location: src/tests/default_shallow_checkout_tidle_path.yml
- test/local-test-build:
test-config-location: src/tests/default_shallow_checkout_working_path.yml
requires:
Expand All @@ -134,6 +136,8 @@ workflows:
test-config-location: src/tests/android_shallow_checkout.yml
- test/local-test-build:
test-config-location: src/tests/android_shallow_checkout_full.yml
- test/local-test-build:
test-config-location: src/tests/android_shallow_checkout_tidle_path.yml
- test/local-test-build:
test-config-location: src/tests/android_shallow_checkout_working_path.yml
requires:
Expand Down
26 changes: 20 additions & 6 deletions src/commands/shallow-checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ parameters:
default: 10
path:
description: >
By default, checkout path is $HOME/project, this can be overrridden.
By default, checkout path is ~/project, this can be overrridden.
type: string
default: $HOME/project
default: ~/project
fetch_lfs:
description: >
By default (false), export GIT_LFS_SKIP_SMUDGE=1 to prevent resolution of LFS pointers.
Expand Down Expand Up @@ -112,17 +112,31 @@ steps:
export GIT_LFS_SKIP_SMUDGE=1
fi
# if path is set, use it, otherwise use a default
CHECKOUT_PATH="${HOME}/project"
if [ "<< parameters.path >>" != "" ]
then
eval CHECKOUT_PATH="<< parameters.path >>"
rm -r $CHECKOUT_PATH || true
fi
# setup / checkout repository
if [ -e "<< parameters.path >>/.git" ]
if [ -e "${CHECKOUT_PATH}/.git" ]
then
cd "<< parameters.path >>"
cd "${CHECKOUT_PATH}"
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
mkdir -p "<< parameters.path >>"
cd "<< parameters.path >>"
mkdir -p "${CHECKOUT_PATH}"
cd "${CHECKOUT_PATH}"
git clone --depth << parameters.depth >> --shallow-submodules "$CIRCLE_REPOSITORY_URL" .
fi
if [ "<< parameters.path >>" != "" ]
then
eval CIRCLE_WORKING_DIRECTORY=$CIRCLE_WORKING_DIRECTORY
mkdir -p $CIRCLE_WORKING_DIRECTORY
fi
# tag, pr, others (master / main)
if [ -n "$CIRCLE_TAG" ]
then
Expand Down
23 changes: 23 additions & 0 deletions src/tests/android_shallow_checkout_tidle_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2.1

orbs:
cli: circleci/circleci-cli@0.1.8

executors:
android:
docker:
- image: circleci/android:api-29-ndk@sha256:d2d054238e1a7e9ab30dd9f6b44a06af8d41836e053ffc40707d75ba50bbe0bf
resource_class: small

# ensure we can specify a tilde based working directory that is a defined
# sub-path of the clone path
jobs:
build:
executor: android
working_directory: ~/foo/bar/baz
steps:
- advanced-checkout/shallow-checkout:
debug: true
path: ~/foo/bar
- run: find ~/foo/bar | grep baz

4 changes: 2 additions & 2 deletions src/tests/android_shallow_checkout_working_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ executors:
jobs:
build:
executor: android
working_directory: ~/foo/bar/src
working_directory: /home/circleci/foo/bar/src
steps:
- cli/install
- advanced-checkout/shallow-checkout:
debug: true
path: ~/foo/bar
path: /home/circleci/foo/bar

16 changes: 16 additions & 0 deletions src/tests/default_shallow_checkout_tidle_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2.1

orbs:
cli: circleci/circleci-cli@0.1.8

# ensure we can specify a tilde based working directory that is a defined
# sub-path of the clone path
jobs:
build:
executor: cli/default
working_directory: ~/foo/bar/src
steps:
- advanced-checkout/shallow-checkout:
debug: true
path: ~/foo/bar

4 changes: 2 additions & 2 deletions src/tests/default_shallow_checkout_working_path.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ orbs:
jobs:
build:
executor: cli/default
working_directory: ~/foo/bar/src
working_directory: /home/circleci/foo/bar/src
steps:
- advanced-checkout/shallow-checkout:
debug: true
path: ~/foo/bar
path: /home/circleci/foo/bar

0 comments on commit 8eaa930

Please sign in to comment.