-
Notifications
You must be signed in to change notification settings - Fork 44
53 lines (46 loc) · 1.91 KB
/
prettier-check.yml
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
46
47
48
49
50
51
52
53
name: Continuous Integration
# This action works with pull requests and pushes on the main branch
on:
pull_request:
push:
branches: [main]
jobs:
prettier:
name: Prettier Check
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Install Prettier
run: npm install --global prettier@latest
- name: Run Prettier Check
id: prettier-check
run: |
npx prettier --check "**/*.{js,jsx,ts,tsx,css,scss,mdx}" --config ./.prettierrc --ignore-path ./.prettierignore || true
- name: Collect Prettier Output
id: prettier-output
run: |
echo "## Prettier Report" > prettier_report.md
echo "The following files are not formatted:" >> prettier_report.md
npx prettier --list-different "**/*.{js,jsx,ts,tsx,css,scss,mdx}" --config ./.prettierrc --ignore-path ./.prettierignore >> prettier_report.md
echo "" >> prettier_report.md
echo "Detailed formatting differences:" >> prettier_report.md
for file in $(npx prettier --list-different "**/*.{js,jsx,ts,tsx,css,scss,mdx}" --config ./.prettierrc --ignore-path ./.prettierignore); do
echo "Differences in $file:" >> prettier_report.md
git diff --color=always --word-diff "$file" >> prettier_report.md
echo "" >> prettier_report.md
done
continue-on-error: true
- name: Create Pull Request Comment
if: ${{ failure() }}
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const prettierReport = fs.readFileSync('prettier_report.md', 'utf8');
const { context } = require('@actions/github');
github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: prettierReport
});