Skip to content

Commit b96af4f

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 b96af4f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/erb_format.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
16+
# Install Ruby and run bundler
17+
- uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: '3.0'
20+
bundler-cache: true
21+
22+
# Fetch base branch so we can get diff of changed 'app/views/**/*.erb' files
23+
- name: Fetch base branch
24+
run: git fetch origin ${{ github.base_ref }}
25+
26+
# Gather names of all files within 'app/views/**/*.erb' that have been changed within this PR
27+
# Store those changed files in the `FILES` ENV variable
28+
- name: Get list of changed `app/views/**/*.erb` files
29+
run: |
30+
FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD -- 'app/views/**/*.erb')
31+
32+
echo "FILES<<EOF" >> $GITHUB_ENV
33+
echo "$FILES" >> $GITHUB_ENV
34+
echo "EOF" >> $GITHUB_ENV
35+
36+
# Check formatting of changed .erb files using erb-format.
37+
# If any file is not properly formatted, this step will fail.
38+
- name: Execute erb-format against all changed `app/views/**/*.erb` files
39+
run: |
40+
if [ -n "$FILES" ]; then
41+
echo "$FILES" | xargs bundle exec erb-format --check
42+
else
43+
echo "No changed files within `app/views/**/*.erb`"
44+
fi

0 commit comments

Comments
 (0)