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

Bug: Triggering via issue_comment Action Kicks Off Workflow For Incorrect Commit/Branch #61

Open
1 task done
jblacker opened this issue Jul 17, 2023 · 3 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@jblacker
Copy link

jblacker commented Jul 17, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I attempt to trigger a workflow in CircleCI from this GitHub Action on the created issue_comment event it works properly, but then starts the workflow on the incorrect branch within CircleCI. It appears to start the pipeline for the commit at HEAD of main rather than on the branch/commit in the Pull Request that triggered the action.

Minimum reproduction code

https://gist.github.com/jblacker/4f8b3d87b3b0b60a00c166e05d6ced81

Steps to reproduce

  1. Create a workflow pipeline in CircleCI using the conditions in the "other" section below
  2. Use the example in my gist to create a GitHub Action that triggers said pipeline on CircleCI
  3. Create a new branch that's not the default and open a PR
  4. Write the comment on the PR "/deploy-staging"
  5. Check CircleCI you'll see that it triggered main (or whatever your default is) rather than the head of the current branch of the PR.

Expected behavior

I would have expected the branch that the PR is for to be triggered in CircleCI.

GitHub Action Version

1.0.5

Other

Here's the trigger on the CircleCI side of things:

when:
      or:
        - and:
          - equal: [<<pipeline.parameters.deploy_branch>>, <<pipeline.git.branch>>]
          - equal: [<<pipeline.parameters.deploy>>, true]
        - and:
          - <<pipeline.parameters.GHA_Action>>
          - equal: [<<pipeline.parameters.GHA_Event>>, "issue_comment"]
          - equal: [<<pipeline.parameters.GHA_Meta>>, "DEPLOY_STAGING"]
@jblacker jblacker added the bug Something isn't working label Jul 17, 2023
@jblacker
Copy link
Author

This issue is actually mentioned in PR #11, but after it was merged. Figured it made sense to create a top-level ticket pointing out this issue.

@ghost
Copy link

ghost commented Aug 2, 2023

Just ran into the same thing. You can use version 1.1.0 of this action and provide target-branch as parameter.
Unfortunately you need to fetch the branch name manually beforehand. (ref: actions/checkout#331)

This works for me:

name: pr comment
on:
  issue_comment:
    types: [created]
jobs:
  deploy-dev:
    if: github.event.issue.pull_request && contains(github.event.comment.body, '/dev')
    name: Deploy dev
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: write
    steps:
      - id: 'get-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
        id: trigger-circleci
        uses: CircleCI-Public/[email protected]
        with:
          target-branch: ${{ steps.get-branch.outputs.branch }}
        env:
          CCI_TOKEN: ${{ secrets.CCI_TOKEN }}

@GreaseMonk
Copy link

GreaseMonk commented Aug 3, 2023

@iwt-denniskribl

Just ran into the same thing. You can use version 1.1.0 of this action and provide target-branch as parameter.

Please could you add this to trigger-circleci-pipeline-action/examples/ ?
I have been looking for a solution like this all day and this finally worked!
My usecase is also a slash command as comment to trigger a workflow that should not normally run.

aboedo added a commit to RevenueCat/purchases-ios that referenced this issue Jul 29, 2024
…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:
CircleCI-Public/trigger-circleci-pipeline-action#61 (comment)

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.
aboedo added a commit to RevenueCat/purchases-ios that referenced this issue Jul 30, 2024
Fix trigger all tests branch (again). 

This was a pretty obvious bug - I was using the output of the
`get-branch` step, but I never set the id of the step to that.

This setup now more closely matches the [solution laid out as a github
comment](CircleCI-Public/trigger-circleci-pipeline-action#61 (comment))
jamesrb1 pushed a commit to RevenueCat/purchases-ios that referenced this issue Aug 7, 2024
…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:
CircleCI-Public/trigger-circleci-pipeline-action#61 (comment)

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.
jamesrb1 pushed a commit to RevenueCat/purchases-ios that referenced this issue Aug 7, 2024
Fix trigger all tests branch (again). 

This was a pretty obvious bug - I was using the output of the
`get-branch` step, but I never set the id of the step to that.

This setup now more closely matches the [solution laid out as a github
comment](CircleCI-Public/trigger-circleci-pipeline-action#61 (comment))
rocxteady pushed a commit to rocxteady/purchases-ios-spm that referenced this issue Aug 7, 2024
…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:
CircleCI-Public/trigger-circleci-pipeline-action#61 (comment)

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.
rocxteady pushed a commit to rocxteady/purchases-ios-spm that referenced this issue Aug 7, 2024
Fix trigger all tests branch (again). 

This was a pretty obvious bug - I was using the output of the
`get-branch` step, but I never set the id of the step to that.

This setup now more closely matches the [solution laid out as a github
comment](CircleCI-Public/trigger-circleci-pipeline-action#61 (comment))
nyeu pushed a commit to RevenueCat/purchases-ios that referenced this issue Oct 2, 2024
…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:
CircleCI-Public/trigger-circleci-pipeline-action#61 (comment)

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.
nyeu pushed a commit to RevenueCat/purchases-ios that referenced this issue Oct 2, 2024
Fix trigger all tests branch (again). 

This was a pretty obvious bug - I was using the output of the
`get-branch` step, but I never set the id of the step to that.

This setup now more closely matches the [solution laid out as a github
comment](CircleCI-Public/trigger-circleci-pipeline-action#61 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants