⚠️ Update 2024: For anyone looking at this gist in 2024, we have moved on from using the Pipelines API to instead using tags. Each time we successfully deploy to an environment, we tag the commit with the environment name. When testing for changes, we then compare the current commit being deployed to the tagged commit for the same environment. This has proven to be a bit more robust than using the changes API. The principles are the same though. Let me know in a comment if it's not obvious how to adapt the script.
One devops strategy is to keep infrastructure state and code in a single repository, and deploy them together. It ensures your infrastructure is always in the correct state to match the version of your code.
The downside is that infrastructure deployments are slow, and generally don't change as frequently as code.
This gist shows how to skip an infrastructure deployment task if there are no changes in a particular sub-path of the repository.
It takes advantage of the pipelines API, which can provide a list of all commits since the last successful pipeline execution. This ensures that it works even when multiple commits are pushed at once, or when the build with the infrastructure change failed. The pipelines API does the hard work of working out which commits need checking.
Hi Elisabeth,
(EDIT replying with my work account)
I'm afraid I don't have a huge amount of time to write this up properly, but hopefully the following will help:
Our Test-ChangesMadeInPath powershell script now looks like this:
At the end of a successful deployment, we then do this:
The idea is that you can compare the current git commit to the tagged version to see what changes have happened since the last successful deployment. This has several advantages, not least that you can rollback by deploying a previous deployment, and it will correctly identify if files have changed between what is live and the version you are redeploying.
I'm thinking it probably makes sense to use branches rather than tags but tags are working for us right now and it hasn't been a priority to change.
Let me know if that gives you enough info to work it out!