Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlighthouse #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/actions/unlighthouse/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
36 changes: 36 additions & 0 deletions .github/workflows/unlighthouse-production.yml
Original file line number Diff line number Diff line change
@@ -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 }}