diff --git a/.github/workflows/erb_format.yml b/.github/workflows/erb_format.yml new file mode 100644 index 0000000000..dd3c10c06f --- /dev/null +++ b/.github/workflows/erb_format.yml @@ -0,0 +1,40 @@ +name: ERB Format Check + +on: + pull_request: + paths: + - 'app/views/**/*.erb' + +jobs: + erb_format: + runs-on: ubuntu-24.04 + + steps: + # Checkout the repo + - uses: actions/checkout@v2 + + # Install Ruby and run bundler + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + + # Gather names of all files within 'app/views/**/*.erb' that have been changed within this PR + # Store those changed files in the `FILES` ENV variable + - name: Get list of changed `app/views/**/*.erb` files + run: | + FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'app/views/**/*.erb') + + echo "FILES<> $GITHUB_ENV + echo "$FILES" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + # Check formatting of changed .erb files using erb-format. + # If any file is not properly formatted, this step will fail. + - name: Execute erb-format against all changed `app/views/**/*.erb` files + run: | + if [ -n "$FILES" ]; then + echo "$FILES" | xargs bundle exec erb-format --check + else + echo "No changed files within `app/views/**/*.erb`" + fi diff --git a/Gemfile b/Gemfile index e66e5e7288..2a115370f4 100644 --- a/Gemfile +++ b/Gemfile @@ -286,6 +286,10 @@ group :ci, :development do # (http://github.com/stewartmckee/bundle-audit) gem 'bundle-audit' + # ERB formatting tool + # https://github.com/nebulab/erb-formatter + gem 'erb-formatter', require: false + # RuboCop is a Ruby code style checking and code formatting tool. It aims to enforce # the community-driven Ruby Style Guide. gem 'rubocop' diff --git a/Gemfile.lock b/Gemfile.lock index 9c399339bb..7f27c9764c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -191,6 +191,8 @@ GEM dragonfly (~> 1.0) fog-aws drb (2.2.1) + erb-formatter (0.7.3) + syntax_tree (~> 6.0) erubi (1.13.1) excon (1.2.5) logger @@ -395,6 +397,7 @@ GEM pg (1.5.9) pp (0.6.2) prettyprint + prettier_print (1.2.1) prettyprint (0.2.0) prime (0.1.3) forwardable @@ -566,6 +569,8 @@ GEM activesupport (>= 6.1) sprockets (>= 3.0.0) stringio (3.1.5) + syntax_tree (6.2.0) + prettier_print (>= 1.2.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) text (1.3.1) @@ -639,6 +644,7 @@ DEPENDENCIES dotenv-rails dragonfly dragonfly-s3_data_store + erb-formatter factory_bot_rails faker flag_shih_tzu