Reputation:
We have a basic CI/CD system in place...when a push happens, Bitbucket will notify one of our servers - there is a commit SHA, and the repo etc.
But there is no obvious (to me) way to test the repo differently depending on the commit. Especially if it's a big repo, we may not want to test everything. So I am thinking something like this:
git commit -am "regular commit message # path/to/test/folder"
so everything after the last # in the commit message would be a path to a folder that contains a test.sh file. If we have git pre commit hooks in place, can we validate the info in the commit message?
Is there a better way to do this? Is there a way to add some metadata to a commit that instructs CI/CD servers how to test the commit?
Upvotes: -1
Views: 543
Reputation: 94581
The best practice is to put such metadata into commit messages with a header to distinguish it from any other metadata. For example Gerrit uses Change-Id
header:
Change-Id: xyzzy
So your command should be something like
git commit -a -m "regular commit message" -m "Test: path/to/test/folder"
This produces commit message
regular commit message
Test: path/to/test/folder
The rest is up to the test script.
Upvotes: 1
Reputation: 841
It's better to use the commit messages for their intended purpose - describing the contents and rationale of the commit. Here's a nice reference.
About CI/CD - Not wanting to test everything makes sense in some cases, but I would suggest to partition the tests as late as possible. IOW, test everything on each commit, and keep the tests as fast as possible. When you need to optimize further, you could partition the tests by their running time - run all "fast" tests on each commit, and all the "slow" ones in a nightly job.
Upvotes: 1