name: Dataset profile

on: [issue_comment]

jobs:
  comment:
    if: (github.event.comment.author_association == 'COLLABORATOR') && contains(github.event.comment.body, '/ds-prof') && (github.event.issue.pull_request != null)
    runs-on: ubuntu-latest
    steps:
      - name: Chatop
        uses: machine-learning-apps/actions-chatops@master
        with:
          TRIGGER_PHRASE: '/ds-prof'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        id: comment

      - name: Clone master
        uses: actions/checkout@v2
        with:
          path: master

      - name: Clone PR
        uses: actions/checkout@v2
        with:
          ref: ${{ steps.comment.outputs.SHA }}
          path: pr

      - name: Install rar
        run: sudo apt-get -y install unrar

      - name: Set up environment
        uses: conda-incubator/setup-miniconda@v2
        with:
          python-version: 3.8
          environment-file: master/action_files/prof-env.yml

      - name: Run profiles
        shell: bash -l {0}
        run: |
          cd pr/
          python -c 'from nixtla.data.datasets.m4 import M4; M4.load("data", group="Yearly")'
          scalene action_files/prof.py --program-path . --reduced-profile --html --outfile ../pr.html
          cp -r data/ ../master/data/
          cd ../master/
          scalene action_files/prof.py --program-path . --reduced-profile --html --outfile ../master.html
          cd ..
          python master/action_files/comment_reports.py master.html pr.html
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_NUMBER: ${{ steps.comment.outputs.PULL_REQUEST_NUMBER }}
