forked from openlawteam/scalafmt-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-scalafmt.sh
executable file
·45 lines (39 loc) · 965 Bytes
/
run-scalafmt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
output=$(mktemp)
warnings=$(mktemp)
errors=$(mktemp)
enforce_scala_format_version() {
if [ -e .scalafmt.conf ]; then
perl -pi -e 'next unless s/^\s*(version)=.*/$1=$ENV{scalafmt_version}/' .scalafmt.conf
fi
}
enforce_scala_format_version
scalafmt --non-interactive $args > "$output" 2> "$warnings"
result=$?
cat "$output"
cat "$warnings" >&2
[ $result -eq 0 ] && exit
report() {
file="$1"
summary="$2"
[ -s "$file" ] || return
echo "<details><summary>$summary</summary>"
echo
echo '```'
perl -pe 's/$ENV{GITHUB_WORKSPACE}//g' "$file"
echo '```'
echo '</details>'
echo
}
source="$output" errors="$errors" extract-errors.pl
source="$warnings" errors="$errors" extract-errors.pl
(
echo "# scalafmt failed ($result)"
if [ -s "$errors" ]; then
echo '# Errors'
cat "$errors"
fi
report "$warnings" "Warnings"
report "$output" "Status"
) >> "$GITHUB_STEP_SUMMARY"
exit $result