dorny / paths-filter

Conditionally run actions based on files modified by PR, feature branch or pushed commits
MIT License
2.14k stars 239 forks source link

[error] The process '/usr/bin/git' failed with exit code 128 #24

Closed dakshshah96 closed 4 years ago

dakshshah96 commented 4 years ago

I'm unable to get my changes job to run which uses paths-filter within it. It always fails with the following error:

Screenshot 2020-07-16 11 09 05

My workflow looks like this:

name: Deploy API server
on:
  push:
    branches: [master]

jobs:
  changes:
    runs-on: ubuntu-latest
    # Set job outputs to values from filter step
    outputs:
      apiServer: ${{ steps.filter.outputs.apiServer }}
    steps:
    - name: Checkout source code
      uses: actions/checkout@v1

    - name: Check for changes
      uses: dorny/paths-filter@v2.2.0
      id: filter
      with:
        filters: |
          apiServer:
            - 'packages/api-server/**/*'

  tests:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: packages/api-server

    if: ${{ needs.changes.outputs.apiServer == 'true' }}
    steps:
    - name: Checkout source code
      uses: actions/checkout@v1

    - name: Use Node.js 12.x
      uses: actions/setup-node@v1
      with:
        node-version: "12.x"

    - name: Install dependencies
      run: yarn

    - name: Tests
      run: yarn test

I don't know if it's paths-filter that's causing it but thought I'll open this issue just in case it helps.

dorny commented 4 years ago

I would say the issue is you are using v1 of the checkout action: uses: actions/checkout@v1. It doesn't persist git authentication token so as paths-filter is trying to fetch additional commit, git command interactively asks for username/password which causes the error.

Please try it with uses: actions/checkout@v2 and let me know if it solved the issue. Anyway I should improve the documentation and error message for this case.

dakshshah96 commented 4 years ago

That seems to have fixed it!

Thanks so much for your help. Would've never figured this out otherwise.

dakshshah96 commented 4 years ago

@dorny Sorry to trouble you, now I'm unable to echo the value of the output from the previous job:

name: Deploy API server
on:
  push:
    branches: [master]

jobs:
  changes:
    runs-on: ubuntu-latest
    # Set job outputs to values from filter step
    outputs:
      apiServer: ${{ steps.filter.outputs.apiServer }}
    steps:
    - name: Checkout source code
      uses: actions/checkout@v2

    - name: Check for changes
      uses: dorny/paths-filter@v2.2.0
      id: filter
      with:
        filters: |
          apiServer:
            - 'packages/api-server/**/*'

  tests:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: packages/api-server

    steps:
    - run: echo ${{ needs.changes.outputs.apiServer }}

    - name: Checkout source code
      uses: actions/checkout@v1

    - name: Use Node.js 12.x
      uses: actions/setup-node@v1
      with:
        node-version: "12.x"

    - name: Install dependencies
      run: yarn

    - name: Tests
      run: yarn test

Screenshot 2020-07-16 13 19 39

dorny commented 4 years ago

Your tests job doesn't declare it depends on the changes job. See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idneeds

You should have this structure:

jobs:
  changes:
    ...

  tests:
    needs: changes
    ....
dakshshah96 commented 4 years ago

Thanks again! That fixes it.

Can I make PRs for the following?

  1. Document error which occurs when using checkout@v1
  2. Update example code to include needs part
dorny commented 4 years ago

You are right, example in the README page is wrong. PR is welcome if you can make it now. Later afternoon I planned to significantly rework the README page to make it simpler and document incoming new features from develop branch.

Then I'm out for a vacation :)

Hamza5 commented 3 years ago

@dorny, I have the exact problem with the latest version of your action and the checkout@v2. The complete output is the following:

Run dorny/paths-filter@v2.10.1
  with:
    filters: backend:
    - 'multilevel_diacritizer/**'

    token: ***
    list-files: none
    initial-fetch-depth: 100
Get current git ref
  /usr/bin/git branch --show-current
  fatal: not a git repository (or any of the parent directories): .git
Error: The process '/usr/bin/git' failed with exit code 128

I am a beginner in GitHub Actions, and this is the first time I do continuous integration. Here is my workflow file. Could you please tell me where the error is?

name: Continious Integration

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  changes:

    runs-on: ubuntu-latest

    outputs:
      backend: ${{ steps.filter.outputs.backend }}
    #      frontend: ${{ steps.filter.outputs.frontend }}

    steps:
      - uses: dorny/paths-filter@v2.10.1
        id: filter
        with:
          filters: |
            backend:
              - 'multilevel_diacritizer/**'
#            frontend:
#              - 'multilevel_diacritizer_ui/**'

  backend:

    needs: changes
    if: ${{ needs.changes.outputs.backend == 'true' }}
    runs-on: ubuntu-latest

    steps:

    - uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.7.10

    - name: Install Poetry
      uses: snok/install-poetry@v1.1.4
      with:
        virtualenvs-create: true
        virtualenvs-in-project: true

    - name: Load the cached virtual environment
      id: cached-poetry-dependencies
      uses: actions/cache@v2
      with:
        path: .venv
        key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

    - name: Install dependencies
      if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
      run: poetry install --no-interaction --no-root

    - name: Run tests
      run: |
        source .venv/bin/activate
        python -m unittest discover tests/
dorny commented 3 years ago

Hi @Hamza5 You are using the checkout action only in the backend job. In your changes job, there is no checkout of the git repository. When the paths-filter action is executed, there's just an empty folder. That's why you see the error: fatal: not a git repository (or any of the parent directories): .git.

It should work fine when the workflow is triggered by a pull request event. But it can't work for push events - detecting changes in push events requires checkout of the repository.

So the solution is simple - just add the checkout step before paths-filter.

mohammadnoorfgli commented 1 year ago

Hello @dorny,

I'm also facing same issue despite of using checkout step before paths-filter

Below is my workflow file:

name: Python application
on:
  push:
    branches: [ "main" , "wip" ]

  pull_request:
    branches: [ "main" , "wip" ]

jobs:
  Deploy-UAT:
    runs-on: linux-21-uat
    steps:
      - name: Git checkout
        uses: actions/checkout@v2

      - name: Paths Changes Filter And Diff Stat
        uses: dorny/paths-filter@v2.10.2
        id: changes
        with:
          filters: |
            service_:
              - 'Resource/**'

      - name: Set up Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: 3.8

      - name: Upload a Build Artifact
        uses: actions/upload-artifact@v3.1.0
        with:
          name: ofac-screening-api
          path: ${{github.workspace}}/*

      - name: Copy ofac-screening-api files 
        run: cp -avR ${{github.workspace}}/ $HOME/FGApp  

      - name: Creating Virtual Environment
        run: |
          pip3 install --upgrade pip
          python3 -m venv $HOME/FGApp/OFAC-screening-api/env_ofac_screening

      - name: Activating Virtual Environment and installing requirements.txt file
        run: |
          source $HOME/FGApp/OFAC-screening-api/env_ofac_screening/bin/activate
          echo "VIRTUAL ENV:" $VIRTUAL_ENV
          pip3 install --upgrade pip
          pip3 install -r $HOME/FGApp/OFAC-screening-api/requirements.txt
          deactivate

      - name: Copy service file 
        if: steps.changes.outputs.service_ == 'true'
        run: |
          echo '${{secrets.UAT_RUNNER_PASSWORD}}' | sudo -S cp /home/fgi1121113/FGApp/OFAC-screening-api/Resource/amlScreening.service /etc/systemd/system/amlScreening.service
          echo '${{secrets.UAT_RUNNER_PASSWORD}}' | sudo -S systemctl daemon-reload

      - name: Running python script
        run: 
          echo '${{secrets.UAT_RUNNER_PASSWORD}}' | sudo -S systemctl restart amlScreening.service

Error :

Run dorny/paths-filter@v2.10.2
  with:
    filters: service_:
    - 'Resource/**'

    token: ***
    list-files: none
    initial-fetch-depth: [1](https://github.com/FUTURE-GENERALI-INDIA-LIFE-INSURANCE/OFAC-screening-api/actions/runs/3214235346/jobs/5254480317#step:3:1)00
Get current git ref
  /usr/bin/git branch --show-current
  fatal: not a git repository (or any of the parent directories): .git
Error: The process '/usr/bin/git' failed with exit code 1[2](https://github.com/FUTURE-GENERALI-INDIA-LIFE-INSURANCE/OFAC-screening-api/actions/runs/3214235346/jobs/5254480317#step:3:2)[8](https://github.com/FUTURE-GENERALI-INDIA-LIFE-INSURANCE/OFAC-screening-api/actions/runs/3214235346/jobs/5254480317#step:3:8)

image

Please assist

yorhodes commented 1 year ago

also getting the same issue...

mjgs commented 8 months ago

I’m seeing the same problem. I use checkout v3 to checkout the repo, followed by dorny/path-filter. The path filter step always fails with

The process '/usr/bin/git' failed with exit code 128

EA22FD3A-7E09-4849-B509-DB790441D55F

Why does it error?

Update: added screenshot