From 4355e3d6052d9b1b775783958ee01a9017dfe41c Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Mon, 29 Jul 2024 10:03:48 -0300 Subject: [PATCH] tests trigger: add target-branch parameter to trigger from the right branch (#4121) Fix the `@RCGitBot please test` issue where tests would always get triggered from the `main` branch. This solution is based on this comment: https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/issues/61#issuecomment-1662021882 But you can also see in the code that this is indeed how the branch name is determined, and that that [logic looks the same as the one for `GHA_action` and `target-slug`](https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/blob/a81cd720792a6088debd7f182b552845abb86f1b/src/lib/CircleCIPipelineTrigger.ts#L66), so it's just undocumented. We're using a fixed version, 1.2.0, so it shouldn't just randomly break. --- .github/workflows/trigger_all_tests.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/trigger_all_tests.yml b/.github/workflows/trigger_all_tests.yml index ad9c3d814e..d02439e43e 100644 --- a/.github/workflows/trigger_all_tests.yml +++ b/.github/workflows/trigger_all_tests.yml @@ -31,12 +31,30 @@ jobs: fi echo "User is a member of the organization" + # Note: actions based on issue comments always trigger from the main branch. So we need to tell CircleCI to use a specific branch. + # We can do that by passing in the target-branch. + # This solution is based on this comment: https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/issues/61#issuecomment-1662021882 + # But we can also see that the following code reads from this parameter: https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/blob/a81cd720792a6088debd7f182b552845abb86f1b/src/lib/CircleCIPipelineTrigger.ts#L66 + # Even though it seems to be undocumented as of writing. + # + # Note 2: this assumes that the github client is installed + # As of writing, this is installed in ubuntu-latest + # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#cli-tools + + - name: 'Get PR branch' + run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName') + env: + REPO: ${{ github.repository }} + PR_NO: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Trigger CircleCI workflow id: trigger_circleci_workflow if: success() uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.2.0 with: + target-branch: ${{ steps.get-branch.outputs.branch }} GHA_Meta: "run-from-github-comments" env: CCI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }}