Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests trigger: add target-branch parameter to trigger from the right branch #4121

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/trigger_all_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ jobs:
fi
echo "User is a member of the organization"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit but there's an extra line here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

# 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: maybe this step can be named "Get PR branch"? "PR" is the relevant bit imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great call, updated!

run: echo ::set-output name=branch::$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the gh CLI will be installed right? I would imagine so, being a github action 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is, listed here:
https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#cli-tools

I'll add a comment that this assumes that it's installed, though, just in case it randomly gets removed one day, although I can't imagine that would ever be the case

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/[email protected]
with:
target-branch: ${{ steps.get-branch.outputs.branch }}
GHA_Meta: "run-from-github-comments"
env:
CCI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }}