-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[no-issue] ci: prettier ci 수정 (#102)
- Loading branch information
Showing
3 changed files
with
54 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
name: Continuous Integration | ||
|
||
# This action works with pull requests and pushes on the main branch | ||
on: | ||
pull_request: | ||
push: | ||
|
@@ -14,18 +13,56 @@ jobs: | |
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run Prettier | ||
id: prettier-run | ||
uses: rutajdash/[email protected] | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
config_path: './.prettierrc' | ||
file_pattern: '**/*' | ||
|
||
# This step only runs if prettier finds errors causing the previous step to fail | ||
# This steps lists the files where errors were found | ||
- name: Prettier Output | ||
if: ${{ failure() }} | ||
shell: bash | ||
node-version: '14' | ||
|
||
- name: Install Prettier | ||
run: npm install 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 | ||
continue-on-error: true | ||
|
||
- name: Collect Prettier Output | ||
if: steps.prettier-check.outcome == 'failure' | ||
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 || true | ||
echo "" >> prettier_report.md | ||
echo "Detailed formatting differences:" >> prettier_report.md | ||
while IFS= read -r file; do | ||
if [ -n "$file" ]; then | ||
echo "Differences in $file:" >> prettier_report.md | ||
npx prettier "$file" --config ./.prettierrc --ignore-path ./.prettierignore > formatted_file.tmp 2>/dev/null || true | ||
diff -u "$file" formatted_file.tmp >> prettier_report.md 2>/dev/null || true | ||
echo "" >> prettier_report.md | ||
fi | ||
done < <(npx prettier --list-different "**/*.{js,jsx,ts,tsx,css,scss,mdx}" --config ./.prettierrc --ignore-path ./.prettierignore) | ||
continue-on-error: true | ||
|
||
- name: Create Pull Request Comment | ||
if: steps.prettier-check.outcome == 'failure' && github.event_name == 'pull_request' | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.ACTION_PAT}} | ||
script: | | ||
const fs = require('fs'); | ||
const prettierReport = fs.readFileSync('prettier_report.md', 'utf8'); | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: prettierReport | ||
}); | ||
- name: Fail if Prettier found issues | ||
if: steps.prettier-check.outcome == 'failure' | ||
run: | | ||
echo "The following files are not formatted:" | ||
echo "${{steps.prettier-run.outputs.prettier_output}}" | ||
echo "Prettier found formatting issues. Please fix them and try again." | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters