Skip to content

Instantly share code, notes, and snippets.

@naesheim
Last active November 28, 2022 20:20
Show Gist options
  • Star 91 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save naesheim/18d0c0a58ee61f4674353a2f4cf71475 to your computer and use it in GitHub Desktop.
Save naesheim/18d0c0a58ee61f4674353a2f4cf71475 to your computer and use it in GitHub Desktop.
CircleCi - only build features that has changed
##################
### config.yml ###
##################
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6
steps:
- checkout
- run:
command: |
.circleci/commit_check.sh
#######################
### commit_check.sh ###
#######################
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
@sumeetshk
Copy link

sumeetshk commented Jul 6, 2021

The circlci example at https://circleci.com/docs/2.0/configuration-cookbook/?section=examples-and-guides#execute-specific-workflows-or-steps-based-on-which-files-are-modified returns below error:

[#/jobs/check-updated-files] 0 subschemas matched instead of one
1. [#/jobs/check-updated-files] only 0 subschema matches out of 2
|   1. [#/jobs/check-updated-files] no subschema matched out of the total 2 subschemas
|   |   1. [#/jobs/check-updated-files] 0 subschemas matched instead of one
|   |   |   1. [#/jobs/check-updated-files] expected type: Mapping, found: Sequence
|   |   |   |   SCHEMA:
|   |   |   |     type: object
|   |   |   |   INPUT:
|   |   |   |     - filter:
|   |   |   |         mapping: |
|   |   |   |           service1/.* run-build-service-1-job true
|   |   |   |           service2/.* run-build-service-2-job true
|   |   |   |         base-revision: master
|   |   |   |         config-path: .circleci/config.yml

@gabrielhesposito
Copy link

i get the same ^

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