name: Test_Change
on: pull_request
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - id: file_changes
        uses: trilom/file-changes-action@v1.2.3
        with:
          output: 'json'
          fileOutput: 'json'
      - name: Check out repository code
        uses: actions/checkout@v2
      - name: Run changes files through test script
        env:
          ALCHEMY_CONNECTION_ARBITRUM: ${{ secrets.ALCHEMY_CONNECTION_ARBITRUM }}
          ALCHEMY_CONNECTION_ETHEREUM: ${{ secrets.ALCHEMY_CONNECTION_ETHEREUM }}
        run: |
          RUN_FILES=$(
            MODIFIED=${{ steps.file_changes.outputs.files_modified}} \
            ADDED=${{ steps.file_changes.outputs.files_added}} \
            node ${{ github.workspace }}/.github/workflows/getFileList.js
          )

          if [ "$RUN_FILES" = "[]" ]; then
            echo "No adapter files were modified"
            exit 0
          fi

          npm ci

          for i in $(echo $RUN_FILES | tr  -d '"[]' | tr "," "\n")
          do
            {
              npm run test --adapter=${i} 2>&1 | tee output.txt
              node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/yield-server/yield-server/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" ${i}
              if grep -q "PASS src/adaptors/test.js" output.txt; then
                exit 0;
              else
                exit 1;
              fi
            } || {
              echo -n $i
              echo ' doesnt run'
            }
          done
