Raven
Raven

Reputation: 3516

GitHub Actions: run if

I am trying to setup a custom action for GitHub Actions and currently this is what I have:

name: 'Install Dependencies'

inputs:
    os:
        description: 'The OS to fetch the dependencies for'
        required: True
    

runs:
    using: "composite"
    steps:
        - run: echo I am a test
          shell: bash
          if: startsWith(os, 'Linux')

What I am trying to do is to eventually have a bunch of different shell scripts that are tailored to do the job for a specific OS and therefore in my action, I want to select the appropriate script based on the os parameter that was passed into it.

When I am invoking the action as shown above though, I get Unexpected value 'if'. So my question is: How can I only run execute the run command if a condition is met?

Upvotes: 3

Views: 1962

Answers (2)

Emoun
Emoun

Reputation: 2507

A workaround is to use bash's || and negating the desired condition to ensure the command that follows is only executed if the condition is true (which is negated to false, which runs the command after ||):

- run: ${{ !startsWith(os, 'Linux') }} || echo "I am a test"
  shell: bash

Upvotes: 1

jessehouwing
jessehouwing

Reputation: 114651

The simplest option is probably to use a naming convention for your scripts and run call them with the name of the os:

myscript.$(os).sh

Upvotes: 2

Related Questions