From acf051c99bb140a9e5152ec32d3e56bb0b2fdeac Mon Sep 17 00:00:00 2001 From: Sunghyun627 Date: Tue, 20 Aug 2024 13:44:48 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20lighthouse=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EB=A5=BC=20comment=EC=97=90=20=EB=B0=98=EC=98=81=ED=95=98?= =?UTF-8?q?=EB=8A=94=20step=20=EC=B6=94=EA=B0=80=20(SP-668)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/lighthouse.yml | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 9f56dce0..25e3c26e 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -69,12 +69,12 @@ jobs: const desktopLightHouseResults = JSON.parse(fs.readFileSync('lhci_reports/desktop/manifest.json')); const mobileLightHouseResults = JSON.parse(fs.readFileSync('lhci_reports/mobile/manifest.json')); - let comments = `💡 LightHouse Reports\n\n`; - comments += `'🟢' 90 ~ 100, '🟠' 50 ~ 89 '🔴' 0 ~ 49 \n\n`; + let comments = `### 💡 LightHouse Reports\n\n`; + comments += `🟢 90 ~ 100, 🟠 50 ~ 89 🔴 0 ~ 49 \n\n`; const getFormattingScore = (res) => Math.round(res * 100); - const getScoreColor = (score) => (score >= LH_MIN_SCORES.GREEN ? '🟢' : score >= LH_MIN_SCORES.ORANGE ? '🟠' : '🔴'); + const getScoreColor = (score) => (score >= LH_MIN_SCORES.GREEN ? '🟢' : score >= LH_MIN_SCORES.ORANGE ? 🟠 : 🔴); const getMonitoringPageName = (url) => { const route = url.replace(DEV_ORIGIN_URL, ''); @@ -117,7 +117,7 @@ jobs: }; const getLightHouseFormattingResult = (results, type) => { - let comment = type === 'mobile' ? `📱 Mobile` : `🖥 Desktop\n`; + let comment = type === 'mobile' ? `####📱 Mobile` : `####🖥 Desktop\n`; results.forEach((result) => (comment += getFormattingResultByPage(result))); return comment + '\n'; @@ -137,21 +137,30 @@ jobs: const { Octokit } = require('@octokit/rest'); const octokit = new Octokit({ auth: `${{ secrets.GITHUB_TOKEN }}` }); - const { context } = require('@actions/github'); const { payload, repo } = context const newComment = `${{ steps.format_lighthouse_score.outputs.comments }}` - octokit.issues.createComment({ + const prevComments = await ocktokit.rest.issues.listComments({ owner: repo.owner repo: repo.repo, issue_number : payload.pull__request__number, - body: newcomment }) - - - - - + const prevComment = comments.find(comment => comment.body.includes(`### 💡 LightHouse Reports\n\n`)); + + if (prevComment) { + await octokit.rest.issues.updateComment({ + owner: repo.owner + repo: repo.repo, + comment_id: prevComment.id, + body: newComment, + }); + } else { + await octokit.rest.issues.updateComment({ + owner: repo.owner + repo: repo.repo, + issue_number : payload.pull__request__number, + body: newComment, + }