Skip to content

Commit 7b3a35d

Browse files
committed
Create erb_format.yml
This new "ERB Format Check" workflow works as follows: - Executes when a PR is made and gathers any changed `app/views/**/*.erb` files. - Executes `erb-format` against all of the gathered files: - If no files were changed, or if there are no formatting errors, then the GH Action passes. - Else there are formatting errors and the GH Action will fail.
1 parent 084345a commit 7b3a35d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

.github/workflows/erb_format.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: ERB Format Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'app/views/**/*.erb'
7+
8+
jobs:
9+
erb_format:
10+
runs-on: ubuntu-24.04
11+
12+
steps:
13+
# Checkout the repo
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
# Install Ruby and run bundler
19+
- uses: ruby/setup-ruby@v1
20+
with:
21+
ruby-version: '3.0'
22+
bundler-cache: true
23+
24+
# Fetch base branch so we can get diff of changed 'app/views/**/*.erb' files
25+
- name: Fetch base branch
26+
run: git fetch origin ${{ github.base_ref }}
27+
28+
# Gather names of all files within 'app/views/**/*.erb' that have been changed within this PR
29+
# Store those changed files in the `FILES` ENV variable
30+
- name: Get list of changed `app/views/**/*.erb` files
31+
run: |
32+
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'app/views/**/*.erb')
33+
34+
echo "FILES<<EOF" >> $GITHUB_ENV
35+
echo "$FILES" >> $GITHUB_ENV
36+
echo "EOF" >> $GITHUB_ENV
37+
38+
# Check formatting of changed .erb files using erb-format.
39+
# If any files require formatting, output their names and exit 1
40+
- name: Execute erb-format against all changed `app/views/**/*.erb` files
41+
run: |
42+
unformatted_files=""
43+
44+
IFS=$'\n'
45+
for file in $FILES; do
46+
formatted=$(bundle exec erb-format "$file")
47+
if ! diff -q <(echo "$formatted") "$file" > /dev/null; then
48+
unformatted_files="${unformatted_files}\n${file}"
49+
fi
50+
done
51+
unset IFS
52+
53+
if [ -n "$unformatted_files" ]; then
54+
printf "The following files require formatting:\n$unformatted_files\n"
55+
echo "Please use erb-format to format them."
56+
exit 1
57+
else
58+
echo "All updated .erb files are correctly formatted."
59+
fi

0 commit comments

Comments
 (0)