name: Unlighthouse SEO Reports

on:
  [deployment_status]

jobs:
  build:
    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: Upload GitHub Pages artifact
        uses: actions/upload-pages-artifact@v1.0.8
        with:
          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