Leveraging parallel mode for Trunk Merge is easy for Bazel-enabled repos because Bazel already knows the structure of your code and can automatically generate a dependency graph. Merge can use this information in parallel mode to run your CI tests more efficiently, eliminating checks when Bazel already knows they cannot conflict.
Setup Trunk Merge
Connect your GitHub repository with Trunk and set up Trunk Merge with the standard instructions.
Turn on Parallel Mode
Next, enable Parallel Mode in the Trunk Merge UI.
Set Up the Github Action
Trunk provides a Merge GitHub Action workflow that leverages Bazel to take care of generating the required impacted targets and uploading them to Merge, taking care of the heavy work for using Parallel mode. In order for GitHub to communicate with Trunk Merge, it needs to be able to authenticate from the GitHub Action instance to the Trunk web application using your Trunk Organization API Token.
Get your Organization API Token
Store your Organization Token as a GitHub Secret
Add merge action with Trunk Org Token
Now add the trunk-io/merge-action action in a new workflow in your repo under .github/workflows
(e.g.: .github/workflows/uploaded_impacted_targets.yaml
).
1name: Upload Impacted Targets2run-name: Upload Impacted Targets for ${{ github.ref_name }}3on: pull_request45jobs:6 compute_impacted_targets:7 name: Compute Impacted Targets8 runs-on: ubuntu-latest9 steps:10 - name: Checkout11 uses: actions/checkout@v312 with:13 lfs: true1415 - name: Compute Impacted Targets16 uses: trunk-io/merge-action@v117 with:18 # Use your Trunk repo or org API token to authenticate impacted targets uploads.19 # This secret should be provided as a GitHub secret.20 # See https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions.21 trunk-token: ${{ secrets.TRUNK_ORG_API_TOKEN }}
If your Bazel setup is not in the root of your repo then you can add bazel-workspace-path: your_workspace_path
just below the trunk-token
. Commit the new workflow back to your repo to make it active.
Now you can submit a new pull request and test it. Success!