-
Notifications
You must be signed in to change notification settings - Fork 13
/
action.yml
85 lines (75 loc) · 2.76 KB
/
action.yml
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: 'A GitHub Action that lints and auto-fixes your Ruby code with Standard Ruby'
author: 'Justin Searls <searls@gmail.com>'
inputs:
ruby-version:
description: 'The Ruby version specifier to pass to ruby/setup-ruby'
required: false
default: 'ruby' # Defaults to the latest stable CRuby version
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 '.'"
default: '.'
runs:
using: composite
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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"
RUBY_VERSION=$(cat .ruby-version)
echo "ruby-version=$RUBY_VERSION" >> $GITHUB_ENV
else
echo "No .ruby-version file found, using default"
fi
- name: Set up Ruby
uses: ruby/setup-ruby@v1
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
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
branding:
icon: 'code'
color: 'gray-dark'