anapaulagomes / pytest-picked

Run the tests related to the changed files (according to Git) 🤓
MIT License
368 stars 16 forks source link

--mode=branch currently unusable with GitHub Actions checkout #92

Closed matthewfeickert closed 3 years ago

matthewfeickert commented 4 years ago

Hi. It seems that at the moment this (very cool!) project isn't usable when run with --mode=branch using GitHub Actions checkout action (the start of pretty much every GHA workflow). If I attempt to use the something like the following

on:
  push:

jobs:
  test:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools wheel
        python -m pip install --ignore-installed -U -q --no-cache-dir -e .
        python -m pip list
    - name: Test with pytest
      run: |
        python -m pytest -r sx --picked=first --mode=branch

I'll get

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

in the printed pytest logs. This is because the checkout action will checkout the current branch and then put the project under remotes/origin/. So adding in

    - name: Check what branches are available
      run: |
        git branch -a

would show something like

* name-of-branch-being-tested-in-pr
  remotes/origin/master

Would it be possible to look for some pattern that could match this if master isn't detected? Or allow for a branch name to given as an argument to test relative to?

anapaulagomes commented 3 years ago

Hello @matthewfeickert! Just noticed that I answer you only in my mind (sorry about that). Would this help you https://github.com/anapaulagomes/pytest-picked/pull/113? I'll be releasing a new version in the next days.

matthewfeickert commented 3 years ago

Would this help you #113?

From taking a brief look at it I think it will. Thanks @pschroeder89!

I'll be releasing a new version in the next days.

Okay great. I'm watching the releases on GitHub, but if you can ping here when it is up on PyPI I'll check my use case and see if that resolves this Issue.

anapaulagomes commented 3 years ago

Hello @matthewfeickert and @pschroeder89, I just release a test version on TestPypi. Would you be kind enough to test it locally? Many thanks. pip install -i https://test.pypi.org/simple/ pytest-picked

pschroeder89 commented 3 years ago

Thanks @anapaulagomes, I just tested locally and it's working:

pytest --picked --mode=branch --parent-branch=main
pytest --picked --mode=branch --parent-branch=master --collect-only               
collected 51 items / 4 deselected / 47 selected                                                              
pytest --picked --mode=branch --parent-branch=main --collect-only               
collected 51 items / 8 deselected / 43 selected                                                              

Thanks!

anapaulagomes commented 3 years ago

Thank you, @pschroeder89! I'll publish it on Pypi.

matthewfeickert commented 3 years ago

@anapaulagomes Sorry for not getting back in a timeline manner, but having had time to test PR #113 in the new release it doesn't address the use case of my Issue actually. Can we please reopen this Issue?

In the following GHA workflow

on:
  push:

jobs:
  test:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools wheel
        python -m pip install --ignore-installed -U -q --no-cache-dir -e .
        python -m pip list
    - name: Test with pytest
      run: |
        python -m pytest -r sx --picked=first --mode=branch --parent-branch=remotes/origin/master

this fails with

ERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...]
__main__.py: error: unrecognized arguments: --parent-branch=remotes/origin/master
  inifile: /home/runner/work/pyhf/pyhf/pyproject.toml
  rootdir: /home/runner/work/pyhf/pyhf

When given the git diff command being run here

https://github.com/anapaulagomes/pytest-picked/blob/1516fcdd341787a03f6155aaf74ecd9c024eedf7/pytest_picked/modes.py#L57

I was expecting it to have found

$ git diff --name-status --relative remotes/origin/master 
M       .github/workflows/ci.yml
M       setup.py

I'll note that

python -m pytest -r sx --picked=first --mode=branch --collect-only

runs correctly as expected.

@pschroeder89 as the PR author do you have thoughts on what might be happenng here?

anapaulagomes commented 3 years ago

Hey @matthewfeickert, thanks for looking into it. Did you test it using the Test PyPi package? This should be the one (the automation for publishing the package to Pypi failed yesterday and I'll look into it today). I'll reopen the issue anyways.

anapaulagomes commented 3 years ago

Now the plugin is available on Pypi too, @matthewfeickert.

matthewfeickert commented 3 years ago

Did you test it using the Test PyPi package? This should be the one (the automation for publishing the package to Pypi failed yesterday and I'll look into it today). I'll reopen the issue anyways.

No, sorry, I was using PyPI. It was late when I was testing this and so I was a bit lazy and didn't check to make sure that the version I got with python -m pip install --upgrade pytest-picked was in fact v0.4.6 (I just saw that it had downloaded a new release from PyPI).

Now the plugin is available on Pypi too.

Indeed! :) I can confirm that v0.4.6 is exhibiting the behavior I wanted, so I'll go ahead and close this now.

Thank you very much for adding this in your PR @pschroeder89 and thank you very much for developing this library @anapaulagomes. Happy holidays!

anapaulagomes commented 3 years ago

Awesome! Happy holidays to you guys too! @matthewfeickert @pschroeder89 🍻