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

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
    
  workflow_dispatch:

env:
  SOLUTION_FILE_PATH: ./mysolution.sln
  BUILD_CONFIGURATION: Release

permissions:
  contents: read

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

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

    steps:
    - 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.