Skip to content

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

License

Notifications You must be signed in to change notification settings

KnicKnic/os-specific-run

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test

os-specific-run

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

    - uses: knicknic/os-specific-run@v1.0.3
      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

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •