diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 030820e..aec9708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,9 +6,9 @@ jobs: runs-on: ubuntu-latest defaults: run: - working-directory: test/using_gemfile + working-directory: test/using_bundler env: - BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_gemfile/Gemfile + BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_bundler/Gemfile steps: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 @@ -19,7 +19,8 @@ jobs: uses: ./ with: github_token: ${{ secrets.github_token }} - brakeman_version: "gemfile" brakeman_flags: "--force" + skip_install: 'true' + use_bundler: 'true' - run: | test "$(bundle exec brakeman --version)" == "brakeman 5.1.2" diff --git a/README.md b/README.md index 5c27bac..d860793 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,14 @@ Optional. Additional reviewdog flags. Optional. The directory from which to look for and run brakeman. Default `.`. +### `skip_install` + +Optional. Do not install Brakeman. Default: `false`. + +### `use_bundler` + +Optional. Run Brakeman with bundle exec. Default: `false`. + ## Example usage ```yml diff --git a/action.yml b/action.yml index 79fa7c6..a310b11 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,12 @@ inputs: workdir: description: "The directory from which to look for and run brakeman. Default '.'" default: '.' + skip_install: + description: "Do not install Brakeman. Default: `false`" + default: 'false' + use_bundler: + description: "Run Brakeman with bundle exec. Default: `false`" + default: 'false' runs: using: 'composite' steps: @@ -54,6 +60,8 @@ runs: INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} INPUT_WORKDIR: ${{ inputs.workdir }} + INPUT_SKIP_INSTALL: ${{ inputs.skip_install }} + INPUT_USE_BUNDLER: ${{ inputs.use_bundler }} branding: icon: 'check-circle' color: 'red' diff --git a/script.sh b/script.sh index 48d5185..ca08002 100755 --- a/script.sh +++ b/script.sh @@ -16,37 +16,45 @@ echo '::group::🐶 Installing reviewdog ... https://github.com/reviewdog/review curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b "${TEMP_PATH}" "${REVIEWDOG_VERSION}" 2>&1 echo '::endgroup::' -echo '::group:: Installing brakeman with extensions ... https://github.com/presidentbeef/brakeman' -# if 'gemfile' brakeman version selected -if [ "$INPUT_BRAKEMAN_VERSION" = "gemfile" ]; then - # if Gemfile.lock is here - if [ -f 'Gemfile.lock' ]; then - # grep for brakeman version - BRAKEMAN_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}brakeman\s\(\K.*(?=\))/' Gemfile.lock) - - # if brakeman version found, then pass it to the gem install - # left it empty otherwise, so no version will be passed - if [ -n "$BRAKEMAN_GEMFILE_VERSION" ]; then - BRAKEMAN_VERSION=$BRAKEMAN_GEMFILE_VERSION +if [ "${INPUT_SKIP_INSTALL}" = "false" ]; then + echo '::group:: Installing brakeman with extensions ... https://github.com/presidentbeef/brakeman' + # if 'gemfile' brakeman version selected + if [ "$INPUT_BRAKEMAN_VERSION" = "gemfile" ]; then + # if Gemfile.lock is here + if [ -f 'Gemfile.lock' ]; then + # grep for brakeman version + BRAKEMAN_GEMFILE_VERSION=$(ruby -ne 'print $& if /^\s{4}brakeman\s\(\K.*(?=\))/' Gemfile.lock) + + # if brakeman version found, then pass it to the gem install + # left it empty otherwise, so no version will be passed + if [ -n "$BRAKEMAN_GEMFILE_VERSION" ]; then + BRAKEMAN_VERSION=$BRAKEMAN_GEMFILE_VERSION + else + printf "Cannot get the brakeman's version from Gemfile.lock. The latest version will be installed." + fi else - printf "Cannot get the brakeman's version from Gemfile.lock. The latest version will be installed." + printf 'Gemfile.lock not found. The latest version will be installed.' fi else - printf 'Gemfile.lock not found. The latest version will be installed.' + # set desired brakeman version + BRAKEMAN_VERSION=$INPUT_BRAKEMAN_VERSION fi - else - # set desired brakeman version - BRAKEMAN_VERSION=$INPUT_BRAKEMAN_VERSION + + gem install -N brakeman --version "${BRAKEMAN_VERSION}" + echo '::endgroup::' fi -gem install -N brakeman --version "${BRAKEMAN_VERSION}" -echo '::endgroup::' +if [ "${INPUT_USE_BUNDLER}" = "false" ]; then + BUNDLE_EXEC="" +else + BUNDLE_EXEC="bundle exec " +fi echo '::group:: Running brakeman with reviewdog 🐶 ...' BRAKEMAN_REPORT_FILE="$TEMP_PATH"/brakeman_report # shellcheck disable=SC2086 -brakeman --quiet --format tabs --no-exit-on-warn --no-exit-on-error ${INPUT_BRAKEMAN_FLAGS} --output "$BRAKEMAN_REPORT_FILE" +${BUNDLE_EXEC}brakeman --quiet --format tabs --no-exit-on-warn --no-exit-on-error ${INPUT_BRAKEMAN_FLAGS} --output "$BRAKEMAN_REPORT_FILE" reviewdog < "$BRAKEMAN_REPORT_FILE" \ -f=brakeman \ -name="${INPUT_TOOL_NAME}" \ diff --git a/test/using_gemfile/Gemfile b/test/using_bundler/Gemfile similarity index 100% rename from test/using_gemfile/Gemfile rename to test/using_bundler/Gemfile diff --git a/test/using_gemfile/Gemfile.lock b/test/using_bundler/Gemfile.lock similarity index 100% rename from test/using_gemfile/Gemfile.lock rename to test/using_bundler/Gemfile.lock