Skip to content

Commit 4350889

Browse files
test(presubmit): build a staging version of site to speed up HTML and CSS transforms (GoogleChrome#6257)
* test(presubmit): build a staging version of site to speed up HTML and CSS transforms * fix(staging): build rss feeds in staging * docs(presubmit): correct name of step
1 parent 14e9ecd commit 4350889

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.github/workflows/presubmit-workflow.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
github_token: ${{ secrets.GITHUB_TOKEN }}
2424
is_presubmit: ${{ contains(github.event.pull_request.labels.*.name, '$-presubmit') }}
2525

26-
- name: Run a production build of site
26+
- name: Run a staging build of site
2727
run: npm run build
2828
env:
29-
ELEVENTY_ENV: prod
29+
ELEVENTY_ENV: staging
3030

3131
# Checks to see if any files in the PR match one of the listed file types.
3232
# We can use this filter to decide whether or not to run linters or tests.

src/site/_collections/hooks/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const filterByLang = require('../../_filters/filter-by-lang');
2929
const feed = (items) => {
3030
const filteredFeed = [];
3131

32-
if (process.env.ELEVENTY_ENV !== 'prod') {
32+
if (!['prod', 'staging'].includes(process.env.ELEVENTY_ENV)) {
3333
return filteredFeed;
3434
}
3535

src/site/_transforms/minify-html.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@
1515
*/
1616

1717
const minify = require('html-minifier').minify;
18+
const path = require('path');
19+
const {URL} = require('url');
20+
const stagingUrls =
21+
require('../../../tools/lhci/lighthouserc').ci.collect.url.map((url) =>
22+
path.join('dist', new URL(url).pathname, 'index.html'),
23+
);
24+
25+
const isProd = process.env.ELEVENTY_ENV === 'prod';
26+
const isStaging = process.env.ELEVENTY_ENV === 'staging';
1827

1928
const minifyHtml = (content, outputPath) => {
20-
if (outputPath && outputPath.endsWith('.html')) {
29+
if (
30+
(isProd && outputPath && outputPath.endsWith('.html')) ||
31+
(isStaging && stagingUrls.includes(outputPath))
32+
) {
2133
try {
2234
content = minify(content, {
2335
removeAttributeQuotes: true,

src/site/_transforms/purify-css.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ const fs = require('fs');
1818
/* eslint-disable node/no-unpublished-require */
1919
const PurgeCSS = require('purgecss').PurgeCSS;
2020
const csso = require('csso');
21+
const path = require('path');
22+
const {URL} = require('url');
23+
const stagingUrls =
24+
require('../../../tools/lhci/lighthouserc').ci.collect.url.map((url) =>
25+
path.join('dist', new URL(url).pathname, 'index.html'),
26+
);
2127
const pathToCss = 'dist/css/main.css';
28+
const isProd = process.env.ELEVENTY_ENV === 'prod';
29+
const isStaging = process.env.ELEVENTY_ENV === 'staging';
2230

2331
/**
2432
* Inlines all of the page's CSS into the <head>
2533
*/
2634

2735
const purifyCss = async (content, outputPath) => {
2836
if (
29-
outputPath &&
30-
outputPath.endsWith('.html') &&
31-
!/data-style-override/.test(content)
37+
(isProd &&
38+
outputPath &&
39+
outputPath.endsWith('.html') &&
40+
!/data-style-override/.test(content)) ||
41+
(isStaging && stagingUrls.includes(outputPath))
3242
) {
3343
const before = fs.readFileSync(pathToCss, {
3444
encoding: 'utf-8',

0 commit comments

Comments
 (0)