Skip to content

Commit

Permalink
Merge pull request #60 from guitarrapc/feature/add_workingdir
Browse files Browse the repository at this point in the history
ci: add working-directory test
  • Loading branch information
guitarrapc authored Oct 5, 2023
2 parents 79f2c2a + 4d8635c commit f8d4489
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 11 deletions.
110 changes: 107 additions & 3 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,63 @@ 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
steps:
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -92,42 +132,65 @@ 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
steps:
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions src/commands/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/commands/checkout_advanced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ steps:
git config --global url."ssh://[email protected]".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
Expand Down

0 comments on commit f8d4489

Please sign in to comment.