How to run .bat file in the repository

I want to run a .bat file at the root of the repository, so I create a job to checkout the repo first, then try to find the file to run it in the second job. I thought this should be very simple, but I just can’t get it right… This is my YAML file.

name: MSBuild

    branches: [ main ]
    branches: [ main ]

  SOLUTION_FILE_PATH: ./mysolution.sln

  contents: read

    runs-on: windows-latest
    - uses: actions/checkout@v3

    runs-on: windows-latest
    needs: checkout
    - working-directory: ${{env.GITHUB_WORKSPACE}}
      run: ./premake.bat
    runs-on: windows-latest
    needs: premake

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@v1.0.2

    - name: Restore NuGet packages
      working-directory: ${{env.GITHUB_WORKSPACE}}
      run: nuget restore ${{env.SOLUTION_FILE_PATH}}

    - name: Build Solution
      working-directory: ${{env.GITHUB_WORKSPACE}}
      run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

Github keeps telling me that the “path is incorrect” or “no such file” or “premake.bat is not recognized as a name of …”, I thought ${{env.GITHUB_WORKSPACE}} is my current working directory, but it is not, I also tried to print out ${{env.GITHUB_WORKSPACE}} and .\, but the ls -a command always returns empty on both powershell and bash shell, what am I missing here? Does ls even work in Github actions?

The thing you’re missing here is that each job in your workflow gets a fresh VM, with a fresh filesystem, and thus a fresh (empty) workspace. Your checkout job retrieves the repository data and ends, then the runner VM is discarded, and with it the repository data. So each job that works with your repository data will need to contain an actions/checkout step of its own.

The best solution for your workflow above is to put all the steps you currently have into one job.

If you later find yourself in a situation where multiple jobs make more sense (e.g. one build job creates an artifact, and then other jobs test and deploy that artifact) check Passing data between jobs in a workflow.