Skip to content

Commit

Permalink
feat: update dynamic badge for pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvdbraak committed Nov 18, 2023
1 parent 06e1740 commit 88d02fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 additions & 4 deletions .github/workflows/unlighthouse.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Unlighthouse

Check failure on line 1 in .github/workflows/unlighthouse.yaml

View workflow job for this annotation

GitHub Actions / Prettier

.github/workflows/unlighthouse.yaml#L1

There are issues with this file's formatting, please run Prettier to fix the errors

on: [pull_request]
on:
push:
branches:
main
pull_request:

permissions:
pull-requests: write
Expand All @@ -12,20 +16,29 @@ 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/[email protected]
if: github.ref != 'refs/heads/main'
with:
header: ${{ env.COMMENT_ID }}
message: |
⚡️ Lighthouse report
![loading](https://github.com/bartvdbraak/hellob.art/assets/3996360/0e00b3fc-d5f9-490b-9aa7-07cb4b59f85f)
- name: Set variables based on trigger
run: |
echo "Discovering the environment stage:"
if [[ ${{ github.ref == 'refs/heads/main' }} ]]; then
echo "CLOUDFLARE_BRANCH=main" >> $GITHUB_ENV
else
echo "CLOUDFLARE_BRANCH=pull-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
fi
- name: Checkout repository
uses: actions/[email protected]

Expand Down Expand Up @@ -84,6 +97,7 @@ 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)}`;
Expand Down Expand Up @@ -115,16 +129,31 @@ jobs:
].join('\n');
core.setOutput("comment", comment);
core.setOutput("score", `${result.summary.score}`);
core.setOutput("scoreColor", getColor(result.summary.score));
- name: Update comment with result
uses: marocchino/[email protected]
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/[email protected]
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/[email protected]
if: ${{ failure() }}
if: failure() && github.ref != 'refs/heads/main'
with:
header: ${{ env.COMMENT_ID }}
message: |
Expand All @@ -134,7 +163,7 @@ jobs:
- name: Update comment on cancel
uses: marocchino/[email protected]
if: ${{ cancelled() }}
if: cancelled() && github.ref != 'refs/heads/main'
with:
header: ${{ env.COMMENT_ID }}
message: |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://main.hellobart-unlighthouse.pages.dev"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/bartvdbraak/795a3d6af5b0db5754cf7279898c3c16/raw/a6a42cf47bbb11fe7de6db90a2957e043d11039e/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>

Expand Down

0 comments on commit 88d02fa

Please sign in to comment.