Skip to content

Commit

Permalink
Allow specifying a working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
wjessop committed Sep 23, 2024
1 parent 6a9e59a commit 2a912df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ permissions:

- `ruby-version` - If your project has a `.ruby-version` file, this Action will use that version of Ruby. If not, this will be forwarded to the [ruby/setup-ruby](https://github.com/ruby/setup-ruby) action, so it takes the same values.
- `autofix` - If set to `false`, the action will not attempt to auto-fix any errors. Defaults to `true`.
- `workdir` - If set the action will descend to this directory before running `bundle exec standardrb …`. Defaults to `.`.

Example with options set:

Expand All @@ -62,6 +63,7 @@ Example with options set:
with:
ruby-version: '3.3'
autofix: false
workdir: my/app/subdirectory
```

## Screenshots
Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
description: 'Whether autofixes should be committed back to the branch'
required: false
default: 'true'
workdir:
description: "The working directory from which to run this action's commands. Default '.'"
default: '.'

runs:
using: composite
Expand All @@ -22,6 +25,7 @@ runs:
- name: Check for .ruby-version file
id: use_ruby_version_or_default
shell: bash
working-directory: ${{ inputs.workdir }}
run: |
if [ -f .ruby-version ]; then
echo "Using Ruby version from .ruby-version file"
Expand All @@ -36,16 +40,19 @@ runs:
with:
ruby-version: ${{ env.ruby-version || inputs.ruby-version }}
bundler-cache: true
working-directory: ${{ inputs.workdir }}

- name: Run Standard Ruby with autofix
id: standardrb
shell: bash
working-directory: ${{ inputs.workdir }}
run: bundle exec standardrb ${{ inputs.autofix == 'true' && '--fix' || '' }} --format github --format "Standard::Formatter"
continue-on-error: true

- name: Check for modified files
id: check_changes
shell: bash
working-directory: ${{ inputs.workdir }}
run: |
if [ -n "$(git diff --name-only --diff-filter=M)" ]; then
echo "standardrb_autofixes_found=true" >> $GITHUB_ENV
Expand Down

0 comments on commit 2a912df

Please sign in to comment.