Skip to content

TEST erb-format GH Action #6

TEST erb-format GH Action

TEST erb-format GH Action #6

Workflow file for this run

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
with:
fetch-depth: 0
# Install Ruby and run bundler
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
# Fetch base branch so we can get diff of changed 'app/views/**/*.erb' files
- name: Fetch base branch
run: git fetch origin ${{ github.base_ref }}
# 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<<EOF" >> $GITHUB_ENV
echo "$FILES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Check formatting of changed .erb files using erb-format.
# If any files require formatting, output their names and exit 1
- name: Execute erb-format against all changed `app/views/**/*.erb` files
run: |
unformatted_files=""
IFS=$'\n'
for file in $FILES; do
formatted=$(bundle exec erb-format "$file")
if ! diff -q <(echo "$formatted") "$file" > /dev/null; then
unformatted_files="${unformatted_files}\n${file}"
fi
done
unset IFS
if [ -n "$unformatted_files" ]; then
printf "The following files require formatting:\n$unformatted_files\n"
echo "Please use erb-format to format them."
exit 1
else
echo "All updated .erb files are correctly formatted."
fi