Invalid Workflow File

Hello, i am getting an error with my yml file. but it only says this:

Check failure on line 17 in .github/workflows/chrometest.yml

GitHub Actions
/ .github/workflows/chrometest.yml
Invalid workflow file
You have an error in your yaml syntax on line 17

Line 17 is the runs-on: ${{ matrix.os }} line.

anyone knows the issue here?

Thanks in advance!

name: Chrome

on:
  push:
    branches:
      - master

jobs:
  selenium:
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, macos-latest]
        browser: [chrome]
        python-version: ["3.8", "3.9", "3.10"]

  runs-on: ${{ matrix.os }}

  steps:
  - uses: actions/checkout@v3

  - name: Set up Python ${{ matrix.python-version }}
    uses: actions/setup-python@v3
    with:
      python-version: ${{ matrix.python-version }}

  - name: Install dependencies
    run: |
      python -m pip install --upgrade pip
      if [ -f requirements.txt ]; then pip install -r requirements.txt
      
  - name: execute py script 
    run: |
      python test.py

In YAML the indentation level is part of the syntax (see the “Nested Mappings” section in the tutorial). The problem is that your runs-on is at the same level of indentation as selenium, so it’s not part of the job, but a new item within jobs (the indentation level above). And ${{ matrix.os }} is not a valid job definition, nor is the selenium job valid without a runs-on or steps. :wink:

To define runs-on for the selenium job, the runs-on must be indented to the same level as other items within the job, like strategy.

The steps item has the same issue, by the way.

1 Like

Thanks for your input!
it looks like the matrix syntax isnt the problem. the indentations are the problem and i could solve it.

But now i have to change the runs for mac and windows so that it uses two different installation methods for python.
because in the windows runner it will execute a powershell file, in the macos runner it uses a .sh file which does not know the powershell syntax.

can you help me solve this too? its my first yml file…
Thanks!

You can add an if condition on a step. Then the step runs only if the condition is met. If you do something like this:

- name: install dependencies (macos)
  run: your install command here
  if: matrix.os == 'macos-latest'

The step will only run if running on the selected runner, in the example the macos-latest one. So you can have one step that runs only on MacOS, and create a similar one that only runs on Windows.

Just as a side note, the indentation was a YAML thing (how to structure mappings, lists, etc.), the rest is specific to GitHub Actions workflows. A lot of other tools (including competing ones) use YAML for other data sets with other structures, but the same format. :wink: