skip to Main Content

Today when I run the github actions, shows error like this:

Error: fatal: --local can only be used inside a git repository

this is the full log about the actions log:

Run actions/checkout@v3
Syncing repository: RedDwarfTech/cv_render
Getting Git version info
Temporarily overriding HOME='/home/runner/work/_temp/2abd7da7-7754-4217-b5db-2984399b003e' before making global git config changes
Adding repository directory to the temporary git global config as a safe directory
/usr/bin/git config --global --add safe.directory /home/runner/work/cv_render/cv_render
/usr/bin/git config --local --get remote.origin.url
Error: fatal: --local can only be used inside a git repository
Deleting the contents of '/home/runner/work/cv_render/cv_render'
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Fetching the repository
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'28106b95ce29effd8f28340d7e6cbba265a04e71'

and this is my github actions define:

- name: Checkout source
  uses: actions/checkout@v3
  with:
    lfs: false

why did this issue happen? what should I do to fixed this issue? This is the full github actions look liks:

name: cv-render-k8s-pro

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Cache
      uses: actions/cache@v3
      with:
        key: lfs-cache
        path: .git/lfs
        restore-keys: |
          - lfs-cache

    - name: Checkout source
      uses: actions/checkout@v3
      with:
        lfs: false
        
    - name: Install git-lfs
      run: |
        curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
        sudo apt-get install git-lfs

    - name: Set Git LFS default remote URL
      run: |
        git remote set-url origin https://${{ secrets.LFS_USER_NAME }}:${{ secrets.LFS_PASSWORD }}@codeup.aliyun.com/6299c42d487c500c27f5f963/cv_render.git
        git config --global credential.helper store
        git config --global user.email "[email protected]"
        git config --global user.name "jiangchaoquan123456"

    - name: Initialize Git LFS
      run: |
        git lfs install

    - name: Pull LFS files
      run: |
        git lfs pull

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v2

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2

    - name: Login to Docker Hub
      uses: docker/login-action@v2
      with:
        registry: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}
        username: ${{ secrets.ALIYUN_DOCKER_REPO_USER_NAME }}
        password: ${{ secrets.ALIYUN_DOCKER_REPO_USER_PASSWORD }}

    - name: Build and push
      uses: docker/build-push-action@v3
      with:
        context: .
        file: Dockerfile
        push: true
        tags: ${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }} 

    - name: deploy to cluster
      uses: steebchen/[email protected]
      with: 
        config: ${{ secrets.KUBE_CONFIG_DATA }}
        command: set image --record deployment/cv-render-service cv-render-service=${{ secrets.ALI_DOCKER_HUB_REGISTRY }}/reddwarf-pro/cv-render:${{ github.sha }} -n reddwarf-pro

    - name: verify deployment
      uses: steebchen/[email protected]
      with:
        config: ${{ secrets.KUBE_CONFIG_DATA }}
        version: v1.21.0
        command: rollout status deployment/cv-render-service -n reddwarf-pro

2

Answers


  1. The error is telling you that you want to do something locally in a directory that’s not a git repository. You will need to find out which is the directory where this command is being executed. Possibilities:

    • your command may be executed at the wrong directory, in which case you will need something like cd /the/path/to/the/correct/directory before your command, or pass the location where the git command is to be executed, like git -C /the/path/to/the/correct/directory <somecommand>
    • your command may be executed at the correct directory, which is not properly initialized as a git repository, in which case you may want to run git init to initialize, or review other steps and find out whether they do something like the removal of the .git folder

    The symptom of your issue is that

    git config --local <whatever>
    

    will error out in the way you have mentioned if it’s not executed either at the correct location or while specifying the correct location, like

    git -C <somepath> config --local <whatever>
    
    Login or Signup to reply.
  2. You’re not using the actions/checkout task in the most default setup 😉. It looks like you’re trying to use LFS storage from a different storage provider than GitHub.

    Your actions/cache, if successful, will create a .git/lfs folder in the runners working directory. That .git folder isn’t a proper git repo, it’s missing all kinds of stuff, but it will trigger a number of different routines in the runner as it needs to check whether the repo is usable for this workflow run or needs to be cleaned up. That code fails.

    I’m guessing you can work around the issue by placing the actions/checkout step before the action/cache step. That way there is no .git folder and the actions/checkout step will act as normal on a hosted runner. The actions/cache step can then restore the LFS cache in the .git folder and after that you can change the LFS configuration to sync the rest of the files if needed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search