diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index d0bfeae..fb27dc3 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -14,23 +14,31 @@ jobs: steps: - checkout - run: git tag --list + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 # Define one or more jobs which will utilize your orb's commands and parameters to validate your changes. integration-test-checkout: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout_advanced + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_alpine: docker: - image: circleci/redis:6.2.1-alpine steps: - run: apk update && apk add openssh git # openssh is required - git-shallow-clone/checkout_advanced + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_fetchoptions: docker: - image: cimg/base:stable @@ -38,11 +46,31 @@ jobs: - git-shallow-clone/checkout_advanced: clone_options: "--depth 100 --single-branch" fetch_options: "--depth 5" + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 + integration-test-checkout_advanced_keyscan_bitbucket: + docker: + - image: cimg/base:stable + steps: + - git-shallow-clone/checkout_advanced: + keyscan_bitbucket: true + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 + integration-test-checkout_advanced_keyscan_github: + docker: + - image: cimg/base:stable + steps: + - git-shallow-clone/checkout_advanced: + keyscan_github: true + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_macos: macos: xcode: 15.0.0 # see: https://circleci.com/docs/using-macos/ steps: - git-shallow-clone/checkout_advanced + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_notags: docker: - image: cimg/base:stable @@ -65,6 +93,16 @@ jobs: exit 1 fi fi + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 + integration-test-checkout_advanced_path: + docker: + - image: cimg/base:stable + steps: + - git-shallow-clone/checkout_advanced: + path: src + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "./src/.git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_sourcecaching: docker: - image: cimg/base:stable @@ -79,6 +117,8 @@ jobs: key: *source-cache paths: - ".git" + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_advanced_tags: docker: - image: cimg/base:stable @@ -92,12 +132,25 @@ jobs: git tag --list count=$(git tag --list | wc -l) if [ $count -eq 0 ]; then exit 1; fi + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 + integration-test-checkout_advanced_workingdir: + docker: + - image: cimg/base:stable + working_directory: ~/test-working-directory + steps: + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ "$(pwd)" == "$HOME/test-working-directory" ] && echo "working directory is correct" || exit 1 + - git-shallow-clone/checkout_advanced + # test checkout result. checkout should be clone to `working_directory`. + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "$HOME/test-working-directory/.git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_alpine: docker: - image: circleci/redis:6.2.1-alpine steps: - run: apk update && apk add openssh git # openssh is required - git-shallow-clone/checkout + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_depth: docker: - image: cimg/base:stable @@ -105,29 +158,39 @@ jobs: - git-shallow-clone/checkout: depth: 5 fetch_depth: 10 + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_fetchdepth: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout: fetch_depth: 1 + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_keyscan_bitbucket: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout: keyscan_bitbucket: true + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_keyscan_github: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout: keyscan_github: true + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_macos: macos: xcode: 15.0.0 # see: https://circleci.com/docs/using-macos/ steps: - git-shallow-clone/checkout + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_notags: docker: - image: cimg/base:stable @@ -149,12 +212,16 @@ jobs: exit 1 fi fi + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_path: docker: - image: cimg/base:stable steps: - git-shallow-clone/checkout: path: src + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "./src/.git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_sourcechching: docker: - image: cimg/base:stable @@ -169,6 +236,8 @@ jobs: key: *source-cache paths: - ".git" + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 integration-test-checkout_tags: docker: - image: cimg/base:stable @@ -181,6 +250,17 @@ jobs: git tag --list count=$(git tag --list | wc -l) if [ $count -eq 0 ]; then exit 1; fi + # test checkout result + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d ".git" ] && echo "git checkout is correct" || exit 1 + integration-test-checkout_workingdir: + docker: + - image: cimg/base:stable + working_directory: ~/test-working-directory + steps: + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ "$(pwd)" == "$HOME/test-working-directory" ] && echo "working directory is correct" || exit 1 + - git-shallow-clone/checkout + # test checkout result. checkout should be clone to `working_directory`. + - run: echo "pwd=$(pwd)" && echo "HOME=$HOME" && ls -la && [ -d "$HOME/test-working-directory/.git" ] && echo "git checkout is correct" || exit 1 integration-test-api-dispatch: docker: - image: cimg/base:stable @@ -203,22 +283,32 @@ workflows: # Run any integration tests defined within the `jobs` key. - normal-checkout: filters: *filters - - integration-test-checkout: - filters: *filters + # ---- checkout_advanced ---- - integration-test-checkout_advanced: filters: *filters - integration-test-checkout_advanced_alpine: filters: *filters - integration-test-checkout_advanced_fetchoptions: filters: *filters + - integration-test-checkout_advanced_keyscan_bitbucket: + filters: *filters + - integration-test-checkout_advanced_keyscan_github: + filters: *filters # - integration-test-checkout_advanced_macos: # filters: *filters - integration-test-checkout_advanced_notags: filters: *filters + - integration-test-checkout_advanced_path: + filters: *filters - integration-test-checkout_advanced_sourcecaching: filters: *filters - integration-test-checkout_advanced_tags: filters: *filters + - integration-test-checkout_advanced_workingdir: + filters: *filters + # ---- checkout_advanced ---- + - integration-test-checkout: + filters: *filters - integration-test-checkout_alpine: filters: *filters - integration-test-checkout_depth: @@ -239,6 +329,9 @@ workflows: filters: *filters - integration-test-checkout_tags: filters: *filters + - integration-test-checkout_workingdir: + filters: *filters + # ---- api ---- - integration-test-api-dispatch: filters: *filters context: api @@ -250,13 +343,20 @@ workflows: pub-type: production requires: - orb-tools/pack - - integration-test-checkout + # ---- checkout_advanced ---- - integration-test-checkout_advanced - integration-test-checkout_advanced_alpine - integration-test-checkout_advanced_fetchoptions + - integration-test-checkout_advanced_keyscan_bitbucket + - integration-test-checkout_advanced_keyscan_github #- integration-test-checkout_advanced_macos - integration-test-checkout_advanced_notags + - integration-test-checkout_advanced_path + - integration-test-checkout_advanced_sourcecaching - integration-test-checkout_advanced_tags + - integration-test-checkout_advanced_workingdir + # ---- checkout ---- + - integration-test-checkout - integration-test-checkout_alpine - integration-test-checkout_depth - integration-test-checkout_fetchdepth @@ -265,7 +365,11 @@ workflows: #- integration-test-checkout_macos - integration-test-checkout_notags - integration-test-checkout_path + - integration-test-checkout_sourcechching - integration-test-checkout_tags + - integration-test-checkout_workingdir + # ---- api ---- + - integration-test-api-dispatch context: orb-publisher filters: branches: diff --git a/src/commands/checkout.yml b/src/commands/checkout.yml index 157e77a..8fca1a3 100644 --- a/src/commands/checkout.yml +++ b/src/commands/checkout.yml @@ -113,17 +113,24 @@ steps: 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 "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>/.git" ]; then + if [ -e "$working_directory/<< parameters.path >>/.git" ]; then echo 'Fetching into existing repository' existing_repo='true' - cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" + cd "$working_directory/<< parameters.path >>" git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true else echo 'Cloning git repository' existing_repo='false' - mkdir -p "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" - cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" + mkdir -p "$working_directory/<< parameters.path >>" + cd "$working_directory/<< parameters.path >>" git clone ${clone_tag_args} --depth << parameters.depth >> $CIRCLE_REPOSITORY_URL . fi diff --git a/src/commands/checkout_advanced.yml b/src/commands/checkout_advanced.yml index 5c122e3..7f1cf6e 100644 --- a/src/commands/checkout_advanced.yml +++ b/src/commands/checkout_advanced.yml @@ -99,17 +99,24 @@ steps: 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 "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>/.git" ]; then + if [ -e "$working_directory/<< parameters.path >>/.git" ]; then echo 'Fetching into existing repository' existing_repo='true' - cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" + cd "$working_directory/<< parameters.path >>" git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true else echo 'Cloning git repository' existing_repo='false' - mkdir -p "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" - cd "$CIRCLE_WORKING_DIRECTORY/<< parameters.path >>" + mkdir -p "$working_directory/<< parameters.path >>" + cd "$working_directory/<< parameters.path >>" git clone << parameters.clone_options >> $CIRCLE_REPOSITORY_URL . fi