name: Deploy to GitHub Pages

on:
  workflow_run:
    workflows: ["<%= deployWorkflowName %>"]
    types:
      - completed
  # Allows you to run this workflow manually from the Actions tab on GitHub.
  workflow_dispatch:

jobs:
    psi-insights:
        env:
            RESULTS_DIR: <%= outputDir %>
        runs-on: ubuntu-latest
        steps:
        - name: Checkout your repository using git
          uses: actions/checkout@v4
        - name: Setup bun
          uses: oven-sh/setup-bun@v2
        - name: Run psi-svg
          run: | # Have to be sure a folder is present if not, make it
            mkdir -p ${RESULTS_DIR}
            bunx psi-svg <%- deployedPageUrl %> $RESULTS_DIR/desktop.svg -s=desktop --categories=performance,accessibility,best-practices,seo
            bunx psi-svg <%- deployedPageUrl %> $RESULTS_DIR/mobile.svg -s=mobile --categories=performance,accessibility,best-practices,seo
        - name: Commit updated PageSpeed Insights SVGs
          run: |
            git add .
            git config --local user.email "actions@github.com"
            git config --local user.name "github-actions[bot]"
            git diff --quiet && git diff --staged --quiet || git commit -am "chore(docs): update PageSpeed Insights SVGs [skip ci]"
            git pull --rebase
            git push
