0

What I have so far is this code:

name: test run

on:
  push:
    branches:
        - V2.0

jobs:
  build:

    runs-on: [windows-2019]

    steps:
    - uses: actions/checkout@v2

    - 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
        pip install pyautogui
        pip install opencv-python
        pip install numpy
        pip install pynput
       
    - name: Test
      run: python Cristishor201/[email protected]/src/pytest.py

And I want to run pytest.py script which is inside my_repo repository, branch V2.0, and in folder src. Does anyone have an idea how to do this ?

UPDATE 1:

I found this article when he put github.ref environment variable using if statement. The problem with this solution is that it skip the code, and I already filtered the branch in the trigger block.

name: my workflow
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Execute tests
        run: exit 0
  deploy:
    runs-on: ubuntu-latest
    needs: test
    if: github.ref == 'refs/heads/master'
    steps:
      - name: Deploy app
        run: exit 0

I tried using env: instead if: but it didn't work.

3
  • What's the error you're getting? Without seeing the error, my guess is you should be using python .\src\pytest.py (assuming the source folder is in your repo root).
    – riQQ
    Commented Aug 26, 2020 at 22:29
  • Deliberately I removed the script from the master branch, and keep it only on the V2.0 branch, for testing purpose. I get: C:\hostedtoolcache\windows\Python\3.8.5\x64\python.exe: can't open file 'src/pytest.py': [Errno 2] No such file or directory Commented Aug 28, 2020 at 6:44
  • Basically I want my trigger and actions to run only at the same branch level. Commented Aug 28, 2020 at 6:47

1 Answer 1

0

Github action actions/checkout@v2 pulls the current branch for which this pipeline was triggered. Since you are specifically telling the pipeline to trigger on V2.0 then you don't need to specify a specific branch to checkout.

Now you are in the current working directory so you can just do the following to properly find your file in the path.

python .\src\pytest.py

Note: this assumes your repo directory structure contains src at the root level of your repo

src
└── pytest.py
4
  • For some reason I can attach yaml file only to the master branch. My trigger is on every push on V2.0 but the actions remaining on what's on the master... :( Commented Aug 28, 2020 at 6:50
  • I tried using with: fetch-depth: 0 but id didn't worked out either. Commented Aug 28, 2020 at 6:52
  • Can you share your repos directory structure? Also did you create V2.0 from master branch? Seems like if you can’t trigger the pipeline on push to V2.0 then something else is going on. Commented Aug 28, 2020 at 14:57
  • I think this is the right answer (after I finished a course :D) Commented Nov 26, 2023 at 2:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.