From 973952d549cc163e971931da7fe16e73e746f688 Mon Sep 17 00:00:00 2001 From: Jinhyung Lee Date: Mon, 5 Aug 2024 16:26:51 +0900 Subject: [PATCH] =?UTF-8?q?[no-issue]=20ci:=20prettier=20ci=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#102)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/prettier-check.yml | 65 +++++++++++++++---- package.json | 4 +- .../api-reference/components/image-legacy.mdx | 2 +- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/.github/workflows/prettier-check.yml b/.github/workflows/prettier-check.yml index 2105694..d5ca5fb 100644 --- a/.github/workflows/prettier-check.yml +++ b/.github/workflows/prettier-check.yml @@ -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/prettier-cli-action@v1.0.0 + - 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 diff --git a/package.json b/package.json index 5175dbf..34663d8 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "build:local": "pnpm run generate-sitemap && next build", "start": "next start", "lint": "next lint --cache", - "format": "prettier --cache --check .", - "format:fix": "prettier --cache --write --log-level warn . --ignore-path .prettierignore", + "format": "prettier --cache --check \"**/*.{js,jsx,ts,tsx,css,scss,mdx}\"", + "format:fix": "prettier --cache --write --ignore-path .prettierignore \"**/*.{js,jsx,ts,tsx,css,scss,mdx}\"", "prepare": "husky", "lint-staged": "pnpm format:fix && pnpm lint", "generate-sitemap": "node scripts/generate-sitemap.mjs" diff --git a/pages/docs/pages/api-reference/components/image-legacy.mdx b/pages/docs/pages/api-reference/components/image-legacy.mdx index 8337612..36b0854 100644 --- a/pages/docs/pages/api-reference/components/image-legacy.mdx +++ b/pages/docs/pages/api-reference/components/image-legacy.mdx @@ -5,7 +5,7 @@ description: Backwards compatible Image Optimization with the Legacy Image compo {/* TODO: 번역이 필요합니다. */} -# `` (Legacy) +`` (Legacy)
Examples