Skip to content

Commit

Permalink
use as a setup action (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Jan 10, 2022
1 parent 64674f3 commit fc8bcb9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 14 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI
on:
pull_request:
push:
jobs:
monkey-help:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
command: help

monkey-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
with:
command: update
args: -vv
workdir: .github/workflows
api_key: ${{ secrets.FUZZYMONKEY_API_KEY }}
github_token: ${{ secrets.github_token }}

setup-monkey:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./
- run: monkey version
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# GitHub Action: Run [@FuzzyMonkeyCo](https://github.com/FuzzyMonkeyCo)'s [`monkey`](https://github.com/FuzzyMonkeyCo/monkey)

[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/FuzzyMonkeyCo/action-monkey?logo=github&sort=semver)](https://github.com/FuzzyMonkeyCo/action-monkey/releases)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/FuzzyMonkeyCo/setup-monkey?logo=github&sort=semver)](https://github.com/FuzzyMonkeyCo/setup-monkey/releases)

This action fetches & runs [`monkey`](https://github.com/FuzzyMonkeyCo/monkey) on GitHub workflows to run `monkey` tests.
This action installs [`monkey`](https://github.com/FuzzyMonkeyCo/monkey) on GitHub workflows to run `monkey` tests.

```yml
name: fuzzymonkey
on: [pull_request]
jobs:
monkey-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: FuzzyMonkeyCo/setup-monkey@v1
- run: monkey lint
```
## Inputs
### `command`
**Required.** `monkey` command to run (e.g. `fuzz` or `fmt`).
Optional. `monkey` command to run (e.g. `fuzz` or `fmt`).
### `args`
Optional. Arguments to the command.
### `workdir`
Expand All @@ -28,14 +40,27 @@ Seed returned by `monkey pastseed`. Non-empty when just ran `monkey fuzz` & foun
```yml
name: fuzzymonkey
on: [pull_request]
jobs:
monkey-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: FuzzyMonkeyCo/setup-monkey@v1
- run: monkey lint
```

### Run a command
```yml
name: fuzzymonkey
on: [pull_request]
jobs:
monkey-fuzz:
name: Run monkey fuzz
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Monkey fuzz
uses: FuzzyMonkeyCo/action-monkey@v1
uses: FuzzyMonkeyCo/setup-monkey@v1
with:
command: fuzz
```
Expand All @@ -54,7 +79,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Monkey fmt
uses: FuzzyMonkeyCo/action-monkey@v1
uses: FuzzyMonkeyCo/setup-monkey@v1
with:
command: fmt
workdir: ./subdirectory/
Expand All @@ -66,7 +91,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Monkey fuzz
uses: FuzzyMonkeyCo/action-monkey@v1
uses: FuzzyMonkeyCo/setup-monkey@v1
with:
command: fuzz
args: --time-budget-overall=30m
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: fuzzy-monkey
name: setup-monkey
description: 🐵 Run @FuzzyMonkeyCo's monkey command
author: fenollp (Pierre Fenoll)

Expand All @@ -9,7 +9,7 @@ branding:
inputs:
command:
description: '`monkey` command to run (ex. `fuzz` or `fmt`)'
required: true
required: false
args:
description: Arguments to the command
required: false
Expand All @@ -22,7 +22,7 @@ inputs:
required: false
github_token:
description: GITHUB_TOKEN, to tame download rate-limiting
required: true
required: false
default: ${{ github.token }}

outputs:
Expand Down
18 changes: 13 additions & 5 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@ set -o pipefail
cd "$GITHUB_WORKSPACE"
cd "$INPUT_WORKDIR"

TMPATH="$(mktemp -d)"
TMPATH="$RUNNER_TEMP/.fuzzymonkey"
mkdir -p "$TMPATH"
echo "$TMPATH" >>"$GITHUB_PATH"
PATH="$TMPATH:$PATH"

echo '::group:: Installing monkey ... https://github.com/FuzzyMonkeyCo/monkey'
curl -sfL https://raw.githubusercontent.com/FuzzyMonkeyCo/monkey/master/.godownloader.sh | BINDIR="$TMPATH" sh
monkey --version
echo '::endgroup::'

if [[ -n "$INPUT_APIKEY" ]]; then
export FUZZYMONKEY_API_KEY="$INPUT_APIKEY"
if [[ -z "$INPUT_COMMAND" ]]; then
# No command given: this is a setup action
exit 0
fi

echo "::group:: $ cd $INPUT_WORKDIR && monkey $INPUT_COMMAND $INPUT_ARGS"
set +e
# shellcheck disable=SC2086
monkey "$INPUT_COMMAND" $INPUT_ARGS; code=$?
if [[ -n "$INPUT_APIKEY" ]]; then
# shellcheck disable=SC2086
FUZZYMONKEY_API_KEY="$INPUT_APIKEY" monkey "$INPUT_COMMAND" $INPUT_ARGS; code=$?
else
# shellcheck disable=SC2086
monkey "$INPUT_COMMAND" $INPUT_ARGS; code=$?
fi
set -e
echo "::set-output name=code::$code"
if [[ $code -eq 6 ]]; then
Expand Down

0 comments on commit fc8bcb9

Please sign in to comment.