I'm trying to set up an AWS CodeBuild project to run tests to validate PRs and commits on a GitHub repository.
Because of the nature of the repo (a monorepo combining several ML models):
How can a running CodeBuild build triggered by a GitHub PR (as per the docs here) 'see' which files are changed by the PR to selectively execute tests?
You can use git diff --name-only $CODEBUILD_RESOLVED_SOURCE_VERSION $CODEBUILD_WEBHOOK_PREV_COMMIT
Where $CODEBUILD_WEBHOOK_PREV_COMMIT is the commit id of the previous commit. And $CODEBUILD_RESOLVED_SOURCE_VERSION is the commit id of the actual one.
Inside a build phase you can check the change with:
- |
    if [ "$(git diff --name-only $CODEBUILD_RESOLVED_SOURCE_VERSION $CODEBUILD_WEBHOOK_PREV_COMMIT | grep -e <filde_path>)" != "" ]; then
      #your code;
    fi
In your buildspec file you can perform shell commands, I think you can use some git commands there and echo the result, so you can see them as logs during the build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With