I created a GitHub action on:issue_comment, I can see the flow running only in the action tab, but not in the PR, where I made the comment. I want to comment in a PR and trigger a check on that PR (not on master)
here is my workflow:
name: issue-comment-CI-test
on:
issue_comment:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: echo ${{ github.event.comment.body }}
currently, I'm just printing the comment body, But I plan to check the body, and if it is equal to "run integration tests" then I'll run my integration tests (maven)
Basically you need to checkout to the PR origin. For that, first make a API request to the pr url and fetch all ref. Then do the checkout on the fetched repo and branch.
Step1
- name: Github API Request
id: request
uses: octokit/[email protected]
with:
route: ${{ github.event.issue.pull_request.url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Step 2
- name: Checkout PR Branch
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ fromJson(steps.request.outputs.data).head.repo.full_name }}
ref: ${{ steps.pr_data.outputs.branch }}
You can follow the following example, specially the GitHub API Request part.
I've also implemented it in one of our workflows, you can take reference from that as well.
https://github.com/adrianjost/workflow-trigger-comment-example/blob/master/.github/workflows/demo.yml https://github.com/TeamAmaze/AmazeFileManager/blob/master/.github/workflows/android-debug-artifact-ondemand.yml
Used built-in gh command to fetch the branch instead of using actions/checkout.
name: issue-comment-CI-test
on:
issue_comment:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
gh pr checkout ${{ github.event.issue.number }}
# do your job...
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required for gh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With