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

Add frontend performance CI integration #4761

Open
wants to merge 54 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
42e8bf3
Add initial site population
schlessera May 20, 2020
3582fab
Commit initial version to try on GH
schlessera May 22, 2020
46b83c2
Avoid allocating pseudo-TTY within GHA
schlessera May 22, 2020
ed9dc34
Add Composer & npm caching
schlessera May 22, 2020
6b2e72d
Avoid Docker within Docker
schlessera May 23, 2020
ea1332e
Switch from localenv to manual setup in GHA
schlessera May 23, 2020
380bd1f
Manually start the MySQL server
schlessera May 23, 2020
0ea1a1a
Use sudo for installing WP-CLI
schlessera May 23, 2020
c1ff5e5
Use relative path as webroot
schlessera May 23, 2020
26a0f1f
Try different way of starting MySQL service
schlessera May 23, 2020
2e93e18
Use sudo to install npm dependency globally
schlessera May 23, 2020
25b9877
Add PWA plugin
schlessera May 23, 2020
beef80a
Switch site into transitional mode
schlessera May 23, 2020
ebd13ef
Add separate release-zip workflow
schlessera May 23, 2020
61849a7
Combine both jobs into single workflow file
schlessera May 23, 2020
7463025
Fix variable syntax
schlessera May 23, 2020
a18b87b
Extract logic to calculate SHA-8
schlessera May 23, 2020
64d2fee
Directly use generated artifact filename
schlessera May 23, 2020
5ee7bd2
Check into filesystem
schlessera May 23, 2020
dda231a
Use correct filename for plugin installation
schlessera May 23, 2020
edcb980
Add checkout to get lighthouse config
schlessera May 23, 2020
2ac35e7
Omit enforcing assertions
schlessera May 23, 2020
af64586
Use branch name instead of version string
schlessera May 23, 2020
1190f06
Skip assertions
schlessera May 23, 2020
960ea4f
Revert changes to dev env, as they are not used anymore
schlessera May 23, 2020
a5742db
Add lhci upload credentials
schlessera May 27, 2020
3f42ae2
Switch cache back to v1
schlessera May 27, 2020
b22fd8f
Remove indentation from multi-line commands$
schlessera May 27, 2020
9780c22
Default to multi-line run syntax
schlessera May 27, 2020
014b254
Add target to lhci upload
schlessera May 27, 2020
1cfe409
Remove config prefix keys for console arguments
schlessera May 27, 2020
c818bdf
Add missing backslash
schlessera May 27, 2020
360d452
Install and activate the Yoast SEO plugin to fix SEO issues
schlessera Jun 2, 2020
0664996
Fix typo in plugin name
schlessera Jun 2, 2020
ae64db4
Create basic robots.txt file
schlessera Jun 2, 2020
2350f6e
Add URL Toggles plugin and measure variations
schlessera Jun 2, 2020
96ef2b9
Fix PHPCS issues with URL Toggles plugin
schlessera Jun 2, 2020
bee1097
Remove Yoast again and add simple meta description MU plugin
schlessera Jun 2, 2020
b8b4fbc
Fix PHPCS issues with meta description plugin
schlessera Jun 2, 2020
0529f51
Add job name for lighthouse
schlessera Jun 10, 2020
593291e
Adapt path to artifacts
schlessera Jun 10, 2020
f7b3187
Shorten workflow name to avoid truncation in UI
schlessera Jun 10, 2020
0136ab4
Fix path name
schlessera Jun 10, 2020
309c7a1
Adapt lighthouse task to add reference site import
schlessera Jul 20, 2020
a3b620f
Remove duplicate comment
schlessera Jul 20, 2020
10809a5
Add autoload dump
schlessera Jul 20, 2020
2a32d2c
Fully install Composer dependencies
schlessera Jul 20, 2020
cb77df9
Update Composer configuration
schlessera Jul 20, 2020
4bbb0b4
Load reference site logic outside of active plugin
schlessera Jul 20, 2020
0a448eb
Fix ZIP requirement
schlessera Jul 20, 2020
b0d0ab0
Add WordPress Importer plugin as is required for reference site
schlessera Jul 20, 2020
ea9ba86
Fix importer plugin path
schlessera Jul 20, 2020
dc171a6
Add WebP support
schlessera Jul 20, 2020
883c28c
Remove WebP plugin again
schlessera Jul 20, 2020
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
174 changes: 166 additions & 8 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build, test & measure
name: Integrate

on:
push:
Expand All @@ -18,8 +18,8 @@ jobs:
if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
runs-on: ubuntu-latest
outputs:
branch-name: ${{ steps.retrieve-branch-name.outputs.branch_name }}
git-sha-8: ${{ steps.retrieve-git-sha-8.outputs.sha8 }}
branch-name: ${{ steps['retrieve-branch-name'].outputs.branch_name }}
git-sha-8: ${{ steps['retrieve-git-sha-8'].outputs.sha8 }}

steps:
- name: Check out source files
Expand All @@ -33,15 +33,18 @@ jobs:
- name: Configure Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
# Scripts are not ignored as they are needed to apply patches for the
# `sabberworm/php-css-parser` dependency.
run: composer install --prefer-dist --optimize-autoloader
run: |
composer install \
--prefer-dist \
--optimize-autoloader

- name: Get npm cache directory
id: npm-cache
Expand All @@ -51,14 +54,16 @@ jobs:
- name: Configure npm cache
uses: actions/cache@v1
with:
path: ${{ steps.npm-cache.outputs.dir }}
path: ${{ steps['npm-cache'].outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install Node dependencies
# Prevent malicious scripts from being run with `--ignore-scripts`
run: npm install --ignore-scripts
run: |
npm install \
--ignore-scripts

- name: Create destination directories
run: mkdir -p builds/dev
Expand All @@ -74,10 +79,14 @@ jobs:

- name: Retrieve git SHA-8 string
id: retrieve-git-sha-8
run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
run: |
echo "::set-output name=sha8::$(echo ${GITHUB_SHA} \
| cut -c1-8)"

- name: Upload build as artifact
uses: actions/upload-artifact@v2
env:
SHA8: ${GITHUB_SHA::8}
with:
name: amp-${{ steps.retrieve-branch-name.outputs.branch_name }}-${{ steps.retrieve-git-sha-8.outputs.sha8 }}-dev
path: builds/dev
Expand Down Expand Up @@ -237,3 +246,152 @@ jobs:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: ${{ steps.get-comment-body.outputs.body }}

#-----------------------------------------------------------------------------------------------------------------------

lighthouse:
name: Audit and track performance via Lighthouse CI
runs-on: ubuntu-latest
needs: prod-zip

steps:
# Although we have a readily built ZIP of the plugin, we also need the dev
# dependencies that contain the reference site setup code.
- name: Check out source files
uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v1
with:
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
# Scripts are not ignored as they are needed to apply patches for the
# `sabberworm/php-css-parser` dependency.
run: |
composer install

- name: Download prod build
uses: actions/download-artifact@v2
with:
name: amp-${{ needs.prod-zip.outputs.branch-name }}-${{ needs.prod-zip.outputs.git-sha-8 }}-prod
path: builds/prod

- name: Install MySQL client
run: |
sudo apt-get install -y mysql-client

- name: Install WP-CLI
run: |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
sudo chmod +x /usr/local/bin/wp

- name: Install WordPress Core
env:
PORT: ${{ job.services.mysql.ports[3306] }}
run: |
mkdir -p www
echo "path: www/" > wp-cli.local.yml
wp core download \
--force \
--allow-root
wp config create \
--dbname=lighthouse_test \
--dbuser=root \
--dbpass=root \
--dbhost="127.0.0.1:$PORT" \
--force \
--skip-check \
--allow-root

- name: Start MySQL server
run: |
sudo service mysql start

- name: Initialize WordPress database
run: |
wp db create --allow-root
wp core install --title="AMP Dev" \
--admin_user=admin \
--admin_password=password \
[email protected] \
--skip-email \
--url=http://localhost:8080 \
--allow-root

- name: Install and activate the AMP plugin
run: |
wp plugin install builds/prod/amp.zip \
--activate \
--force \
--allow-root

- name: Install and activate the PWA plugin
run: |
wp plugin install pwa \
--activate \
--force \
--allow-root

- name: Install and activate the WordPress Importer plugin
run: |
wp plugin install wordpress-importer \
--activate \
--force \
--allow-root

- name: Install the URL Toggles plugin as a must-use plugin
run: |
mkdir -p www/wp-content/mu-plugins
cp tests/e2e/plugins/url-toggles.php www/wp-content/mu-plugins

- name: Install the Meta Description plugin as a must-use plugin
run: |
cp tests/e2e/plugins/add-meta-description.php www/wp-content/mu-plugins

- name: Create basic robots.txt file
run: |
echo "User-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n" > www/robots.txt

- name: Switch site into Transitional mode
run: |
wp eval \
'AMP_Options_Manager::update_option( AmpProject\AmpWP\Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG );' \
--allow-root

- name: Import "Travel Blog" reference site
run: |
wp --require=tests/php/register-wp-cli-commands.php amp reference-site import travel-blog --allow-root

- name: Install Lighthouse CI
run: |
sudo npm install -g @lhci/cli

- name: Run Lighthouse CI health check
run: |
lhci healthcheck

- name: Run Lighthouse CI audit
run: |
lhci collect

- name: Assert Lighthouse CI measurements against requirements
run: |
echo -n 'Skipping assertions for now'
# lhci assert

- name: Upload Lighthouse CI measurements to Lighthouse CI server
run: |
lhci upload \
--target=lhci \
--serverBaseUrl=${{ secrets.LHCI_SERVER_BASE_URL }} \
--token=${{ secrets.LHCI_BUILD_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ built
.idea/
/lib/*/vendor/
/lib/*/composer.lock
/.lighthouseci
/phpcs.xml
/phpunit.xml
*.sql
41 changes: 41 additions & 0 deletions .lighthouserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
ci: {

// Configure the way data is collected.
collect: {

// List of URLs to run the audit against.
url: [
'http://localhost:8080/',
'http://localhost:8080/?amp=1&amp_optimizer=0&amp_ssr=0',
'http://localhost:8080/?amp=1&amp_optimizer=1&amp_ssr=0',
'http://localhost:8080/?amp=1&amp_optimizer=1&amp_ssr=1',
],

// How many runs to use for averaging out variability.
numberOfRuns: 3,

// Chrome settings that we need for running headless within a Docker container.
settings: {
chromeFlags: '--headless --disable-gpu --no-sandbox --no-zygote'
},

// How to launch a background server to run the audit against.
startServerCommand: "wp server --allow-root & sleep 1 && echo 'web server ready'"
},

// Configure the assertions that are run against the collected data.
assert: {

// Asserts that every audit outside performance received a perfect score, that no resources were flagged for
// performance opportunities, and warns when metric values drop below a score of 90.
preset: 'lighthouse:recommended',
},

// Configure the upload destination.
upload: {

// This is handled via command-line flags in GitHub workflow.
},
},
};
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@
},
"autoload-dev": {
"psr-4": {
"AmpProject\\AmpWP\\Tests\\": "tests/php/src/",
"AmpProject\\AmpWP\\Seed\\": "tests/seeds/"
"AmpProject\\AmpWP\\Tests\\": "tests/php/src/"
},
"classmap": [
"tests/php/validation/"
Expand Down
28 changes: 17 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading