Skip to content

Commit

Permalink
chore: lighthouse 결과를 comment에 반영하는 step 추가 (SP-668)
Browse files Browse the repository at this point in the history
  • Loading branch information
SungHyun627 committed Aug 20, 2024
1 parent 2782d54 commit acf051c
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
Expand Down Expand Up @@ -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';
Expand All @@ -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,
}

0 comments on commit acf051c

Please sign in to comment.