From d5036836b702c4d45333f5590c791a48b3e778e3 Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Wed, 13 Sep 2023 11:31:59 -0400 Subject: [PATCH] Unlighthouse --- .github/actions/unlighthouse/action.yml | 72 +++++++++++++++++++ .../examples/dryrun-production.yml | 0 .../examples/dryrun-staging.yml | 0 .../examples/eject-production.yml | 0 .../examples/sage10-build-test.yml | 0 .github/workflows/unlighthouse-production.yml | 36 ++++++++++ 6 files changed, 108 insertions(+) create mode 100644 .github/actions/unlighthouse/action.yml rename .github/{ => workflows}/examples/dryrun-production.yml (100%) rename .github/{ => workflows}/examples/dryrun-staging.yml (100%) rename .github/{ => workflows}/examples/eject-production.yml (100%) rename .github/{ => workflows}/examples/sage10-build-test.yml (100%) create mode 100644 .github/workflows/unlighthouse-production.yml diff --git a/.github/actions/unlighthouse/action.yml b/.github/actions/unlighthouse/action.yml new file mode 100644 index 0000000..418310c --- /dev/null +++ b/.github/actions/unlighthouse/action.yml @@ -0,0 +1,72 @@ +name: '⛵ Audit a Trellis site with Unlighthouse' +description: 'Audits a Trellis site with Unlighthouse and publishes the result to GitHub Pages' + +inputs: + + environment: + description: 'The environment to audit' + required: true + + trellis_deploy_ssh_private_key: + description: 'The SSH private key to use for deployment' + required: true + + trellis_deploy_ssh_known_hosts: + description: 'The SSH known hosts to use for deployment' + required: true + + github_token: + description: 'The GitHub token to use' + required: true + +runs: + using: 'composite' + steps: + + # Set up known hosts + - uses: shimataro/ssh-key-action@v2 + with: + key: ${{ inputs.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }} + known_hosts: ${{ inputs.TRELLIS_DEPLOY_SSH_KNOWN_HOSTS }} + + # Set up SSH agent + - uses: webfactory/ssh-agent@v0.8.0 + with: + ssh-private-key: ${{ inputs.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }} + + # install WP-CLI + - name: Setup WP-CLI + uses: godaddy-wordpress/setup-wp-cli@1 + + # Use WP CLI to get the site URL from the deployed site + - name: Get site URL + shell: bash + working-directory: site + id: site_url + run: | + echo "url=$(wp @"${{ inputs.environment }}" option get home)" >> $GITHUB_OUTPUT + + # Install Unlighthouse and dependencies + - name: Install Dependencies + shell: bash + run: npm install -g @unlighthouse/cli puppeteer + + # Run Unlighthouse on the URL from the previous step + - name: Unlighthouse assertions and client + shell: bash + run: unlighthouse-ci --site ${{ steps.site_url.outputs.url }} --budget 75 --build-static --routerPrefix "example.com" + + # Publish the resulting .unlighthouse directory to GitHub Pages + - name: Publish Unlighthouse results + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ inputs.github_token }} + publish_dir: .unlighthouse + publish_branch: gh-pages + publish_dir_prefix: ${{ inputs.environment }} + enable_jekyll: false + commit_message: 'Unlighthouse results for ${{ inputs.environment }}' + force_orphan: true + keep_files: true + clean: true + allow_empty_commit: true diff --git a/.github/examples/dryrun-production.yml b/.github/workflows/examples/dryrun-production.yml similarity index 100% rename from .github/examples/dryrun-production.yml rename to .github/workflows/examples/dryrun-production.yml diff --git a/.github/examples/dryrun-staging.yml b/.github/workflows/examples/dryrun-staging.yml similarity index 100% rename from .github/examples/dryrun-staging.yml rename to .github/workflows/examples/dryrun-staging.yml diff --git a/.github/examples/eject-production.yml b/.github/workflows/examples/eject-production.yml similarity index 100% rename from .github/examples/eject-production.yml rename to .github/workflows/examples/eject-production.yml diff --git a/.github/examples/sage10-build-test.yml b/.github/workflows/examples/sage10-build-test.yml similarity index 100% rename from .github/examples/sage10-build-test.yml rename to .github/workflows/examples/sage10-build-test.yml diff --git a/.github/workflows/unlighthouse-production.yml b/.github/workflows/unlighthouse-production.yml new file mode 100644 index 0000000..2a71b66 --- /dev/null +++ b/.github/workflows/unlighthouse-production.yml @@ -0,0 +1,36 @@ +# .github/workflows/unlighthouse.yml +## +# Run an Unlighthouse audit on a Trellis environment +# +# This workflow will run an Unlighthouse audit on a Trellis environment set in the +# workflow's environment variables. The audit will be run on the environment's production +# URL and published to GitHub Pages. +## + +name: ⛵ Unlighthouse Audit Production +run-name: unlighthouse-audit-production + +on: + workflow_dispatch: + +env: + environment: production + +jobs: + unlighthouse: + name: Unlighthouse Audit + runs-on: ubuntu-latest + steps: + # Checkout the repo + - uses: actions/checkout@v3 + with: + ref: main + + # Run the Unlighthouse audit + - uses: ./.github/actions/unlighthouse + name: Audit with Unlighthouse + with: + environment: ${{ env.environment }} + github_token: ${{ secrets.GITHUB_TOKEN }} + trellis_deploy_ssh_private_key: ${{ secrets.TRELLIS_DEPLOY_SSH_PRIVATE_KEY }} + trellis_deploy_ssh_known_hosts: ${{ secrets.TRELLIS_DEPLOY_SSH_KNOWN_HOSTS }}