Skip to content

Commit 9a3332b

Browse files
committed
changes into a file
1 parent da8aa71 commit 9a3332b

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

.github/workflows/format_check.yml

+28-11
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,43 @@ jobs:
2626
- name: Fetch latest changes
2727
run: git fetch origin
2828

29-
# Step 4: Get a list of changed Java files in the PR
3029
- name: Get changed Java files
3130
id: changed_files
3231
run: |
3332
echo "::group::Changed Java Files"
34-
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} | grep '\.java$' || true)
33+
CHANGED_FILES=$(git diff --name-only origin/master | grep '\.java$' || true)
3534
echo "$CHANGED_FILES"
3635
echo "::endgroup::"
37-
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
38-
echo $CHANGED_FILES
36+
# Write the multiline content to a file
37+
echo "$CHANGED_FILES" > changed_files.txt
3938
40-
# Step 5: Check formatting of the changed files
39+
# Step 4: Get a list of changed Java files in the PR
4140
- name: Check Java file format
4241
run: |
43-
if [ -z "${{ env.CHANGED_FILES }}" ]; then
42+
# Check if the changed_files.txt exists
43+
if [ ! -f changed_files.txt ]; then
44+
echo "No changed files found."
45+
exit 0
46+
fi
47+
48+
# Read the multiline content from the file
49+
CHANGED_FILES=$(cat changed_files.txt)
50+
51+
# Ensure there are changed files
52+
if [ -z "$CHANGED_FILES" ]; then
4453
echo "No Java files changed."
4554
else
46-
for FILE in ${{ env.CHANGED_FILES }}; do
47-
FILE_NAME=$(basename "$FILE")
48-
echo "Checking for $FILE_NAME"
49-
mvn formatter:validate -f formatter-pom.xml "-Dformatter.includes=**/$FILE_NAME"
50-
done
55+
echo "Processing the following changed Java files:"
56+
57+
# Iterate over the CHANGED_FILES variable, assuming files are separated by newlines
58+
while IFS= read -r FILE; do
59+
# Skip empty lines if any
60+
if [ -n "$FILE" ]; then
61+
FILE_NAME=$(basename "$FILE")
62+
echo "Checking for $FILE_NAME"
63+
64+
# Run your formatter validation for each file
65+
mvn formatter:validate -f formatter-pom.xml "-Dformatter.includes=**/$FILE_NAME"
66+
fi
67+
done <<< "$CHANGED_FILES"
5168
fi

0 commit comments

Comments
 (0)