4

I have a mono repo (git) which houses multiple microservices that I am working on. On push, the 3rd party build service detects this push and starts processing the build and deployment.

This works great. But now I am trying to optimize this process and I would only like it to build the particular services I have been working on. This means that the build services has to detect which folders have been changed and build those services only.

I have gotten this process to work on Travis pretty well because it has a GIT_COMMIT_RANGE environment variable. So I can get all the commits in my latest push and then across all those commits get the folders that have changed.. this works really well.. but ONLY on travis.

I wish to cut out travis and build my docker images directly on a GCP or whatever other 3rd party container builder I am using, but I only wish to build the folders that have changed.

I am thinking that it might be possible to do this with a git commit hook. Through this hook I can start generating a list of folders to mark for the build server to build, or even start generating a build file (cloudbuild.yaml). Then on some git push hook, (is there even a post-push hook) I reset the contents of the cloudbuild.yaml file locally.

tensai
  • 1,628
  • 3
  • 17
  • 22

1 Answers1

1

I have actually managed to solve this problem in a different repo using github actions

lucky for me someone created a github action to filter folders that have changed

- uses: dorny/paths-filter@v2
    id: changes
    with:
      filters: |
        src:
          - '<folder to check>/**'

In your following build steps you can then use an if statement to trigger the step if the path filter has returned true:

- name: Build node
    if: steps.changes.outputs.src == 'true'
    run: |
      <command goes here>

As you can see src will return true if anything in the subfolder has changed.

The action repo is available here https://github.com/dorny/paths-filter

tensai
  • 1,628
  • 3
  • 17
  • 22