From b6bdfe940b635dc455a80dfd0dbea0bb0962cead Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 18 Nov 2023 11:29:34 -0800 Subject: [PATCH] feat: update dynamic badge for pull requests --- .github/workflows/unlighthouse.yaml | 36 +++++++++++++++++++++++++---- README.md | 1 + 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unlighthouse.yaml b/.github/workflows/unlighthouse.yaml index d5d77e88..e5b7c1a0 100644 --- a/.github/workflows/unlighthouse.yaml +++ b/.github/workflows/unlighthouse.yaml @@ -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,15 @@ jobs: ![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/checkout@v4.1.1 @@ -84,6 +96,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)}`; @@ -115,16 +128,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 +162,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: | diff --git a/README.md b/README.md index abd8247e..54b0fdc9 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@
+