How to port "on paths" from github actions to Circle?


I want to build some docker images on Circle. I don’t want to build every single dockerfile in the git repository, but only those that actually changed. Also, only pushing to the master branch should build anything. All other branches are ignored.

On Github Actions, I do the following in each yml file. There’s one yml file per docker image. build-docker-foo-linux.yml for example has this at the top:

name: Build Linux docker image foo
      - master
      - 'foo/linux/Dockerfile'

  # ...

If the push is not on master, and the file foo/linux/Dockerfile didn’t change, nothing is executed. The workflow is just skipped altogether.

I’m trying to move this to CircleCI, and I can’t find anything on how to make this work. I’ve been searching since yesterday, and all solutions I could find don’t work. They all resolve around parsing the output of git show --name-only ${CIRCLE_SHA1}, which just doesn’t work, since it can’t detect anything other than what’s in the diff of the current commit. Other commits are ignored.

How on earth do I move this to CircleCI?

The first part where you only want to do any action if the master branch is touched can be handled with branch filters

2 things to remember - spaces matter and there is a lot of indenting when using this structure and to get this to work the config.yml has to be updated across all the defined branches in the repo.

The second part is more complicated as CircleCI does not have access to the same detailed ‘state’ information that github has when it is also hosting the repo. CircleCI has a more complicated solution detailed here, but I’ve never tried to use it

Another solution may be to look at the artefact storing feature - so you could use a script to store the checksum of the file(s) you want to track between sessions.

My personal solution has so far been to use a self-hosted runner that can hold state between jobs. So my script can just compare a file between the current git pull and the last pull. If it sees a difference it runs the job and if it completes just copies the current git pull over the stored last pull, ready for the next time.

1 Like

Thank you very much!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.