Skip to content

Instantly share code, notes, and snippets.

@FaisalAl-Tameemi
Forked from naesheim/buildWhenAffected.sh
Last active September 5, 2019 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FaisalAl-Tameemi/d34bbf8f38083bd5fd59f742207ea064 to your computer and use it in GitHub Desktop.
Save FaisalAl-Tameemi/d34bbf8f38083bd5fd59f742207ea064 to your computer and use it in GitHub Desktop.
CircleCi - only build features that has changed
set -e
# latest commit
LATEST_COMMIT=$(git rev-parse HEAD)
# latest commit where path/to/folder1 was changed
FOLDER1_COMMIT=$(git log -1 --format=format:%H --full-diff path/to/folder1)
# latest commit where path/to/folder2 was changed
FOLDER2_COMMIT=$(git log -1 --format=format:%H --full-diff path/to/folder2)
if [ $FOLDER1_COMMIT = $LATEST_COMMIT ];
then
echo "files in folder1 has changed"
.circleci/do_something.sh
elif [ $FOLDER2_COMMIT = $LATEST_COMMIT ];
then
echo "files in folder2 has changed"
.circleci/do_something_else.sh
else
echo "no folders of relevance has changed"
exit 0;
fi
version: 2
jobs:
build:
docker:
- image: circleci/...
steps:
- checkout
- run:
command: |
.circleci/build_directory.sh
@FaisalAl-Tameemi
Copy link
Author

The idea is that the actual CircleCI job only runs a shell script. The shell script then checks which folders have been effected with the commit using regular git commands.

The git commands then figure out which folder (service/lib) has been changed and does the relevant build steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment