I am trying to set up a monorepo complete CI/CD pipeline developed with nx.dev where I build and deploy only the apps and services that have changed in the commit.
My cloud build is linked to my github repo and when a change is pushed it kicks off a build. First npm install and then build the changed apps.
As per nrwls docs on nx https://nx.dev/guides/monorepo-affected#ci they say to use
npm run affected:build -- --base=origin/master~1 --head=origin/master
This will compare the current commit with the previous commit to find out which services or apps to build.
I have tried using this but am getting this error when running in cloud build
Step #1: fatal: Not a valid object name master~1
Step #1: Command failed: git merge-base master~1 master
Step #1: fatal: Not a valid object name master~1
When building this locally with cloud-build-local it works fine and successfully figures out which services to build.
I think the reason that it is failing is because when cloud build checks out the git repository it only checks out the commit and none of the previous commit information. Therefore it cannot reference the previous commit.
Is there any way around this or am I missing something?
Thanks!