axel-op / dart-package-analyzer

GitHub Action that uses the Dart Package Analyzer to compute the Pub score of Dart/Flutter packages
MIT License
52 stars 9 forks source link

fatal: detected dubious ownership in repository at '/github/workspace' #27

Closed littleGnAl closed 8 months ago

littleGnAl commented 8 months ago

I run into an issue when using the axel-op/dart-package-analyzer@v3 recently, the error log

Running pana
  {"logName":"pana","level":"WARNING","message":"Flutter SDK path was not specified, pana will use the default Dart SDK to run `dart analyze` on Flutter packages."}
  {"logName":"pana","level":"INFO","message":"Running `dart --version`..."}
  {"logName":"pana","level":"INFO","message":"Running `flutter --no-version-check --version --machine`..."}
  {"logName":"pana","level":"INFO","message":"Running `git rev-parse --show-toplevel`..."}
  {"level":"SHOUT","message":"Problem analyzing /github/workspace","error":"Failed to run `rev-parse --show-toplevel`.\nfatal: detected dubious ownership in repository at '/github/workspace'\nTo add an exception for this directory, call:\n\n\tgit config --global --add safe.directory /github/workspace","stackTrace":"#0      runGit (package:pana/src/tool/git_tool.dart:41:5)\n<asynchronous suspension>\n#1      withTempDir (package:pana/src/utils.dart:134:12)\n<asynchronous suspension>\n#2      runGitIsolated (package:pana/src/tool/git_tool.dart:52:10)\n<asynchronous suspension>\n#3      _detectGitRoot (package:pana/src/package_analyzer.dart:274:14)\n<asynchronous suspension>\n#4      PackageAnalyzer.inspectDir.<anonymous closure> (package:pana/src/package_analyzer.dart:95:23)\n<asynchronous suspension>\n#5      withTempDir (package:pana/src/utils.dart:134:12)\n<asynchronous suspension>\n#6      main (file:///root/.pub-cache/hosted/pub.dev/pana-0.22.2/bin/pana.dart:2[49](https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/actions/runs/8075870137/job/22154729575?pr=1585#step:6:51):19)\n<asynchronous suspension>\n"}
Error: Pana exited with code 1

here's the failed job https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/actions/runs/8075870137/job/22154729575?pr=1585

After some search, https://github.com/actions/runner-images/issues/6775, I tried to add this as a workaround in my step, but it's no luck.

git config --global --add safe.directory '/github/workspace'

I'm not very sure if it should be added inside the Dockerfile, I think it can easily reproduce this issue with the following workflow config

jobs:
  flutter_codestyle_check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
        with:
          channel: 'stable'
      - uses: axel-op/dart-package-analyzer@v3
        id: analysis
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
axel-op commented 8 months ago

Hello,

Thanks for reporting this issue.

After some search, actions/runner-images#6775, I tried to add this as a workaround in my step, but it's no luck.

The problem is that pana runs Git in a way that prevents any custom config to be used, this is why your workaround didn't work.

I fixed the issue by assigning the ownership of the Git directory to the user set in the container.

Btw, this issue failed my automated tests recently so it shouldn't have made its way to you, but I thought it was a bug in my tests and I changed the tests instead of the code... I'll be more careful next time.

JaffaKetchup commented 8 months ago

Thanks @axel-op :) no worries about the small break

littleGnAl commented 8 months ago

@axel-op It works now, thanks for your work.

buenaflor commented 8 months ago

it's still failing for us, anything we're doing wrong? https://github.com/getsentry/sentry-dart/pull/1918

axel-op commented 8 months ago

@buenaflor Thanks for notifying it. Here's what I did:

Can you please retry the workflow?

buenaflor commented 8 months ago

Still failing unfortunately :(

axel-op commented 8 months ago

I think I found the root cause and definitely fixed the issue. Your package is located in a subdirectory. My initial fix acquires the ownership of this subdirectory only but not of the root repository. The problem is that Git commands are run from the root.

I implemented a fix and added a new test to prevent any regression. Tell me if this solves your issue :)

buenaflor commented 8 months ago

works now, thx!