Why do I need to prefix npm/yarn scripts with interpreter?

For some reason - run: yarn test-2 step fails.

name: Unit tests
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  build:
    name: Node ${{ matrix.node }} unit tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: ['14']
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node }}
      - run: yarn install
      - run: yarn test-1
      - run: yarn test-2

And package.json:

    "test-1": "bash ./test.sh",
    "test-2": "./test.sh",

test.sh

#!/bin/env bash
echo $(pwd)

test-2 command fails with:

/bin/sh: 1: ./test.sh: not found
error Command failed with exit code 127.

It doesn’t matter if I’m using bash or sh interpreter.

On my local dev machine (Linux) both versions work.

Apologies on the late reply @ivandotv

That yarn test-2 command should indeed work. Do you by any chance still have this issue, and if so, do you have a reference to a problematic CI as a reference repository that I can look at?

Overall, it looks like you are indeed running the test-2 script in package.json, however the script can’t find the ./test.sh file.