gh-actions icon indicating copy to clipboard operation
gh-actions copied to clipboard

insufficient permission for adding an object to repository database .git/objects error: Error building trees

Open marcofranssen opened this issue 3 years ago • 3 comments

Describe the bug

On a small new repo this action creates new folders in the .git/objects folder. These objects are owned by root:root as opposed to runner:docker. Therefore any other actions fail when trying to write to git.

How can we reproduce it?

See the logs of this workflow run:

https://github.com/marcofranssen/terraform-provider-curl/actions/runs/2909746851

Environment information

Ubuntu GitHub runner.

marcofranssen avatar Aug 23 '22 08:08 marcofranssen

Probably this is the root cause https://github.com/terraform-docs/gh-actions/issues/50

marcofranssen avatar Aug 23 '22 08:08 marcofranssen

For now I workarround the issue as following:

      - name: Debug
        run: |
          ls -lha .git
          ls -lha .git/objects

      - name: Update module docs
        uses: terraform-docs/[email protected]
        with:
          working-dir: examples/${{ matrix.module }}
          output-file: README.md
          output-method: inject
          git-push: "false"

      - name: Debug
        run: |
          ls -lha .git
          ls -lha .git/objects

      - name: Fix .git owner
        run: sudo chown runner:docker -R .git

      - name: Debug
        run: |
          ls -lha .git
          ls -lha .git/objects

Doing the sudo chown runner:docker -R .git fixes the problem for any next steps like creating a PR in my workflow.

marcofranssen avatar Aug 30 '22 08:08 marcofranssen

I'm experimenting exactly same issue, using git-push: "false" and it fails committing changes in next step

 runs-on: ubuntu-latest
...
 - name: Render terraform docs inside the main and the modules README.md files
    id: terraform-docs
    uses: terraform-docs/[email protected]
    with:
      find-dir: .
      args: --sort-by required
      indention: 3
      git-push: "false"

  - name: Create Pull Request
     ...

@marcofranssen's workaround solves the issue but I would like to understand the cause. What's weird to me is that it was working fine, but suddenly it started crashing. I compared both workflows and with the same versions for all actions (same SHA), the only difference between the previous job that works and now is a new version of the image runner, I can't test with the old version as it's impossible to specify an image version.

ocobles avatar Feb 08 '23 11:02 ocobles