Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Pilot Lvl 1
Message 1 of 8

What is the correct if condition syntax for checking matrix.os version?

Solved! Go to Solution.

Hi,

 

I previously used travis with a build matrix and could check in if condtions for the os-version/type, however in GithubActions I couldn't figure out what the correct syntax is:

I tested both with and without expression braces:

 - if:  matrix.os  == 'ubuntu-latest'
      run: |
        ionic cordova platform add android
        ionic cordova build android
 
and something like:
    - if: ${{ matrix.os == 'macOS-10.14'}}
run: | ionic cordova platform add ios ionic cordova build ios
Both give me errors:
- Your workflow file was invalid: .github/workflows/main.yml (Line: 33, Col: 11): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.os == 'macOS-10.14'
 
7 Replies
Highlighted
Solution
Pilot Lvl 1
Message 2 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

I figured it out and now it works:

 

- if: matrix.os == 'macOS-10.14'
      run: |
        ionic cordova platform add ios
        ionic cordova build ios

 - if: matrix.os == 'ubuntu-latest'
      run: |
        ionic cordova platform add android
        ionic cordova build android
Ground Controller Lvl 2
Message 3 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

Does't work.  I get "You have an error in your yaml syntax on line 30" with this:

      - name: Install Depencies unless Windows

        - if: matrix.os != 'windows-latest'

          run: cpanm -iqn BSD::Resource

 

Of course, it's not helpful that Github doesn't tell you what the syntax error is, or the place in the line that the error occured.

Pilot Lvl 1
Message 4 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

- name: run on mac
      if: startsWith(matrix.os, 'macOS')
      run: |
        ionic cordova platform add ios
        ionic cordova build ios
        mkdir -pv output
    - name: run on linux
      if: startsWith(matrix.os,'ubuntu')
      run: |
        npm run test-headless
        ionic cordova platform add android
        ionic cordova build android
        mkdir -pv output     
        readlink -f output

This works fine for me. Maybe your indentation is wrong?

Ground Controller Lvl 2
Message 5 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

I checked and double checked the indentation.  Looks right to me.  And there are no tabs either.

Ground Controller Lvl 2
Message 6 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

Looking more, the indentation isn't clear to me.  In your answer the 'run' is under the 'if'; whereas in the 'solved' response it's indented by four spaces.  I indented by two.

Ground Controller Lvl 2
Message 7 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

That was it.  It wants no indend, the "solved" solution is wrong.

Pilot Lvl 1
Message 8 of 8

Re: What is the correct if condition syntax for checking matrix.os version?

I think it could be a copy paste problem with the forum here which killed the right indentations