Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Jul 23, 2020
0 parents commit b7991ad
Show file tree
Hide file tree
Showing 9 changed files with 1,963 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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@master
with:
macos: echo "Hi from macos"
linux: |
echo "Hi from linux"
echo "Hi from linux second line"
windows: echo "Hi from windows"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/**
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Nick Maliwacki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# os-specific-run

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


## 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

## Example

```yaml
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@master
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

```pwsh
npm i -g @zeit/ncc
npm install
```

### Update project

```pwsh
ncc build index.js
```
30 changes: 30 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'OS specific run'
description: 'Run a command based on the OS'
inputs:
linux: # id of input
description: 'linux commandline'
required: false
default: 'echo "No command specified for linux"'
macos: # id of input
description: 'macos commandline'
required: false
default: 'echo "No command specified for macos"'
windows: # id of input
description: 'windows commandline'
required: false
default: 'echo "No command specified for windows"'
linuxShell: # id of input
description: 'linux commandline shell'
required: false
default: 'bash'
macosShell: # id of input
description: 'macos commandline shell'
required: false
default: 'bash'
windowsShell: # id of input
description: 'windows commandline shell'
required: false
default: 'pwsh'
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit b7991ad

Please sign in to comment.