76 lines
3.2 KiB
YAML
76 lines
3.2 KiB
YAML
version: 2
|
|
|
|
jobs:
|
|
build:
|
|
machine: true
|
|
working_directory: ~/repo
|
|
|
|
steps:
|
|
- checkout
|
|
|
|
- run:
|
|
name: Choose which test suite to run based on which files were modified
|
|
command: |
|
|
## Checking commits for changes to Packer files
|
|
## This handles the cases where there are multiple commits
|
|
if echo "$CIRCLE_COMPARE_URL" | grep '\.\.'; then
|
|
if [ "$(git diff-tree --no-commit-id --name-only -r $(git rev-parse origin/HEAD) $(echo $CIRCLE_COMPARE_URL | cut -d '.' -f 5) | grep -c ^Packer/)" -gt 0 ]; then
|
|
export PACKER_MODIFIED=1
|
|
else
|
|
export PACKER_MODIFIED=0
|
|
fi
|
|
else
|
|
## This handles the cases where there is only a single commit
|
|
export COMMIT_ID="$(echo $CIRCLE_COMPARE_URL | cut -d '/' -f 7)"
|
|
if [ "$(git diff-tree --no-commit-id --name-only -r $COMMIT_ID | grep -c ^Packer/)" -gt 0 ]; then
|
|
export PACKER_MODIFIED=1
|
|
else
|
|
export PACKER_MODIFIED=0
|
|
fi
|
|
fi
|
|
## Checking commits for changes to Vagrant files
|
|
if echo "$CIRCLE_COMPARE_URL" | grep '\.\.'; then
|
|
if [ "$(git diff-tree --no-commit-id --name-only -r $(git rev-parse origin/HEAD) $(echo $CIRCLE_COMPARE_URL | cut -d '.' -f 5) | grep -c ^Vagrant/)" -gt 0 ]; then
|
|
export VAGRANT_MODIFIED=1
|
|
else
|
|
export VAGRANT_MODIFIED=0
|
|
fi
|
|
else
|
|
export COMMIT_ID="$(echo $CIRCLE_COMPARE_URL | cut -d '/' -f 7)"
|
|
if [ "$(git diff-tree --no-commit-id --name-only -r $COMMIT_ID | grep -c \"^Vagrant/\")" -gt 0 ]; then
|
|
export VAGRANT_MODIFIED=1
|
|
else
|
|
export VAGRANT_MODIFIED=0
|
|
fi
|
|
fi
|
|
echo "VAGRANT_MODIFIED=$VAGRANT_MODIFIED"
|
|
echo "PACKER_MODIFIED=$PACKER_MODIFIED"
|
|
## Choosing which test suite to run based on the files that were changed
|
|
if [[ "$PACKER_MODIFIED" -eq 1 ]] && [[ "$VAGRANT_MODIFIED" -eq 1 ]]; then
|
|
echo "Running the test suite for Packer and Vagrant changes"
|
|
chmod +x ci/circle_workflows/packer_and_vagrant_changes.sh
|
|
ci/circle_workflows/packer_and_vagrant_changes.sh
|
|
exit 0
|
|
fi
|
|
if [[ "$PACKER_MODIFIED" -eq 0 ]] && [[ "$VAGRANT_MODIFIED" -eq 0 ]]; then
|
|
echo "Running the default test suite (Vagrant-only)"
|
|
chmod +x ci/circle_workflows/vagrant_changes.sh
|
|
ci/circle_workflows/vagrant_changes.sh
|
|
exit 0
|
|
fi
|
|
if [ "$PACKER_MODIFIED" -eq 1 ]; then
|
|
echo "Running the test suite for Packer-only changes"
|
|
chmod +x ci/circle_workflows/packer_changes.sh
|
|
ci/circle_workflows/packer_changes.sh
|
|
exit 0
|
|
fi
|
|
if [ "$VAGRANT_MODIFIED" -eq 1 ]; then
|
|
echo "Running the test suite for Vagrant-only changes"
|
|
chmod +x ci/circle_workflows/vagrant_changes.sh
|
|
ci/circle_workflows/vagrant_changes.sh
|
|
exit 0
|
|
fi
|
|
|
|
- store_artifacts:
|
|
path: /tmp/artifacts
|