From 822514fdc178f6c22b16aa2f59f3ae235438f2af Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Fri, 9 Jun 2023 18:47:07 +0200 Subject: [PATCH 01/38] feat: Initial workflow for unlighthouse --- .github/workflows/seo.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/seo.yaml diff --git a/.github/workflows/seo.yaml b/.github/workflows/seo.yaml new file mode 100644 index 0000000..39f4ae9 --- /dev/null +++ b/.github/workflows/seo.yaml @@ -0,0 +1,34 @@ +name: Assertions and static report + +on: + workflow_dispatch: + +jobs: + demo: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install Dependencies + run: npm add @unlighthouse/cli puppeteer + + - name: Unlighthouse assertions and client + run: unlighthouse-ci --site --build-static + + - name: Deploy report to Netlify + uses: nwtgck/actions-netlify@v1.2 + with: + publish-dir: './.unlighthouse' + production-branch: main + production-deploy: true + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "New Release Deploy from GitHub Actions" + enable-pull-request-comment: false + enable-commit-comment: true + overwrites-pull-request-comment: true + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }} + timeout-minutes: 1 From 511042c32df0825d60bd39c26c401d79c65684a6 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 17:50:02 +0200 Subject: [PATCH 02/38] feat: Add Dependabot updates for Github Actions --- .github/dependabot.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d1f0d08..406baea 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,7 @@ updates: directory: "/" schedule: interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 81b8ebe80742e2e2d416350e2dd554ccc5f0ca66 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 17:50:43 +0200 Subject: [PATCH 03/38] refactor: Rename Workflow reflecting intended use --- .github/workflows/{check.yaml => lint-deps-check.yaml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{check.yaml => lint-deps-check.yaml} (94%) diff --git a/.github/workflows/check.yaml b/.github/workflows/lint-deps-check.yaml similarity index 94% rename from .github/workflows/check.yaml rename to .github/workflows/lint-deps-check.yaml index d023901..ac91874 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/lint-deps-check.yaml @@ -1,4 +1,4 @@ -name: Checks +name: Linting and Dependency Check on: push: From f513fbe44acff6c1f5058c67b47441ffce013046 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 17:51:16 +0200 Subject: [PATCH 04/38] feat: SEO reports Workflow using `unlighthouse` --- .github/workflows/seo-report.yaml | 31 ++++++++++++++++++++++++++++ .github/workflows/seo.yaml | 34 ------------------------------- 2 files changed, 31 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/seo-report.yaml delete mode 100644 .github/workflows/seo.yaml diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml new file mode 100644 index 0000000..9b7f240 --- /dev/null +++ b/.github/workflows/seo-report.yaml @@ -0,0 +1,31 @@ +name: Unlighthouse SEO Reports + +on: + [deployment_status] + +jobs: + e2e: + if: github.event.deployment_status.state == 'success' + runs-on: ubuntu-latest + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v1 + with: + node-version: 20 + + - name: Install Dependencies + run: yarn global add @unlighthouse/cli puppeteer + + - name: Build Unlighthouse report + run: unlighthouse-ci --site ${{ github.event.deployment_status.target_url }} --build-static + + - name: Deploy report to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: './.unlighthouse' + publish_branch: gh-pages + publish_dir_prefix: ${{ github.head_ref }} diff --git a/.github/workflows/seo.yaml b/.github/workflows/seo.yaml deleted file mode 100644 index 39f4ae9..0000000 --- a/.github/workflows/seo.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: Assertions and static report - -on: - workflow_dispatch: - -jobs: - demo: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Install Dependencies - run: npm add @unlighthouse/cli puppeteer - - - name: Unlighthouse assertions and client - run: unlighthouse-ci --site --build-static - - - name: Deploy report to Netlify - uses: nwtgck/actions-netlify@v1.2 - with: - publish-dir: './.unlighthouse' - production-branch: main - production-deploy: true - github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: "New Release Deploy from GitHub Actions" - enable-pull-request-comment: false - enable-commit-comment: true - overwrites-pull-request-comment: true - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEMO_SITE_ID }} - timeout-minutes: 1 From eef4772cb23e917744263cc26fdad598644daa16 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 18:30:50 +0200 Subject: [PATCH 05/38] refactor: Use native Github Actions --- .github/workflows/seo-report.yaml | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 9b7f240..5f2c21a 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -4,7 +4,7 @@ on: [deployment_status] jobs: - e2e: + build: if: github.event.deployment_status.state == 'success' runs-on: ubuntu-latest steps: @@ -22,10 +22,21 @@ jobs: - name: Build Unlighthouse report run: unlighthouse-ci --site ${{ github.event.deployment_status.target_url }} --build-static - - name: Deploy report to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 + - name: Upload GitHub Pages artifact + uses: actions/upload-pages-artifact@v1.0.8 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: './.unlighthouse' - publish_branch: gh-pages - publish_dir_prefix: ${{ github.head_ref }} + path: './.unlighthouse' + + deploy: + needs: build + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 From aacc5216da1ea665f77de27e6cbe028955d0bbcf Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 18:42:35 +0200 Subject: [PATCH 06/38] refactor: Update GitHub Action task versions --- .github/workflows/seo-report.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 5f2c21a..99e6669 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out Git repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 20 From f5d8d10c256dae156b811216e9e8366dae45f2ef Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 18:48:20 +0200 Subject: [PATCH 07/38] refactor: Add permissions, concurrency, manual --- .github/workflows/seo-report.yaml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 99e6669..b7ef165 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -1,7 +1,16 @@ name: Unlighthouse SEO Reports on: - [deployment_status] + [deployment_status, workflow_dispatch] + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false jobs: build: @@ -25,17 +34,14 @@ jobs: - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v1.0.8 with: - path: './.unlighthouse' + path: ./.unlighthouse deploy: - needs: build - permissions: - pages: write - id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest + needs: build steps: - name: Deploy to GitHub Pages id: deployment From 1f1817a81a21fb597c44d7eedcd820ccfc474914 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 19:00:01 +0200 Subject: [PATCH 08/38] refactor: Minor name change --- .github/workflows/seo-report.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index b7ef165..45f1363 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -17,7 +17,7 @@ jobs: if: github.event.deployment_status.state == 'success' runs-on: ubuntu-latest steps: - - name: Check out Git repository + - name: Check out uses: actions/checkout@v3 - name: Set up Node.js From 106b07a8adf94293d5d8161f77af9458d45fd16f Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 20:11:59 +0200 Subject: [PATCH 09/38] debug: See if a deployment from different actor would work --- .github/workflows/seo-report.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 45f1363..7005cf4 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -1,7 +1,10 @@ name: Unlighthouse SEO Reports on: - [deployment_status, workflow_dispatch] + pull_request: + types: + - opened + - synchronize permissions: contents: read @@ -14,7 +17,6 @@ concurrency: jobs: build: - if: github.event.deployment_status.state == 'success' runs-on: ubuntu-latest steps: - name: Check out @@ -29,7 +31,7 @@ jobs: run: yarn global add @unlighthouse/cli puppeteer - name: Build Unlighthouse report - run: unlighthouse-ci --site ${{ github.event.deployment_status.target_url }} --build-static + run: unlighthouse-ci --site "https://omnidash.io" --build-static - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v1.0.8 From d42570b4c41581ac0221bed76ed46bc8c567ffc7 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 20:38:41 +0200 Subject: [PATCH 10/38] fix: Change base path for `unlighthouse` build --- .github/workflows/seo-report.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 7005cf4..bd05874 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -33,6 +33,10 @@ jobs: - name: Build Unlighthouse report run: unlighthouse-ci --site "https://omnidash.io" --build-static + - name: Add base href to `index.html` + run: | + node -e "const fs = require('fs'); const file = './.unlighthouse/index.html'; let html = fs.readFileSync(file, 'utf-8'); html = html.replace(/([\s\S]*?)<\/head>/, (match, headContent) => '' + headContent + ''); fs.writeFileSync(file, html);" + - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v1.0.8 with: From fc6e7392a92b805dc1488b7aa2712787bce34ba5 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 20:39:15 +0200 Subject: [PATCH 11/38] feat: Added `.unlighthouse` dir to ignorelist --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8f322f0..2d9b881 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +# unlighthouse +.unlighthouse From 33304c1945479683145fca0bbd2e481724d71b5d Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 20:52:08 +0200 Subject: [PATCH 12/38] fix: Use router prefix to fix build for GitHub Pages --- .github/workflows/seo-report.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index bd05874..6de22eb 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -31,11 +31,7 @@ jobs: run: yarn global add @unlighthouse/cli puppeteer - name: Build Unlighthouse report - run: unlighthouse-ci --site "https://omnidash.io" --build-static - - - name: Add base href to `index.html` - run: | - node -e "const fs = require('fs'); const file = './.unlighthouse/index.html'; let html = fs.readFileSync(file, 'utf-8'); html = html.replace(/([\s\S]*?)<\/head>/, (match, headContent) => '' + headContent + ''); fs.writeFileSync(file, html);" + run: unlighthouse-ci --site "https://omnidash.io" --build-static --router-prefix ${{ github.event.repository.name }} - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v1.0.8 From 5a59e24a31ccaaf4d203b1749b1dab80d3cfa293 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 21:41:55 +0200 Subject: [PATCH 13/38] refactor: `deployment_status` trigger using secret --- .github/workflows/seo-report.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 6de22eb..04a8f21 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -1,10 +1,7 @@ name: Unlighthouse SEO Reports on: - pull_request: - types: - - opened - - synchronize + deployment_status permissions: contents: read @@ -48,3 +45,5 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v2 + with: + token: ${{ secrets.GH_PAGES_TOKEN }} From b2c4144c7061eaccbb0a407a721ce4fcc276fd07 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 10 Jun 2023 21:59:57 +0200 Subject: [PATCH 14/38] fix: Added correct `target_url` to analysis --- .github/workflows/seo-report.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 04a8f21..7f736e2 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -28,7 +28,7 @@ jobs: run: yarn global add @unlighthouse/cli puppeteer - name: Build Unlighthouse report - run: unlighthouse-ci --site "https://omnidash.io" --build-static --router-prefix ${{ github.event.repository.name }} + run: unlighthouse-ci --site "${{ github.event.deployment_status.target_url }}" --build-static --router-prefix ${{ github.event.repository.name }} - name: Upload GitHub Pages artifact uses: actions/upload-pages-artifact@v1.0.8 From 70c5d497c14ec61148716be10b8c324e98730c09 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:01:02 +0200 Subject: [PATCH 15/38] debug: Try different method for gh-pages deploy --- .github/workflows/seo-report.yaml | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 7f736e2..7c1a754 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -13,7 +13,11 @@ concurrency: cancel-in-progress: false jobs: - build: + build-deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + if: github.event.deployment_status.state == 'success' runs-on: ubuntu-latest steps: - name: Check out @@ -25,25 +29,14 @@ jobs: node-version: 20 - name: Install Dependencies - run: yarn global add @unlighthouse/cli puppeteer + run: yarn global add @unlighthouse/cli puppeteer gh-pages - name: Build Unlighthouse report run: unlighthouse-ci --site "${{ github.event.deployment_status.target_url }}" --build-static --router-prefix ${{ github.event.repository.name }} - - name: Upload GitHub Pages artifact - uses: actions/upload-pages-artifact@v1.0.8 - with: - path: ./.unlighthouse - - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v2 - with: - token: ${{ secrets.GH_PAGES_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GH_PAGES_TOKEN }} + run: | + echo "baseurl: /$(basename $GITHUB_REF)" >> _config.yml + npx gh-pages --dist ./.unlighthouse --repo $(basename $GITHUB_REPOSITORY) --branch gh-pages From 6645962e4cbc46ddf9e5fcae7d2405d4b82cfa51 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:08:47 +0200 Subject: [PATCH 16/38] feat: Use subdirectory for parralel branch deployments --- .github/workflows/seo-report.yaml | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 7c1a754..5028b73 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -14,9 +14,6 @@ concurrency: jobs: build-deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} if: github.event.deployment_status.state == 'success' runs-on: ubuntu-latest steps: @@ -29,14 +26,19 @@ jobs: node-version: 20 - name: Install Dependencies - run: yarn global add @unlighthouse/cli puppeteer gh-pages + run: yarn global add @unlighthouse/cli puppeteer - name: Build Unlighthouse report - run: unlighthouse-ci --site "${{ github.event.deployment_status.target_url }}" --build-static --router-prefix ${{ github.event.repository.name }} - - - name: Deploy to GitHub Pages - env: - GITHUB_TOKEN: ${{ secrets.GH_PAGES_TOKEN }} run: | - echo "baseurl: /$(basename $GITHUB_REF)" >> _config.yml - npx gh-pages --dist ./.unlighthouse --repo $(basename $GITHUB_REPOSITORY) --branch gh-pages + unlighthouse-ci \ + --site "${{ github.event.deployment_status.target_url }}" \ + --build-static \ + --router-prefix "${{ github.event.repository.name }}/${{ github.head_ref }}" + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./.unlighthouse + destination_dir: ${{ github.head_ref }} + From 3d452350dfb3cb6a0df80e44802729ea0198d1cc Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:14:08 +0200 Subject: [PATCH 17/38] fix: Change token to be able to reach repo --- .github/workflows/seo-report.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 5028b73..6a6fd44 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -15,6 +15,9 @@ concurrency: jobs: build-deploy: if: github.event.deployment_status.state == 'success' + environment: + name: github-pages + url: '' runs-on: ubuntu-latest steps: - name: Check out @@ -38,7 +41,7 @@ jobs: - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GH_PAGES_TOKEN }} publish_dir: ./.unlighthouse destination_dir: ${{ github.head_ref }} From 5f951d73edafd22140f93e53a0b1f7c59a43022d Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:24:58 +0200 Subject: [PATCH 18/38] feat: Add deployment environment URL --- .github/workflows/seo-report.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 6a6fd44..2215589 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -17,7 +17,7 @@ jobs: if: github.event.deployment_status.state == 'success' environment: name: github-pages - url: '' + url: https://${{ github.repository_owner }}.github.io/${{ github.repository }}/${{ github.event.repository.name }}/${{ github.head_ref }} runs-on: ubuntu-latest steps: - name: Check out From 9d3bbc281ff20d509a293a4540b11972c03a23a3 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:40:09 +0200 Subject: [PATCH 19/38] debug: Retrieve related branch --- .github/workflows/seo-report.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 2215589..03e92b8 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -17,7 +17,7 @@ jobs: if: github.event.deployment_status.state == 'success' environment: name: github-pages - url: https://${{ github.repository_owner }}.github.io/${{ github.repository }}/${{ github.event.repository.name }}/${{ github.head_ref }} + url: https://${{ github.repository_owner }}.github.io/${{ github.head_ref }}/ runs-on: ubuntu-latest steps: - name: Check out @@ -31,6 +31,16 @@ jobs: - name: Install Dependencies run: yarn global add @unlighthouse/cli puppeteer + - name: Get Deployment Source Branch Name + id: git-branch + run: | + git branch -a --contains ${{ github.event.deployment.ref }} + source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" + result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" + echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + - name: Build Unlighthouse report run: | unlighthouse-ci \ From 4dd7664f29af7babe01bef1c26f635cffcbec448 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 00:51:51 +0200 Subject: [PATCH 20/38] debug: Retrieve through the use of GitHub API --- .github/workflows/seo-report.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 03e92b8..4291c41 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -34,12 +34,11 @@ jobs: - name: Get Deployment Source Branch Name id: git-branch run: | - git branch -a --contains ${{ github.event.deployment.ref }} - source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" - result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" - echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + branch=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/deployments/${{ github.event.deployment.id }}" \ + | jq -r '.ref' | cut -d "/" -f 3-) + echo "Source branch of deployment: $branch" + echo "SOURCE_REF=$branch" >> "$GITHUB_ENV" - name: Build Unlighthouse report run: | From 7772c6367efcc856a49fe02de8cc7ef9afc8bba8 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 01:00:22 +0200 Subject: [PATCH 21/38] debug: Retry using commit SHA --- .github/workflows/seo-report.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 4291c41..6f26359 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -34,9 +34,12 @@ jobs: - name: Get Deployment Source Branch Name id: git-branch run: | + commit_sha=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/deployments/${{ github.event.deployment.id }}" \ + | jq -r '.sha') branch=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/deployments/${{ github.event.deployment.id }}" \ - | jq -r '.ref' | cut -d "/" -f 3-) + "https://api.github.com/repos/${{ github.repository }}/commits/$commit_sha" \ + | jq -r '.ref' | sed 's/refs\/heads\///') echo "Source branch of deployment: $branch" echo "SOURCE_REF=$branch" >> "$GITHUB_ENV" From bb718525ef5b302bc433678b02d78a916dd98e48 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 01:14:55 +0200 Subject: [PATCH 22/38] debug: Return to git commands before checkout --- .github/workflows/seo-report.yaml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 6f26359..db8f151 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -20,6 +20,16 @@ jobs: url: https://${{ github.repository_owner }}.github.io/${{ github.head_ref }}/ runs-on: ubuntu-latest steps: + - name: Get Deployment Source Branch Name + id: git-branch + run: | + git branch -a --contains ${{ github.event.deployment.ref }} + source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" + result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" + echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + - name: Check out uses: actions/checkout@v3 @@ -31,18 +41,6 @@ jobs: - name: Install Dependencies run: yarn global add @unlighthouse/cli puppeteer - - name: Get Deployment Source Branch Name - id: git-branch - run: | - commit_sha=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/deployments/${{ github.event.deployment.id }}" \ - | jq -r '.sha') - branch=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/commits/$commit_sha" \ - | jq -r '.ref' | sed 's/refs\/heads\///') - echo "Source branch of deployment: $branch" - echo "SOURCE_REF=$branch" >> "$GITHUB_ENV" - - name: Build Unlighthouse report run: | unlighthouse-ci \ From e104b3adc0d9361740d65695f4f4a03a4432d78a Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 01:18:30 +0200 Subject: [PATCH 23/38] debug: Move step back after checkout, with fetch all --- .github/workflows/seo-report.yaml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index db8f151..7b4cc4b 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -20,16 +20,6 @@ jobs: url: https://${{ github.repository_owner }}.github.io/${{ github.head_ref }}/ runs-on: ubuntu-latest steps: - - name: Get Deployment Source Branch Name - id: git-branch - run: | - git branch -a --contains ${{ github.event.deployment.ref }} - source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" - result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" - echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" - - name: Check out uses: actions/checkout@v3 @@ -41,6 +31,17 @@ jobs: - name: Install Dependencies run: yarn global add @unlighthouse/cli puppeteer + - name: Get Deployment Source Branch Name + id: git-branch + run: | + git fetch --all + git branch -a --contains ${{ github.event.deployment.ref }} + source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" + result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" + echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + - name: Build Unlighthouse report run: | unlighthouse-ci \ From bb718ae289e8dadd3b37ce782e85021a5726fab9 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 01:26:52 +0200 Subject: [PATCH 24/38] feat: Added correct notation for the branch --- .github/workflows/seo-report.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 7b4cc4b..6f17cbe 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -17,7 +17,7 @@ jobs: if: github.event.deployment_status.state == 'success' environment: name: github-pages - url: https://${{ github.repository_owner }}.github.io/${{ github.head_ref }}/ + url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} runs-on: ubuntu-latest steps: - name: Check out @@ -47,12 +47,12 @@ jobs: unlighthouse-ci \ --site "${{ github.event.deployment_status.target_url }}" \ --build-static \ - --router-prefix "${{ github.event.repository.name }}/${{ github.head_ref }}" + --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GH_PAGES_TOKEN }} publish_dir: ./.unlighthouse - destination_dir: ${{ github.head_ref }} + destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} From ad09a0960b59d449796bc27006221ef0a7e46590 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 01:31:52 +0200 Subject: [PATCH 25/38] debug: File system information --- .github/workflows/seo-report.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index 6f17cbe..ab2dc50 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -44,10 +44,12 @@ jobs: - name: Build Unlighthouse report run: | + pwd unlighthouse-ci \ --site "${{ github.event.deployment_status.target_url }}" \ --build-static \ --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" + ls -la - name: Deploy uses: peaceiris/actions-gh-pages@v3 From 2623cb62780081f41cfebf20e08a467ce92e64b2 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 03:01:45 +0200 Subject: [PATCH 26/38] debug: Remove system info --- .github/workflows/seo-report.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml index ab2dc50..6f17cbe 100644 --- a/.github/workflows/seo-report.yaml +++ b/.github/workflows/seo-report.yaml @@ -44,12 +44,10 @@ jobs: - name: Build Unlighthouse report run: | - pwd unlighthouse-ci \ --site "${{ github.event.deployment_status.target_url }}" \ --build-static \ --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - ls -la - name: Deploy uses: peaceiris/actions-gh-pages@v3 From 79add3a8815c4d2111a91198a4fb1e86b1ebb321 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 03:02:44 +0200 Subject: [PATCH 27/38] feat: `vercel.json` disabling deploying `gh-pages` --- vercel.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 vercel.json diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..e686f30 --- /dev/null +++ b/vercel.json @@ -0,0 +1,7 @@ +{ + "git": { + "deploymentEnabled": { + "gh-pages": false + } + } +} From f94056228e1805ff09c9baeb7477a3c0aa6482b8 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 15:45:07 +0200 Subject: [PATCH 28/38] feat: Rename Workflow file and commenting --- .github/workflows/seo-report.yaml | 58 ---------- .../workflows/unlighthouse/build-deploy.yaml | 107 ++++++++++++++++++ 2 files changed, 107 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/seo-report.yaml create mode 100644 .github/workflows/unlighthouse/build-deploy.yaml diff --git a/.github/workflows/seo-report.yaml b/.github/workflows/seo-report.yaml deleted file mode 100644 index 6f17cbe..0000000 --- a/.github/workflows/seo-report.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: Unlighthouse SEO Reports - -on: - deployment_status - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - build-deploy: - if: github.event.deployment_status.state == 'success' - environment: - name: github-pages - url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install Dependencies - run: yarn global add @unlighthouse/cli puppeteer - - - name: Get Deployment Source Branch Name - id: git-branch - run: | - git fetch --all - git branch -a --contains ${{ github.event.deployment.ref }} - source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" - result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" - echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" - - - name: Build Unlighthouse report - run: | - unlighthouse-ci \ - --site "${{ github.event.deployment_status.target_url }}" \ - --build-static \ - --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GH_PAGES_TOKEN }} - publish_dir: ./.unlighthouse - destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} - diff --git a/.github/workflows/unlighthouse/build-deploy.yaml b/.github/workflows/unlighthouse/build-deploy.yaml new file mode 100644 index 0000000..d355138 --- /dev/null +++ b/.github/workflows/unlighthouse/build-deploy.yaml @@ -0,0 +1,107 @@ +name: Unlighthouse SEO Reports + +on: + deployment_status + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build-deploy: + if: github.event.deployment_status.state == 'success' && (github.event.deployment_status.environment == 'Production' || github.event.deployment_status.environment == 'Preview') + environment: + name: github-pages + url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install Dependencies + run: yarn global add @unlighthouse/cli puppeteer + + - name: Get Deployment Source Branch Name + id: git-branch + run: | + git fetch --all + git branch -a --contains ${{ github.event.deployment.ref }} + source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" + result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" + echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + + - name: Build Unlighthouse report + run: | + unlighthouse-ci \ + --site "${{ github.event.deployment_status.target_url }}" \ + --build-static \ + --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" + + - name: Calculate Average Score + id: calculate-score + run: | + average=$(jq -r '[.[] | .score] | add / length' ./.unlighthouse/ci-result.json) + echo "::set-output name=average_score::$average" + + - name: Create Markdown Table + id: create-table + run: | + echo "## Unlighthouse Results" > ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "Path | Score" >> ./.unlighthouse/table.md + echo "-----|------" >> ./.unlighthouse/table.md + cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> ./.unlighthouse/table.md + echo "::set-output name=table_path::.unlighthouse/table.md" + + - name: Comment on Pull Request + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: tablePath + }); + + - name: Comment on issue + id: create_comment + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GH_PAGES_TOKEN}} + script: | + const fs = require('fs'); + const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: tablePath + }) + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GH_PAGES_TOKEN }} + publish_dir: ./.unlighthouse + destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} + From 2ea253fb94877a7205c56eaa0092959d0b289a45 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 15:47:13 +0200 Subject: [PATCH 29/38] refactor: Move and rename file --- .../build-deploy.yaml => unlighthouse-build-deploy.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{unlighthouse/build-deploy.yaml => unlighthouse-build-deploy.yaml} (100%) diff --git a/.github/workflows/unlighthouse/build-deploy.yaml b/.github/workflows/unlighthouse-build-deploy.yaml similarity index 100% rename from .github/workflows/unlighthouse/build-deploy.yaml rename to .github/workflows/unlighthouse-build-deploy.yaml From 1579a046a96c18ba370f016526a7af8fe930bab6 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 15:51:58 +0200 Subject: [PATCH 30/38] debug: Revert to old naming --- .github/workflows/seo-reports.yaml | 57 ++++++++++ .../workflows/unlighthouse-build-deploy.yaml | 107 ------------------ 2 files changed, 57 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/seo-reports.yaml delete mode 100644 .github/workflows/unlighthouse-build-deploy.yaml diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml new file mode 100644 index 0000000..4f134c1 --- /dev/null +++ b/.github/workflows/seo-reports.yaml @@ -0,0 +1,57 @@ +name: Unlighthouse SEO Reports + +on: + deployment_status + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build-deploy: + if: github.event.deployment_status.state == 'success' + environment: + name: github-pages + url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install Dependencies + run: yarn global add @unlighthouse/cli puppeteer + + - name: Get Deployment Source Branch Name + id: git-branch + run: | + git fetch --all + git branch -a --contains ${{ github.event.deployment.ref }} + source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" + result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" + echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + - name: Build Unlighthouse report + run: | + pwd + unlighthouse-ci \ + --site "${{ github.event.deployment_status.target_url }}" \ + --build-static \ + --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" + ls -la + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GH_PAGES_TOKEN }} + publish_dir: ./.unlighthouse + destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} diff --git a/.github/workflows/unlighthouse-build-deploy.yaml b/.github/workflows/unlighthouse-build-deploy.yaml deleted file mode 100644 index d355138..0000000 --- a/.github/workflows/unlighthouse-build-deploy.yaml +++ /dev/null @@ -1,107 +0,0 @@ -name: Unlighthouse SEO Reports - -on: - deployment_status - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - build-deploy: - if: github.event.deployment_status.state == 'success' && (github.event.deployment_status.environment == 'Production' || github.event.deployment_status.environment == 'Preview') - environment: - name: github-pages - url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install Dependencies - run: yarn global add @unlighthouse/cli puppeteer - - - name: Get Deployment Source Branch Name - id: git-branch - run: | - git fetch --all - git branch -a --contains ${{ github.event.deployment.ref }} - source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" - result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" - echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" - - - name: Build Unlighthouse report - run: | - unlighthouse-ci \ - --site "${{ github.event.deployment_status.target_url }}" \ - --build-static \ - --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - - - name: Calculate Average Score - id: calculate-score - run: | - average=$(jq -r '[.[] | .score] | add / length' ./.unlighthouse/ci-result.json) - echo "::set-output name=average_score::$average" - - - name: Create Markdown Table - id: create-table - run: | - echo "## Unlighthouse Results" > ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "Path | Score" >> ./.unlighthouse/table.md - echo "-----|------" >> ./.unlighthouse/table.md - cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> ./.unlighthouse/table.md - echo "::set-output name=table_path::.unlighthouse/table.md" - - - name: Comment on Pull Request - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: tablePath - }); - - - name: Comment on issue - id: create_comment - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GH_PAGES_TOKEN}} - script: | - const fs = require('fs'); - const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: tablePath - }) - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GH_PAGES_TOKEN }} - publish_dir: ./.unlighthouse - destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} - From e7b1ffec56e1537d52289f7b7fb81197ab7471c9 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 15:56:57 +0200 Subject: [PATCH 31/38] fix: Changes to remove unnecessary debug info --- .github/workflows/seo-reports.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml index 4f134c1..9f3c360 100644 --- a/.github/workflows/seo-reports.yaml +++ b/.github/workflows/seo-reports.yaml @@ -35,20 +35,17 @@ jobs: id: git-branch run: | git fetch --all - git branch -a --contains ${{ github.event.deployment.ref }} source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" + - name: Build Unlighthouse report run: | - pwd unlighthouse-ci \ --site "${{ github.event.deployment_status.target_url }}" \ --build-static \ --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - ls -la + - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: From 984b4e49f01e45c300e04afaeecd144e7bcd6bcd Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 16:18:04 +0200 Subject: [PATCH 32/38] fix: Added Deploy Key --- .github/workflows/seo-reports.yaml | 59 +++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml index 9f3c360..50b331f 100644 --- a/.github/workflows/seo-reports.yaml +++ b/.github/workflows/seo-reports.yaml @@ -14,10 +14,13 @@ concurrency: jobs: build-deploy: - if: github.event.deployment_status.state == 'success' + + if: github.event.deployment_status.state == 'success' && (github.event.deployment_status.environment == 'Production' || github.event.deployment_status.environment == 'Preview') + environment: name: github-pages url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} + runs-on: ubuntu-latest steps: - name: Check out @@ -35,8 +38,11 @@ jobs: id: git-branch run: | git fetch --all + git branch -a --contains ${{ github.event.deployment.ref }} source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') + echo "Remote source of deployment: ${result}" + echo "Local git ref of deployment: ${result#remotes/origin/*}" echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" - name: Build Unlighthouse report @@ -49,6 +55,55 @@ jobs: - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: - github_token: ${{ secrets.GH_PAGES_TOKEN }} + deploy_key: ${{ secrets.GH_PAGES_DEPLOY_PRIVATE_KEY }} publish_dir: ./.unlighthouse destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} + + - name: Calculate Average Score + id: calculate-score + run: | + average=$(jq -r '[.[] | .score] | add / length' ./.unlighthouse/ci-result.json) + echo "::set-output name=average_score::$average" + + - name: Create Markdown Table + id: create-table + run: | + echo "## Unlighthouse Results" > ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "Path | Score" >> ./.unlighthouse/table.md + echo "-----|------" >> ./.unlighthouse/table.md + cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> ./.unlighthouse/table.md + echo "" >> ./.unlighthouse/table.md + echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> ./.unlighthouse/table.md + echo "::set-output name=table_path::.unlighthouse/table.md" + + - name: Comment on Pull Request + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: tablePath + }); + + - name: Comment on issue + id: create_comment + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GH_PAGES_TOKEN}} + script: | + const fs = require('fs'); + const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: tablePath + }) From a41ae0e580e775db584f9f186f6bb1a72f7f69e5 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 17:15:43 +0200 Subject: [PATCH 33/38] fix: Deprecated set-output changes and GitHub Rest --- .github/workflows/seo-reports.yaml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml index 50b331f..b7b6208 100644 --- a/.github/workflows/seo-reports.yaml +++ b/.github/workflows/seo-reports.yaml @@ -63,29 +63,31 @@ jobs: id: calculate-score run: | average=$(jq -r '[.[] | .score] | add / length' ./.unlighthouse/ci-result.json) - echo "::set-output name=average_score::$average" + echo "average_score=${average}" >> "$GITHUB_OUTPUT" - name: Create Markdown Table id: create-table + env: + md_file_path: './.unlighthouse/table.md' run: | - echo "## Unlighthouse Results" > ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "Path | Score" >> ./.unlighthouse/table.md - echo "-----|------" >> ./.unlighthouse/table.md - cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> ./.unlighthouse/table.md - echo "" >> ./.unlighthouse/table.md - echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> ./.unlighthouse/table.md - echo "::set-output name=table_path::.unlighthouse/table.md" + echo "## Unlighthouse Results" > $md_file_path + echo "" >> $md_file_path + echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> $md_file_path + echo "" >> $md_file_path + echo "Path | Score" >> $md_file_path + echo "-----|------" >> $md_file_path + cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> $md_file_path + echo "" >> $md_file_path + echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> $md_file_path + echo "md_file_path=${md_file_path}" >> "$GITHUB_OUTPUT" - name: Comment on Pull Request uses: actions/github-script@v6 with: script: | const fs = require('fs'); - const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); - github.issues.createComment({ + const tablePath = fs.readFileSync('${{ steps.create-table.outputs.md_file_path }}', 'utf8'); + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From 9c2387e2c75bd345da4dbdd0db15c39d1f66da23 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 17:27:23 +0200 Subject: [PATCH 34/38] debug: Temporary debug logging --- .github/workflows/seo-reports.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml index b7b6208..95862f8 100644 --- a/.github/workflows/seo-reports.yaml +++ b/.github/workflows/seo-reports.yaml @@ -81,6 +81,13 @@ jobs: echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> $md_file_path echo "md_file_path=${md_file_path}" >> "$GITHUB_OUTPUT" + - run: | + echo GITHUB_ACTION: $GITHUB_ACTION + echo GITHUB_WORKFLOW: $GITHUB_WORKFLOW + echo GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME + echo GITHUB_EVENT_PATH: $GITHUB_EVENT_PATH + cat $GITHUB_EVENT_PATH + - name: Comment on Pull Request uses: actions/github-script@v6 with: From 2c918ef6efb58940be189e078519c19e4bda44e8 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 19:53:31 +0200 Subject: [PATCH 35/38] refactor: Entire rebuild based on PR trigger --- .github/workflows/lighthouse-report.yaml | 127 +++++++++++++++++++++++ .github/workflows/seo-reports.yaml | 118 --------------------- 2 files changed, 127 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/lighthouse-report.yaml delete mode 100644 .github/workflows/seo-reports.yaml diff --git a/.github/workflows/lighthouse-report.yaml b/.github/workflows/lighthouse-report.yaml new file mode 100644 index 0000000..262ee56 --- /dev/null +++ b/.github/workflows/lighthouse-report.yaml @@ -0,0 +1,127 @@ +name: Lighthouse report + +on: + pull_request: + +permissions: + contents: write + pages: write + id-token: write + pull-requests: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build-deploy: + environment: + name: github-pages + url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.BRANCH_NAME }} + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + runs-on: ubuntu-latest + steps: + - name: Sticky Comment on Pull Request + uses: marocchino/sticky-pull-request-comment@v2.6.2 + with: + header: unlighthouse + message: | + Running Lighthouse audit... + + - name: Check out + uses: actions/checkout@v3.5.3 + + - name: Set up Node.js + uses: actions/setup-node@v3.6.0 + with: + node-version: 18 + + - name: Install Dependencies + run: yarn global add @unlighthouse/cli puppeteer + + - name: vercel-preview-url + uses: zentered/vercel-preview-url@v1.1.9 + id: vercel_preview_url + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + with: + vercel_project_id: ${{ vars.VERCEL_PROJECT_ID }} + + - uses: UnlyEd/github-action-await-vercel@v1.2.39 + id: await-vercel + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + with: + deployment-url: ${{ steps.vercel_preview_url.outputs.preview_url }} + timeout: 30 + poll-interval: 1 + + - name: Build Unlighthouse report + run: | + unlighthouse-ci \ + --site "${{ steps.vercel_preview_url.outputs.preview_url }}" \ + --build-static \ + --router-prefix "${{ github.event.repository.name }}/${{ env.BRANCH_NAME }}" + + - name: Deploy report to GitHub pages + uses: peaceiris/actions-gh-pages@v3.9.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./.unlighthouse + destination_dir: ${{ env.BRANCH_NAME }} + + - name: Format lighthouse score + id: format_lighthouse_score + uses: actions/github-script@v6.4.1 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const fs = require('fs'); + + const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8')); + + const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'; + + const reportUrl = `https://${process.env.GITHUB_REPOSITORY_OWNER}.github.io/${process.env.GITHUB_EVENT.repository.name}/${process.env.BRANCH_NAME}`; + + const comment = [ + `⚡️ Lighthouse report for the changes in this PR:`, + '| Category | Score |', + '| --- | --- |', + `| Performance | ${score(result.summary.categories.performance.averageScore * 100)} |`, + `| Accessibility | ${score(result.summary.categories.accessibility.averageScore * 100)} |`, + `| Best practices | ${score(result.summary.categories['best-practices'].averageScore * 100)} |`, + `| SEO | ${score(result.summary.categories.seo.averageScore * 100)} |`, + ' ', + '*Lighthouse scores for individual routes:*', + '', + '| Path | Performance | Accessibility | Best practices | SEO |', + '| --- | --- | --- | --- | --- |', + `${result.routes.map(route => `| ${route.path} | ${score(route.categories.performance.score * 100)} | ${score(route.categories.accessibility.score * 100)} | ${score(route.categories['best-practices'].score * 100)} | ${score(route.categories.seo.score * 100)} |`).join('\n')}`, + ' ', + '*Lighthouse metrics:*', + '', + '| Metric | Average Value |', + '| --- | --- |', + `${Object.entries(result.summary.metrics).map(([metric, { averageNumericValue }]) => `| ${metric} | ${averageNumericValue} |`).join('\n')}`, + ' ', + `View the full Lighthouse report [here](${reportUrl}).`, + ' ', + 'Learn more about the Lighthouse metrics:', + '- [Largest Contentful Paint](https://web.dev/lighthouse-largest-contentful-paint/)', + '- [Cumulative Layout Shift](https://web.dev/cls/)', + '- [First Contentful Paint](https://web.dev/first-contentful-paint/)', + '- [Total Blocking Time](https://web.dev/lighthouse-total-blocking-time/)', + '- [Max Potential First Input Delay](https://web.dev/lighthouse-max-potential-fid/)', + '- [Time to Interactive](https://web.dev/interactive/)', + ].join('\n'); + + core.setOutput("comment", comment); + + - name: Sticky Comment on Pull Request with result + uses: marocchino/sticky-pull-request-comment@v2.6.2 + with: + header: unlighthouse + message: | + ${{ steps.format_lighthouse_score.outputs.comment }} diff --git a/.github/workflows/seo-reports.yaml b/.github/workflows/seo-reports.yaml deleted file mode 100644 index 95862f8..0000000 --- a/.github/workflows/seo-reports.yaml +++ /dev/null @@ -1,118 +0,0 @@ -name: Unlighthouse SEO Reports - -on: - deployment_status - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - build-deploy: - - if: github.event.deployment_status.state == 'success' && (github.event.deployment_status.environment == 'Production' || github.event.deployment_status.environment == 'Preview') - - environment: - name: github-pages - url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }} - - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 20 - - - name: Install Dependencies - run: yarn global add @unlighthouse/cli puppeteer - - - name: Get Deployment Source Branch Name - id: git-branch - run: | - git fetch --all - git branch -a --contains ${{ github.event.deployment.ref }} - source_branches="$(git branch -a --contains ${{ github.event.deployment.ref }})" - result=$(echo "$source_branches" | tail -n1 | sed 's/^[ \t]*//') - echo "Remote source of deployment: ${result}" - echo "Local git ref of deployment: ${result#remotes/origin/*}" - echo "SOURCE_REF=${result#remotes/origin/*}" >> "$GITHUB_OUTPUT" - - - name: Build Unlighthouse report - run: | - unlighthouse-ci \ - --site "${{ github.event.deployment_status.target_url }}" \ - --build-static \ - --router-prefix "${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }}" - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.GH_PAGES_DEPLOY_PRIVATE_KEY }} - publish_dir: ./.unlighthouse - destination_dir: ${{ steps.git-branch.outputs.SOURCE_REF }} - - - name: Calculate Average Score - id: calculate-score - run: | - average=$(jq -r '[.[] | .score] | add / length' ./.unlighthouse/ci-result.json) - echo "average_score=${average}" >> "$GITHUB_OUTPUT" - - - name: Create Markdown Table - id: create-table - env: - md_file_path: './.unlighthouse/table.md' - run: | - echo "## Unlighthouse Results" > $md_file_path - echo "" >> $md_file_path - echo "Overall score: **${{ steps.calculate-score.outputs.average_score }}**" >> $md_file_path - echo "" >> $md_file_path - echo "Path | Score" >> $md_file_path - echo "-----|------" >> $md_file_path - cat ./.unlighthouse/ci-result.json | jq -r '.[] | [.path, .score] | @tsv' | sed 's/\t/ | /g' >> $md_file_path - echo "" >> $md_file_path - echo "[View the full report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ steps.git-branch.outputs.SOURCE_REF }})" >> $md_file_path - echo "md_file_path=${md_file_path}" >> "$GITHUB_OUTPUT" - - - run: | - echo GITHUB_ACTION: $GITHUB_ACTION - echo GITHUB_WORKFLOW: $GITHUB_WORKFLOW - echo GITHUB_EVENT_NAME: $GITHUB_EVENT_NAME - echo GITHUB_EVENT_PATH: $GITHUB_EVENT_PATH - cat $GITHUB_EVENT_PATH - - - name: Comment on Pull Request - uses: actions/github-script@v6 - with: - script: | - const fs = require('fs'); - const tablePath = fs.readFileSync('${{ steps.create-table.outputs.md_file_path }}', 'utf8'); - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: tablePath - }); - - - name: Comment on issue - id: create_comment - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GH_PAGES_TOKEN}} - script: | - const fs = require('fs'); - const tablePath = fs.readFileSync('${{ steps.create-table.outputs.table_path }}', 'utf8'); - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: tablePath - }) From d79207285a9c93db49c9984933e5ece479954f57 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 19:58:14 +0200 Subject: [PATCH 36/38] fix: Remove polling variable, resolved URL issue --- .github/workflows/lighthouse-report.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lighthouse-report.yaml b/.github/workflows/lighthouse-report.yaml index 262ee56..50872b1 100644 --- a/.github/workflows/lighthouse-report.yaml +++ b/.github/workflows/lighthouse-report.yaml @@ -55,7 +55,6 @@ jobs: with: deployment-url: ${{ steps.vercel_preview_url.outputs.preview_url }} timeout: 30 - poll-interval: 1 - name: Build Unlighthouse report run: | @@ -83,7 +82,7 @@ jobs: const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'; - const reportUrl = `https://${process.env.GITHUB_REPOSITORY_OWNER}.github.io/${process.env.GITHUB_EVENT.repository.name}/${process.env.BRANCH_NAME}`; + const reportUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.BRANCH_NAME }}`; const comment = [ `⚡️ Lighthouse report for the changes in this PR:`, From 74c7e063d4bb3b23b924a21322d63fe0dcb34aa4 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 20:26:37 +0200 Subject: [PATCH 37/38] fix: Added `jsonExpanded` reporter --- .github/workflows/lighthouse-report.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lighthouse-report.yaml b/.github/workflows/lighthouse-report.yaml index 50872b1..d7c6152 100644 --- a/.github/workflows/lighthouse-report.yaml +++ b/.github/workflows/lighthouse-report.yaml @@ -59,9 +59,10 @@ jobs: - name: Build Unlighthouse report run: | unlighthouse-ci \ + --router-prefix "${{ github.event.repository.name }}/${{ env.BRANCH_NAME }}" \ --site "${{ steps.vercel_preview_url.outputs.preview_url }}" \ - --build-static \ - --router-prefix "${{ github.event.repository.name }}/${{ env.BRANCH_NAME }}" + --reporter jsonExpanded \ + --build-static - name: Deploy report to GitHub pages uses: peaceiris/actions-gh-pages@v3.9.3 From bd62b4abcc34dba485e647cb2f4e3e1f8fc1700a Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sun, 11 Jun 2023 20:32:45 +0200 Subject: [PATCH 38/38] feat: Improved comment with actual scores --- .github/workflows/lighthouse-report.yaml | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lighthouse-report.yaml b/.github/workflows/lighthouse-report.yaml index d7c6152..2427a0a 100644 --- a/.github/workflows/lighthouse-report.yaml +++ b/.github/workflows/lighthouse-report.yaml @@ -14,7 +14,7 @@ concurrency: cancel-in-progress: false jobs: - build-deploy: + unlighthouse: environment: name: github-pages url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.BRANCH_NAME }} @@ -81,7 +81,10 @@ jobs: const result = JSON.parse(fs.readFileSync('.unlighthouse/ci-result.json', 'utf8')); - const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'; + const formatScore = score => `${Math.round(score * 100)} (${score})`; + const getEmoji = score => score >= 0.9 ? '🟢' : score >= 0.5 ? '🟠' : '🔴'; + + const score = res => `${getEmoji(res)} ${formatScore(res)}`; const reportUrl = `https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.BRANCH_NAME }}`; @@ -89,25 +92,25 @@ jobs: `⚡️ Lighthouse report for the changes in this PR:`, '| Category | Score |', '| --- | --- |', - `| Performance | ${score(result.summary.categories.performance.averageScore * 100)} |`, - `| Accessibility | ${score(result.summary.categories.accessibility.averageScore * 100)} |`, - `| Best practices | ${score(result.summary.categories['best-practices'].averageScore * 100)} |`, - `| SEO | ${score(result.summary.categories.seo.averageScore * 100)} |`, - ' ', + `| Performance | ${score(result.summary.categories.performance.averageScore)} |`, + `| Accessibility | ${score(result.summary.categories.accessibility.averageScore)} |`, + `| Best practices | ${score(result.summary.categories['best-practices'].averageScore)} |`, + `| SEO | ${score(result.summary.categories.seo.averageScore)} |`, + '', '*Lighthouse scores for individual routes:*', '', '| Path | Performance | Accessibility | Best practices | SEO |', '| --- | --- | --- | --- | --- |', - `${result.routes.map(route => `| ${route.path} | ${score(route.categories.performance.score * 100)} | ${score(route.categories.accessibility.score * 100)} | ${score(route.categories['best-practices'].score * 100)} | ${score(route.categories.seo.score * 100)} |`).join('\n')}`, - ' ', + `${result.routes.map(route => `| ${route.path} | ${score(route.categories.performance.score)} | ${score(route.categories.accessibility.score)} | ${score(route.categories['best-practices'].score)} | ${score(route.categories.seo.score)} |`).join('\n')}`, + '', '*Lighthouse metrics:*', '', '| Metric | Average Value |', '| --- | --- |', `${Object.entries(result.summary.metrics).map(([metric, { averageNumericValue }]) => `| ${metric} | ${averageNumericValue} |`).join('\n')}`, - ' ', + '', `View the full Lighthouse report [here](${reportUrl}).`, - ' ', + '', 'Learn more about the Lighthouse metrics:', '- [Largest Contentful Paint](https://web.dev/lighthouse-largest-contentful-paint/)', '- [Cumulative Layout Shift](https://web.dev/cls/)',