From d57e422cb429b1fa0e66122ddfbe2f9cb5bacc25 Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Fri, 26 Jul 2024 18:53:16 -0300 Subject: [PATCH 1/4] added target-branch parameter to trigger tests from the right branch --- .github/workflows/trigger_all_tests.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/trigger_all_tests.yml b/.github/workflows/trigger_all_tests.yml index ad9c3d814e..a724b79210 100644 --- a/.github/workflows/trigger_all_tests.yml +++ b/.github/workflows/trigger_all_tests.yml @@ -31,12 +31,21 @@ jobs: fi echo "User is a member of the organization" + + - name: 'Get github 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 }} From bd3a9609c47d2fb2c970133c977941de8d87671e Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Fri, 26 Jul 2024 18:55:48 -0300 Subject: [PATCH 2/4] slight cleanup --- .github/workflows/trigger_all_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trigger_all_tests.yml b/.github/workflows/trigger_all_tests.yml index a724b79210..0c0c3be6f5 100644 --- a/.github/workflows/trigger_all_tests.yml +++ b/.github/workflows/trigger_all_tests.yml @@ -32,7 +32,7 @@ jobs: echo "User is a member of the organization" - - name: 'Get github branch' + - name: 'Get GitHub branch' run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName') env: REPO: ${{ github.repository }} From 105fc58ad29ed627e149782c4e31e9de2f40e516 Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Fri, 26 Jul 2024 19:00:23 -0300 Subject: [PATCH 3/4] added comment explaining --- .github/workflows/trigger_all_tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/trigger_all_tests.yml b/.github/workflows/trigger_all_tests.yml index 0c0c3be6f5..bc8c79f53c 100644 --- a/.github/workflows/trigger_all_tests.yml +++ b/.github/workflows/trigger_all_tests.yml @@ -32,6 +32,12 @@ jobs: 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. + - name: 'Get GitHub branch' run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName') env: From c6aef2eeb046a729f81120079ed3ca0566af75a8 Mon Sep 17 00:00:00 2001 From: Andy Boedo Date: Mon, 29 Jul 2024 09:58:54 -0300 Subject: [PATCH 4/4] improvements from PR comments --- .github/workflows/trigger_all_tests.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trigger_all_tests.yml b/.github/workflows/trigger_all_tests.yml index bc8c79f53c..d02439e43e 100644 --- a/.github/workflows/trigger_all_tests.yml +++ b/.github/workflows/trigger_all_tests.yml @@ -31,14 +31,17 @@ 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 GitHub branch' + - 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 }}