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/my_repo@V2.0/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.

Cristian F.
  • 328
  • 2
  • 12
  • 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 Aug 26 '20 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 – Cristian F. Aug 28 '20 at 06:44
  • Basically I want my trigger and actions to run only at the same branch level. – Cristian F. Aug 28 '20 at 06:47

1 Answers1

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
Edward Romero
  • 2,905
  • 1
  • 5
  • 17
  • 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... :( – Cristian F. Aug 28 '20 at 06:50
  • I tried using `with: fetch-depth: 0` but id didn't worked out either. – Cristian F. Aug 28 '20 at 06: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. – Edward Romero Aug 28 '20 at 14:57