mirror of
https://github.com/bartvdbraak/hellob.art.git
synced 2025-04-26 17:11:21 +00:00
feat: update dynamic badge for pull requests
This commit is contained in:
parent
06e1740366
commit
4529530d8e
2 changed files with 35 additions and 5 deletions
39
.github/workflows/unlighthouse.yaml
vendored
39
.github/workflows/unlighthouse.yaml
vendored
|
@ -1,6 +1,9 @@
|
|||
name: Unlighthouse
|
||||
|
||||
on: [pull_request]
|
||||
on:
|
||||
push:
|
||||
branches: main
|
||||
pull_request:
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
@ -12,13 +15,13 @@ jobs:
|
|||
COMMENT_ID: unlighthouse-node${{matrix.node-version}}
|
||||
PORT: 8000
|
||||
CLOUDFLARE_PROJECT: hellobart-unlighthouse
|
||||
CLOUDFLARE_BRANCH: pull-${{ github.event.pull_request.number }}
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18]
|
||||
steps:
|
||||
- name: Create initial comment
|
||||
uses: marocchino/sticky-pull-request-comment@v2.8.0
|
||||
if: github.ref != 'refs/heads/main'
|
||||
with:
|
||||
header: ${{ env.COMMENT_ID }}
|
||||
message: |
|
||||
|
@ -26,6 +29,16 @@ jobs:
|
|||
|
||||

|
||||
|
||||
- name: Set variables based on trigger
|
||||
run: |
|
||||
if [[ ${{ github.ref == 'refs/heads/main' }} == true ]]; then
|
||||
echo "CLOUDFLARE_BRANCH=main" >> $GITHUB_ENV
|
||||
echo "CLOUDFLARE_URL=https://${{ env.CLOUDFLARE_PROJECT }}.pages.dev" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CLOUDFLARE_BRANCH=pull-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
|
||||
echo "CLOUDFLARE_URL=https://pull-${{ github.event.pull_request.number }}.${{ env.CLOUDFLARE_PROJECT }}.pages.dev" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
|
@ -84,10 +97,11 @@ jobs:
|
|||
|
||||
const formatScore = score => `${Math.round(score * 100)} (${score})`;
|
||||
const getEmoji = score => score >= 0.9 ? '🟢' : score >= 0.5 ? '🟠' : '🔴';
|
||||
const getColor = score => score >= 0.9 ? 'green' : score >= 0.5 ? 'orange' : 'red';
|
||||
|
||||
const score = res => `${getEmoji(res)} ${formatScore(res)}`;
|
||||
|
||||
const reportUrl = `https://${{ env.CLOUDFLARE_BRANCH }}.${{ env.CLOUDFLARE_PROJECT }}.pages.dev`;
|
||||
const reportUrl = `${{ env.CLOUDFLARE_URL }}`;
|
||||
|
||||
const comment = [
|
||||
`⚡️ Lighthouse report for the changes in this PR:`,
|
||||
|
@ -115,16 +129,31 @@ jobs:
|
|||
].join('\n');
|
||||
|
||||
core.setOutput("comment", comment);
|
||||
core.setOutput("score", `${Math.round(result.summary.score * 100)}`);
|
||||
core.setOutput("scoreColor", getColor(result.summary.score));
|
||||
|
||||
- name: Update comment with result
|
||||
uses: marocchino/sticky-pull-request-comment@v2.8.0
|
||||
if: github.ref != 'refs/heads/main'
|
||||
with:
|
||||
header: ${{ env.COMMENT_ID }}
|
||||
message: ${{ steps.create_result_content.outputs.comment }}
|
||||
|
||||
- name: Create Lighthouse Score badge
|
||||
uses: schneegans/dynamic-badges-action@v1.7.0
|
||||
if: github.ref == 'refs/heads/main'
|
||||
with:
|
||||
auth: ${{ secrets.GIST_SECRET }}
|
||||
gistID: 795a3d6af5b0db5754cf7279898c3c16
|
||||
filename: hellob.art-unlighthouse.json
|
||||
namedLogo: Lighthouse
|
||||
label: Lighthouse
|
||||
message: ${{ steps.create_result_content.outputs.score }}
|
||||
color: ${{ steps.create_result_content.outputs.scoreColor }}
|
||||
|
||||
- name: Update comment on failure
|
||||
uses: marocchino/sticky-pull-request-comment@v2.8.0
|
||||
if: ${{ failure() }}
|
||||
if: failure() && github.ref != 'refs/heads/main'
|
||||
with:
|
||||
header: ${{ env.COMMENT_ID }}
|
||||
message: |
|
||||
|
@ -134,7 +163,7 @@ jobs:
|
|||
|
||||
- name: Update comment on cancel
|
||||
uses: marocchino/sticky-pull-request-comment@v2.8.0
|
||||
if: ${{ cancelled() }}
|
||||
if: cancelled() && github.ref != 'refs/heads/main'
|
||||
with:
|
||||
header: ${{ env.COMMENT_ID }}
|
||||
message: |
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
<div align="center">
|
||||
<a href="https://sonarcloud.io/summary/new_code?id=bartvdbraak_hellob.art"><img src="https://sonarcloud.io/api/project_badges/measure?project=bartvdbraak_hellob.art&metric=alert_status" /></a>
|
||||
<a href="https://hellobart-unlighthouse.pages.dev"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/bartvdbraak/795a3d6af5b0db5754cf7279898c3c16/raw/hellob.art-unlighthouse.json" /></a>
|
||||
<a href="https://github.com/bartvdbraak/hellob.art/deployments/activity_log?environment=Production"><img src="https://img.shields.io/github/deployments/bartvdbraak/hellob.art/production?label=vercel&logo=vercel" /></a>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in a new issue