Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 4

Simpler way to run steps only for a single platform

Solved! Go to Solution.

I have some conditions in my steps like:

 

if: matrix.os == 'ubuntu-latest'

 

It feels clunky having to repeat "ubuntu-latest" in many places when really what I want to say is just "linux". If I was running on multiple versions of Ubuntu or in the future if there were non-Ubuntu linux options, it would be weird to have to maintain all of these.

 

Is there some way we could have a field that represents the platform ("win", "mac", "linux" or similar)?

 

(I just found some people doing "startsWith(matrix.name, 'linux')" which looks slightly better - but still weird, especially as I think it needs to Ubuntu, not Linux).

3 Replies
Solution
Pilot Lvl 1
Message 2 of 4

Re: Simpler way to run steps only for a single platform

if: runner.os == 'Linux'
if: runner.os == 'Windows'
if: runner.os == 'macOS'

 

Copilot Lvl 3
Message 3 of 4

Re: Simpler way to run steps only for a single platform

Looks like `runner.os` is not documented, I'm wondering if this should be the official way to do it.

GitHub Staff
Message 4 of 4

Re: Simpler way to run steps only for a single platform

We haven't finalized the documentation for the `runner` context yet, but you should be able to safely rely on `runner.os`.