diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cbacd16 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index 03b23df..35cc978 100644 --- a/README.md +++ b/README.md @@ -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` @@ -28,6 +40,19 @@ 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 @@ -35,7 +60,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Monkey fuzz - uses: FuzzyMonkeyCo/action-monkey@v1 + uses: FuzzyMonkeyCo/setup-monkey@v1 with: command: fuzz ``` @@ -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/ @@ -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 diff --git a/action.yml b/action.yml index a072e95..8794add 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: fuzzy-monkey +name: setup-monkey description: 🐵 Run @FuzzyMonkeyCo's monkey command author: fenollp (Pierre Fenoll) @@ -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 @@ -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: diff --git a/script.sh b/script.sh index 258bc94..bed4195 100755 --- a/script.sh +++ b/script.sh @@ -6,7 +6,9 @@ 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' @@ -14,14 +16,20 @@ curl -sfL https://raw.githubusercontent.com/FuzzyMonkeyCo/monkey/master/.godownl 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