Skip to content

OS specific run

Actions
Run a command based on the OS
v1.0.4
Latest
Star (6)

test

os-specific-run

A github action for running a separate command based on the os

    - uses: knicknic/[email protected]
      with:
        macos: echo "Hi from macos"
        linux: |
          echo "Hi from linux"
          echo "Hi from linux second line"
        windows: echo "Hi from windows"

Keeping actions up-to-date

Enable dependabot to get notifications for updated actions by creating .github/dependabot.yml in your repository with the actions configurations

Params

(optional) Command you wish to run

os command value
macos echo "No command specified for macos"
linux echo "No command specified for linux"
windows echo "No command specified for windows"

(optional) Shell you wish to use

os command value
macosShell bash
linuxShell bash
windowsShell pwsh

See https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell for more details

Full Example

name: test

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: ["ubuntu-latest", "windows-latest", "macos-latest"]
    steps:
    - uses: actions/checkout@v2

    - uses: knicknic/os-specific-run@v1
      with:
        macos: echo "Hi from macos"
        linux: |
          echo "Hi from linux"
          echo "Hi from linux second line"
        windows: echo "Hi from windows"

Alternatives

You can do what this project accomplishes with simple if statements in github actions.

The problem is you have to figure them out, and they end up creating multiple steps one per each OS. I think a single step (rather than multiple steps in each OS that are not run) looks cleaner and is more obvious what failed. More details on if statements - https://github.community/t/what-is-the-correct-if-condition-syntax-for-checking-matrix-os-version/16221/4

Developer instructions

Setup Environment

npm i -g @vercel/ncc@0.26.2 # can be a newer version
npm install

Update project

ncc build index.js

OS specific run is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Run a command based on the OS
v1.0.4
Latest

OS specific run is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.