name: R artifact builds

on:
  pull_request_review_comment:
    types: [created]

jobs:
  cran-package:
    name: cran-package
    if: github.event.comment.body == '/gha build r-artifacts' && contains('OWNER,MEMBER,COLLABORATOR', github.event.comment.author_association)
    timeout-minutes: 60
    runs-on: ubuntu-latest
    container: rocker/r-base
    steps:
      - name: Install Git before checkout
        shell: bash
        run: |
          apt-get update
          apt-get install --no-install-recommends -y git
      - name: Checkout repository
        uses: actions/checkout@v2.3.4
        with:
          fetch-depth: 5
          submodules: true
      - name: Build package
        shell: bash
        id: build_package
        run: |
          sh build-cran-package.sh || exit -1
          LGB_VERSION=$(cat VERSION.txt | sed "s/rc/-/g")
          ARTIFACT_NAME=lightgbm-${LGB_VERSION}-r-cran.tar.gz
          mv lightgbm_${LGB_VERSION}.tar.gz ${ARTIFACT_NAME}
          echo "::set-output name=artifact_name::${ARTIFACT_NAME}"
          echo "::set-output name=artifact_path::$(pwd)/${ARTIFACT_NAME}"
      - name: Upload package
        uses: actions/upload-artifact@v2
        with:
          name: ${{ steps.build_package.outputs.artifact_name }}
          path: ${{ steps.build_package.outputs.artifact_path }}
