name: Triggering comments

on:
  issue_comment:
    types: [created]

jobs:
  triggering-tests:
    if: github.event.issue.pull_request && contains('OWNER,MEMBER,COLLABORATOR', github.event.comment.author_association) && startsWith(github.event.comment.body, '/gha run')
    runs-on: ubuntu-latest
    env:
      SECRETS_WORKFLOW: ${{ secrets.WORKFLOW }}
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2.3.4
      with:
        fetch-depth: 5
        submodules: false

    - name: Trigger R valgrind tests
      if: github.event.comment.body == '/gha run r-valgrind'
      run: |
        $GITHUB_WORKSPACE/.ci/trigger_dispatch_run.sh \
          "${{ github.event.issue.pull_request.url }}" \
          "${{ github.event.comment.id }}" \
          "gha_run_r_valgrind"

    - name: Trigger R Solaris CRAN checks
      if: github.event.comment.body == '/gha run r-solaris'
      run: |
        $GITHUB_WORKSPACE/.ci/trigger_dispatch_run.sh \
          "${{ github.event.issue.pull_request.url }}" \
          "${{ github.event.comment.id }}" \
          "gha_run_r_solaris"

    - name: Trigger update R configure
      if: github.event.comment.body == '/gha run r-configure'
      run: |
        $GITHUB_WORKSPACE/.ci/trigger_dispatch_run.sh \
          "${{ github.event.issue.pull_request.url }}" \
          "${{ github.event.comment.id }}" \
          "gha_run_r_configure"
