Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wily fails when enabled on GitHub workflow #141

Closed
edmondop opened this issue Feb 6, 2022 · 8 comments
Closed

Wily fails when enabled on GitHub workflow #141

edmondop opened this issue Feb 6, 2022 · 8 comments

Comments

@edmondop
Copy link
Contributor

edmondop commented Feb 6, 2022

Describe the bug
I have added a specific job to my Github Workflow without installing wily locally and Wily fails with a git error:

Failed to setup archiver: '<class 'git.exc.GitCommandError'> - Cmd('git') failed due to: exit code(128)
  cmdline: git diff --numstat 4b2122317b4775a75d30403fc158ea89bac3d204 ce16aee57f19e7e948a4794779d5aa5135b64e8f --
  stderr: 'fatal: bad object 4b2122317b4775a75d30403fc158ea89bac3d204''

To Reproduce
Add a job to a Github pipeline to your code like so:

  evaluate-complexity:
    name: Evaluate code complexity
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.10.0
    - name: Install Wily and compile cache
      run: |
            pip install wily
            wily build my_proj
    - name: Compute code complexity diff with main
      run: "wily diff my_proj/ -r main"
      id: run_wily

Expected behavior
Build would succeed

Additional context
It's interesting that the git diff command copy-pasted on my machine works correctly

@skarzi
Copy link
Contributor

skarzi commented Feb 7, 2022

Hi 👋

that's probably because actions/checkout fetches only a single commit by default.
Try to use: fetch-depth: 0 to checkout the full history or write some custom script to fetch only needed commits

@edmondop
Copy link
Contributor Author

edmondop commented Feb 8, 2022

Thanks a lot for your help. That resolves the problem with the bad object, but not Wily fails elsewhere

Run wily build my_pkg/ test/
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/wily/commands/build.py", line 30, in build
    archiver = archiver.cls(config)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/wily/archivers/git.py", line 38, in __init__
    self.current_branch = self.repo.active_branch
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/git/repo/base.py", line [7](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:7)97, in active_branch
    return self.head.reference
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/git/refs/symbolic.py", line 294, in _get_reference
    raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
TypeError: HEAD is a detached symbolic reference as it points to '7e0196a45590b167123caab43179b6f2d[8](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:8)b3303e'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.0/x64/bin/wily", line 8, in <module>
    sys.exit(cli())
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/click/core.py", line 165[9](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:9), in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.[10](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:10).0/x64/lib/python3.10/site-packages/click/core.py", line [13](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:13)95, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/click/decorators.py", line [26](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:26), in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/wily/__main__.py", line 99, in build
    build(
  File "/opt/hostedtoolcache/Python/3.10.0/x64/lib/python3.10/site-packages/wily/commands/build.py", line [33](https://github.com/edmondo1984/my-pkg/pull/19/checks#step:5:33), in build
    logger.error(f"Failed to setup archiver: '{e.message}'")
AttributeError: 'TypeError' object has no attribute 'message'

@skarzi
Copy link
Contributor

skarzi commented Feb 8, 2022

Are you running your action on the pull_request event?

The problem is you are in a detached HEAD state, see this StackOverflow post for reference

@edmondop
Copy link
Contributor Author

edmondop commented Feb 8, 2022

Correct, why is the pull request in detached HEAD?

@tonybaloney
Copy link
Owner

PR will copy the code at the commit hash instead of checking out the particular branch.
Wily needs to use the git API to checkout previous revisions and build a history.

IIRC you can use wily build <path> -a filesystem to make it only run the analytics on the current changes.

@tonybaloney
Copy link
Owner

checkout the build docs for more https://wily.readthedocs.io/en/latest/commands/build.html#wily

@edmondop
Copy link
Contributor Author

edmondop commented Feb 9, 2022

I think it is desirable to run Wily on a PR to compare with the previous result, can you please suggest how to do it?

@edmondop
Copy link
Contributor Author

#143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants