Skip to content

Commit 9540ba0

Browse files
committed
output the changed files & diff to the github env
and then use those env variables in the pr comment
1 parent bff590c commit 9540ba0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

.github/workflows/prettier.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
echo "Fixing the following files:"
3838
echo "$CHANGED_FILES"
3939
echo "$CHANGED_FILES" | xargs npx prettier --write
40+
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
4041
else
4142
echo "No files to format"
4243
fi
@@ -51,17 +52,19 @@ jobs:
5152
git add .
5253
git commit -m "Apply Prettier formatting"
5354
git push
55+
DIFF_OUTPUT=$(git diff HEAD~1 HEAD)
56+
echo "DIFF_OUTPUT<<EOF" >> $GITHUB_ENV
57+
echo "$DIFF_OUTPUT" >> $GITHUB_ENV
58+
echo "EOF" >> $GITHUB_ENV
5459
else
5560
echo "No changes to commit"
5661
fi
5762
- name: Set Prettier diff output
5863
env:
5964
GH_TOKEN: ${{ github.token }}
6065
run: |
61-
DIFF_OUTPUT=$(git diff HEAD~1 HEAD)
62-
CHANGED_FILES=$(gh pr diff ${{ github.event.pull_request.number }} --name-only | grep -E '\.js$|\.jsx$|\.ts$|\.tsx$' || echo "")
63-
if [ -n "$DIFF_OUTPUT" ]; then
64-
gh pr comment ${{ github.event.pull_request.number }} --body "$(echo -e "Hi from your friendly robot! 🤖\n\nI've applied Prettier formatting to the following files:\n\n$CHANGED_FILES\n\nThe full diff is below:\n\n<details>\n<summary>Click to expand</summary>\n\n\`\`\`diff\n$DIFF_OUTPUT\n\`\`\`\n</details>")"
66+
if [ -n "${{ env.DIFF_OUTPUT }}" ]; then
67+
gh pr comment ${{ github.event.pull_request.number }} --body "$(echo -e "Hi from your friendly robot! 🤖\n\nI've applied Prettier formatting to the following files:\n\n${{ env.CHANGED_FILES }}\n\nThe full diff is below:\n\n<details>\n<summary>Click to expand</summary>\n\n\`\`\`diff\n$DIFF_OUTPUT\n\`\`\`\n</details>")"
6568
else
6669
echo "No Prettier changes"
6770
fi

0 commit comments

Comments
 (0)