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 artifact builds
      if: github.event.comment.body == '/gha run build-r-artifacts'
      run: |
        $GITHUB_WORKSPACE/.ci/trigger_dispatch_run.sh \
          "${{ github.event.issue.pull_request.url }}" \
          "${{ github.event.comment.id }}" \
          "gha_run_build_r_artifacts"

    - 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"
