-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
executable file
·38 lines (29 loc) · 1.04 KB
/
entrypoint.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
#!/bin/bash
# Wrapper for the formatter that passes action args and processes the output.
# Required args:
# - Path to base directory.
# - File include glob pattern.
# - Whether to fail on file changes.
if [[ $# -ne 3 ]]; then
echo 'Exactly three parameters (base dir path, input file pattern, fail on changes) required.'
exit 1
fi
base_path=$1
include_pattern=$2
fail_on_changes=$3
# Prepare the workspace for safe usage:
git config --global --add safe.directory /github/workspace
cd "/github/workspace/$base_path" || exit 2
changed_files_before=$(git status --short)
/opt/idea/bin/format.sh -m $include_pattern -r .
changed_files_after=$(git status --short)
changed_files=$(diff <(echo "$changed_files_before") <(echo "$changed_files_after"))
changed_files_count=$(($(echo "$changed_files" | wc --lines) - 1))
echo "$changed_files"
echo "files-changed=$changed_files_count" >> $GITHUB_OUTPUT
if [[ "$fail_on_changes" == 'true' ]]; then
if [[ $changed_files_count -gt 0 ]]; then
echo 'Failing, because these files changed:'
exit 1
fi
fi