Skip to content

Commit

Permalink
Allow use bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
massongit committed Jan 16, 2024
1 parent d37d0b1 commit 917b287
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
48 changes: 28 additions & 20 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 917b287

Please sign in to comment.