mirror of
https://github.com/bartvdbraak/omnidash.git
synced 2025-04-27 15:31:21 +00:00
refactor: improve output value usage
This commit is contained in:
parent
321e00ed26
commit
4fa20ea103
1 changed files with 29 additions and 14 deletions
43
.github/workflows/unlighthouse.yaml
vendored
43
.github/workflows/unlighthouse.yaml
vendored
|
@ -89,25 +89,21 @@ jobs:
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
command: pages deploy .unlighthouse --project-name="${{ env.CLOUDFLARE_PROJECT }}" --branch=${{ steps.set_variables.outputs.CLOUDFLARE_BRANCH }}
|
command: pages deploy .unlighthouse --project-name="${{ env.CLOUDFLARE_PROJECT }}" --branch=${{ steps.set_variables.outputs.CLOUDFLARE_BRANCH }}
|
||||||
|
|
||||||
- name: Create result content
|
- name: Create comment content
|
||||||
id: create_result_content
|
id: create_comment
|
||||||
uses: actions/github-script@v7.0.1
|
uses: actions/github-script@v7.0.1
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
result-encoding: string
|
||||||
script: |
|
script: |
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8'));
|
const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8'));
|
||||||
|
|
||||||
const formatScore = score => `${Math.round(score * 100)} (${score})`;
|
const formatScore = score => `${Math.round(score * 100)} (${score})`;
|
||||||
const getEmoji = score => score >= 0.9 ? '🟢' : score >= 0.5 ? '🟠' : '🔴';
|
const getEmoji = score => score >= 0.9 ? '🟢' : score >= 0.5 ? '🟠' : '🔴';
|
||||||
const getColor = score => score >= 0.9 ? '4c1' : score >= 0.5 ? 'ffa400' : 'eb0f00';
|
const getColor = score => score >= 0.9 ? '4c1' : score >= 0.5 ? 'ffa400' : 'eb0f00';
|
||||||
|
|
||||||
const score = res => `${getEmoji(res)} ${formatScore(res)}`;
|
const score = res => `${getEmoji(res)} ${formatScore(res)}`;
|
||||||
|
|
||||||
const reportUrl = `${{ steps.set_variables.outputs.CLOUDFLARE_URL }}`;
|
const reportUrl = `${{ steps.set_variables.outputs.CLOUDFLARE_URL }}`;
|
||||||
|
return [
|
||||||
const comment = [
|
|
||||||
`## ✅ **Unlighthouse report** 🗼`,
|
`## ✅ **Unlighthouse report** 🗼`,
|
||||||
'| Category | Score |',
|
'| Category | Score |',
|
||||||
'| --- | --- |',
|
'| --- | --- |',
|
||||||
|
@ -132,16 +128,35 @@ jobs:
|
||||||
`View the full Lighthouse report [here](${reportUrl}).`,
|
`View the full Lighthouse report [here](${reportUrl}).`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
core.setOutput("comment", comment);
|
- name: Create summary score
|
||||||
core.setOutput("score", `${Math.round(result.summary.score * 100)}`);
|
id: create_score
|
||||||
core.setOutput("scoreColor", getColor(result.summary.score));
|
uses: actions/github-script@v7.0.1
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
result-encoding: string
|
||||||
|
script: |
|
||||||
|
const fs = require('fs');
|
||||||
|
const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8'));
|
||||||
|
return `${Math.round(result.summary.score * 100)}`;
|
||||||
|
|
||||||
|
- name: Create summary score color
|
||||||
|
id: create_score_color
|
||||||
|
uses: actions/github-script@v7.0.1
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
result-encoding: string
|
||||||
|
script: |
|
||||||
|
const fs = require('fs');
|
||||||
|
const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8'));
|
||||||
|
const getColor = score => score >= 0.9 ? '4c1' : score >= 0.5 ? 'ffa400' : 'eb0f00';
|
||||||
|
return getColor(result.summary.score);
|
||||||
|
|
||||||
- name: Update comment with result
|
- name: Update comment with result
|
||||||
uses: marocchino/sticky-pull-request-comment@v2.9.0
|
uses: marocchino/sticky-pull-request-comment@v2.9.0
|
||||||
if: github.ref != 'refs/heads/main'
|
if: github.ref != 'refs/heads/main'
|
||||||
with:
|
with:
|
||||||
header: ${{ env.COMMENT_ID }}
|
header: ${{ env.COMMENT_ID }}
|
||||||
message: ${{ steps.create_result_content.outputs.comment }}
|
message: ${{ steps.create_comment.outputs.result }}
|
||||||
|
|
||||||
- name: Create Lighthouse Score badge
|
- name: Create Lighthouse Score badge
|
||||||
uses: schneegans/dynamic-badges-action@v1.7.0
|
uses: schneegans/dynamic-badges-action@v1.7.0
|
||||||
|
@ -152,8 +167,8 @@ jobs:
|
||||||
filename: ${{ env.BADGE_FILE }}
|
filename: ${{ env.BADGE_FILE }}
|
||||||
namedLogo: Lighthouse
|
namedLogo: Lighthouse
|
||||||
label: lighthouse
|
label: lighthouse
|
||||||
message: ${{ steps.create_result_content.outputs.score }}
|
message: ${{ steps.create_score.outputs.result }}
|
||||||
color: ${{ steps.create_result_content.outputs.scoreColor }}
|
color: ${{ steps.create_score_color.outputs.result }}
|
||||||
|
|
||||||
- name: Update comment on failure
|
- name: Update comment on failure
|
||||||
uses: marocchino/sticky-pull-request-comment@v2.9.0
|
uses: marocchino/sticky-pull-request-comment@v2.9.0
|
||||||
|
|
Loading…
Reference in a new issue