-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathaction.yml
More file actions
85 lines (76 loc) · 3.2 KB
/
action.yml
File metadata and controls
85 lines (76 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Standard Ruby
description: Lint and auto-fix your Ruby code with Standard Ruby.
author: Justin Searls <searls@gmail.com>
branding: { icon: code, color: yellow }
inputs:
ruby-version:
description: >
The ruby version specifier to pass to ruby/setup-ruby. If omitted,
respects files (in order) — .ruby-version, .tool-versions, mise.toml.
Finally defaults to 'ruby' (latest stable CRuby).
https://github.com/ruby/setup-ruby?tab=readme-ov-file#supported-version-syntax
required: false
default: ''
autofix:
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: ''
deprecationMessage: rename to 'working-directory'.
working-directory:
description: The working directory from which to run this action's commands.
default: '.'
runs:
using: composite
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- if: ${{ inputs.ruby-version == '' }}
shell: bash
working-directory: ${{ inputs.workdir || inputs.working-directory }}
run: |
if [ -f .ruby-version ] || grep -sq ruby -- .tool-versions mise.toml;
then echo "Version files found; allow setup-ruby to resolve from file."
else echo "No version files found; using 'ruby' (latest stable CRuby)."
echo "ruby-version=ruby" >> "$GITHUB_ENV"
fi
- uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd # v1.288.0
with:
ruby-version: ${{ inputs.ruby-version || env.ruby-version }}
bundler-cache: true
working-directory: ${{ inputs.workdir || inputs.working-directory }}
- name: Run Standard Ruby; optionally autofix
id: standardrb
shell: bash
working-directory: ${{ inputs.workdir || inputs.working-directory }}
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 || inputs.working-directory }}
run: |
if [ -n "$(git diff --name-only --diff-filter=M)" ]; then
echo "standardrb_autofixes_found=true" >> $GITHUB_ENV
else
echo "standardrb_autofixes_found=false" >> $GITHUB_ENV
fi
- name: Commit autofixes
shell: bash
if: env.standardrb_autofixes_found == 'true'
run: |
echo "::group::Committing Standard Fixes"
git config --global user.name 'standard-ruby-action[bot]'
git config --global user.email 'standard-ruby-action[bot]@users.noreply.github.com'
# Add any files that were changed by Standard Ruby
git diff --name-only --diff-filter=M | xargs git add
git commit -m "Apply Standard Ruby autofixes" || echo "No changes to commit"
git push
echo "::endgroup::"
- name: Fail the build if Standard Ruby failed
shell: bash
if: ${{ steps.standardrb.outcome == 'failure' }}
run: |
echo "::error::Standard Ruby found issues in your code."
exit 1