In my team we are investigating NX and as part of our investigation, we want to know if we can use it to trigger our workflows and how.
A script of NX, called
nx print-affected can tell you which applications in your monorepo have changed.
I wanted to use this script, this information, to determine when a workflow should run.
Let’s say I have an application called
infrastructure in our monorepo, and I want to use nx in the
when workflow condition like
pull_request_infrastructure: when: $(case "infrastructure" in *yarn nx print-affected --base=main --head=HEAD --select=projects*) echo "Infrastructure has changed";; esac) jobs:
I wonder, in first place if I can use a script like that in a workflow condition. Haven’t found any example in CircleCi config documentation. It doesn’t error but always triggers the workflow even if I change
case "infrastructure" to
case "marco" for example.
If is doable, how this script should be?
As you might ask, I am aware of CircleCi Dynamic config, which would be easy for me to set up and I know it works. But as far as I know it would not be able to understand if an application has changed also based on it’s dependencies which is what NX would be offering in addition.
So if infrastructure hasn’t changed but depends on the “auth” application which has changed, infrastructure workflow should still run. And for avoiding taking responsibility to set the logic for dependencies my self, as in other scenario might be too complex, I am going for NX.
But please let me know what you think and a solution to use the script in the when condition.