Home > Blockchain >  Github action pointing to a different directory than the current directory
Github action pointing to a different directory than the current directory

Time:12-30

When running an action during a pull request the path emitted by mkdir while trying to create a folder was different than the current directory set by a previous step. This also continues to the next steps as follows..

name: Publish demo
on: 
  push:
    branches:    
      - 'develop'
  pull_request:
    branches:    
      - 'develop'
jobs:
  web-deploy:
    name: Deploy
    runs-on: windows-latest
    steps:
    - name: Get latest code
      uses: actions/checkout@v3
      
    - name: Setup MSBuild
      uses: microsoft/setup-msbuild@v1

    - name: Setup NuGet
      uses: NuGet/[email protected]
      
    - name: Navigate to Workspace
      run: cd ${{ github.workspace }}/demo_project

    - name: Create Build Directory
      run: mkdir _build
      
    - name: Restore Packages
      run: nuget restore demo_project.csproj

    - name: Build Solution
      run: |
        msbuild.exe demo_project.csproj /nologo /nr:false /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:platform="Any CPU" /p:configuration="Release" /p:PublishUrl="_build"
    - name: Sync files
      uses: SamKirkland/[email protected]
      with:
        local-dir: "_build"
        server: <server>
        username: <username>
        password: ${{ secrets.password }}

So, in this line..

      run: mkdir _build

the _build folder should be created in demo_project but instead it gets created in ${{ github.workspace }} which i think means that setting the current directory here..

      run: cd ${{ github.workspace }}/demo_project

which in turn prints out this in job view..

Run cd D:\a\demo_solution\demo_solution/demo_project

and..

Input file does not exist: D:\demo_project.csproj.

did not take effect. So, what am i missing?

CodePudding user response:

you could specify a different working directory for a job:

You can provide default shell and working-directory options for all run steps in a job

jobs:
  web-deploy:
    name: Deploy
    runs-on: windows-latest
    defaults:
      run:
        shell: bash
        working-directory: ${{ github.workspace }}/demo_project
    steps:
    - name: Get latest code
      uses: actions/checkout@v3

  • Related