Skip to content
list

GitHub Action

OS specific runner

v2.1.1 Latest version

OS specific runner

list

OS specific runner

Run a command based on the OS

Installation

Copy and paste the following snippet into your .yml file.

              

- name: OS specific runner

uses: carlkidcrypto/[email protected]

Learn more about this action in carlkidcrypto/os-specific-runner

Choose a version

os-specific-runner

All credit for the original work goes to (KnicKnic). This is a detached-fork of https://github.com/KnicKnic/os-specific-run. This version (2.0.0 and beyond) will attempt to stay upto date on the lastest version of NPM and other dependecies.

Status Badge(s)

tests CodeQL regenerate total download count latest release download count

How to Support This Project

Buy Me A Coffee

About

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

    - uses: carlkidcrypto/[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@v4

    - uses: carlkidcrypto/[email protected]
      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 install -g npm@10.8.3
npm i -g @vercel/ncc@0.38.2
npm install

Update lock file

npm update

Update project

ncc build index.js -m

Run tests