Skip to content

Commit a281652

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 a281652

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/erb_format.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 file is not properly formatted, this step will fail.
40+
- name: Execute erb-format against all changed `app/views/**/*.erb` files
41+
run: |
42+
if [ -n "$FILES" ]; then
43+
echo "$FILES" | xargs bundle exec erb-format --write
44+
else
45+
echo "No changed files within `app/views/**/*.erb`"
46+
fi

0 commit comments

Comments
 (0)