Home > Back-end >  GitHub Action incapable of pushing due to "unsafe repository" error
GitHub Action incapable of pushing due to "unsafe repository" error

Time:04-14

I have a private GitHub repository that has a GitHub Action that pushes files which are created at the Action's runtime to the repository. Since yesterday (2022-04-12), the Action fails at the following step:

    - name: Push data to repo
      uses: github-actions-x/[email protected]
      with:
        push-branch: 'main'
        commit-message: 'Add current data'
        force-add: 'true'
        files: *.zip
        name: autoupdate

Running this step triggers the following error message:

Command line: | /usr/bin/git checkout -B main
Stderr:       | fatal: unsafe repository ('/github/workspace' is owned by someone else)
              | To add an exception for this directory, call:
              | 
              |     git config --global --add safe.directory /github/workspace

Based on the error message I added the following to my GitHub Action:

    - name: Fix issue with repository ownership
      run: |
        git config --global --add safe.directory /home/runner/work/vksm/vksm
        git config --global --add safe.directory /github/workspace

I have also added /home/runner/work/vksm/vksm as I was not sure if /github/workspace in the error message is meant as a generic path or not. /home/runner/work/vksm/vksm is where the checkout step puts the repository when the Action runs: /usr/bin/git init /home/runner/work/vksm/vksm

The whole sequence of steps is as follows:

 steps:
    - name: Checkout the repository
      uses: actions/checkout@v2

    - name: Fix issue with repository ownership
      run: |
        git config --global --add safe.directory /home/runner/work/vksm/vksm
        git config --global --add safe.directory /github/workspace

    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      ...

    - name: Install dependencies
      run: |
        pip install requests
        
    - name: Run Python script
      run: |
        python script.py

    - name: Push data to repo
      uses: github-actions-x/[email protected]
      ...

However, the error still occurs.

This questions is possibly related to enter image description here

  • Related