name: R valgrind tests

on:
  pull_request_review_comment:
    types: [created]

jobs:
  test-r-valgrind:
    name: r-package (ubuntu-latest, R-devel, valgrind)
    if: github.event.comment.body == '/gha run r-valgrind' && contains('OWNER,MEMBER,COLLABORATOR', github.event.comment.author_association)
    timeout-minutes: 120
    runs-on: ubuntu-latest
    container: wch1/r-debug
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2.3.4
        with:
          fetch-depth: 5
          submodules: true
      - name: Install packages
        shell: bash
        run: |
          RDscriptvalgrind -e "install.packages(c('R6', 'data.table', 'jsonlite', 'testthat'), repos = 'https://cran.r-project.org')"
          sh build-cran-package.sh
          RDvalgrind CMD INSTALL --preclean --install-tests lightgbm_*.tar.gz || exit -1
      - name: Run tests with valgrind
        shell: bash
        run: ./.ci/test_r_package_valgrind.sh
