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

feat(size-report): add proper size report check #2638

Merged
merged 46 commits into from Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
54fe6df
feat(size-report): start doug off
redallen Jan 29, 2020
eac7158
add patternfly.css and conditionally fail
redallen Jan 29, 2020
804ef21
always run all linting tasks in CI
redallen Jan 29, 2020
21b5226
chore(fix): initial css size report
ddonahue007 Jan 30, 2020
2feed01
chore(fix): refactor a bit
ddonahue007 Jan 31, 2020
b9a792c
chore(fix): css size chart
ddonahue007 Jan 31, 2020
ced89dd
chore(fix): css size chart
ddonahue007 Jan 31, 2020
0f02e38
chore(fix): css size chart
ddonahue007 Jan 31, 2020
3fc649e
chore(fix): css size chart
ddonahue007 Jan 31, 2020
e1baffc
chore(fix): css size chart
ddonahue007 Feb 5, 2020
0f2c587
chore(fix): css size chart
ddonahue007 Feb 5, 2020
75c1abc
Merge remote-tracking branch 'upstream/master' into feat/size-report
redallen Feb 5, 2020
32dd1da
chore(fix): css size chart
ddonahue007 Feb 5, 2020
ffef2cc
chore(fix): css size chart
ddonahue007 Feb 5, 2020
ad09d69
chore(fix): css size chart
ddonahue007 Feb 5, 2020
5f19eed
chore(fix): css size chart
ddonahue007 Feb 5, 2020
bc87625
chore(fix): css size chart
ddonahue007 Feb 5, 2020
681fb33
chore(fix): css size chart
ddonahue007 Feb 5, 2020
5b474a4
chore(fix): css size chart
ddonahue007 Feb 5, 2020
2983a98
chore(fix): css size chart
ddonahue007 Feb 6, 2020
eb83cb5
chore(fix): css size chart
ddonahue007 Feb 6, 2020
54912dd
chore(fix): css size chart
ddonahue007 Feb 6, 2020
b9733ac
chore(fix): css size chart
ddonahue007 Feb 6, 2020
e34b19a
chore(fix): css size chart
ddonahue007 Feb 6, 2020
d4d2516
chore(fix): css size chart
ddonahue007 Feb 6, 2020
e8fed57
chore(fix): css size chart
ddonahue007 Feb 6, 2020
387b3e5
chore(fix): css size chart
ddonahue007 Feb 6, 2020
1e24182
chore(fix): css size chart
ddonahue007 Feb 7, 2020
4aea866
chore(fix): css size chart
ddonahue007 Feb 7, 2020
8cc8484
chore(fix): css size chart
ddonahue007 Feb 7, 2020
ea19d81
chore(fix): css size chart
ddonahue007 Feb 7, 2020
28ec576
chore(fix): css size chart
ddonahue007 Feb 8, 2020
3f78153
chore(fix): css size chart
ddonahue007 Feb 8, 2020
c8a89d6
chore(fix): css size chart
ddonahue007 Feb 8, 2020
fe9cc8a
chore(fix): css size chart
ddonahue007 Feb 8, 2020
33a8e38
chore(fix): css size chart
ddonahue007 Feb 10, 2020
1a587c3
chore(fix): css size chart
ddonahue007 Feb 10, 2020
7663194
fix(async): nightmare
redallen Feb 10, 2020
94441eb
chore(fix): css size chart
ddonahue007 Feb 10, 2020
1f7a32e
chore(fix): css size chart
ddonahue007 Feb 11, 2020
4618441
checkout last tagged version in git log
redallen Feb 11, 2020
0da0c40
feat(stupid): duplicate flex
redallen Feb 11, 2020
1ffdc6b
chore(css): add upload preview script
redallen Feb 11, 2020
a55f5d0
fix workflow
redallen Feb 11, 2020
dae297f
revert flex, bad exit code if too big
redallen Feb 11, 2020
d08e963
remove unused code
redallen Feb 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions .circleci/config.yml
Expand Up @@ -12,6 +12,12 @@ references:
- src/icons/PfIcons/
js_deps_cache_key: &js_deps_cache_key
js-deps-v{{.Environment.CACHE_VERSION}}-{{checksum "package-lock.json"}}
size_report_paths: &size_report_paths
redallen marked this conversation as resolved.
Show resolved Hide resolved
- dist/size-report.json
size_report_cache_key: &size_report_cache_key
size-report-v{{.Environment.CACHE_VERSION}}-{{ .Branch }}
size_report_master_cache_key: &size_report_master_cache_key
size-report-v{{.Environment.CACHE_VERSION}}-master
attach_workspace: &attach_workspace
attach_workspace:
at: ~/project
Expand Down Expand Up @@ -108,12 +114,24 @@ jobs:
- run:
name: Lint JS
command: npm run lint:js
- run:
name: Lint CSS Size
command: npm run lint:size
when: always
- run:
name: Lint CSS
command: npm run lint:css
when: always
- restore_cache:
redallen marked this conversation as resolved.
Show resolved Hide resolved
keys:
- *size_report_master_cache_key
- run:
name: Lint CSS Size
command: .circleci/css-size-report/css-size-report.sh
when: always
- persist_to_workspace:
root: ~/project
paths: *size_report_paths
- save_cache:
redallen marked this conversation as resolved.
Show resolved Hide resolved
paths: *size_report_paths
key: *size_report_cache_key
deploy:
docker:
- image: circleci/node:10
Expand Down
51 changes: 51 additions & 0 deletions .circleci/css-size-report/css-size-report.sh
@@ -0,0 +1,51 @@
#!/bin/bash

# A simple script that will check to see if the previous patternfly has been installed to .circleci/css-size-report/nodemodules.
# this installtion is used to calculate size changes in css files..

cd $(dirname $0)

# log levels
INFO="INFO"
WARN="WARNING"
ERR="ERROR"

logMsg() {
local _msg=${1}
echo "${INFO}: ${_msg}"
}

logErr() {
local _msg=${1}
echo "${ERR}: ${_msg}"
}

setup() {
if [ ! -d "./node_modules/@patternfly/patternfly" ]; then
logMsg "setup previous version of patternfly for css comparisons"

if npm i -D @patternfly/patternfly; then
logMsg "setup ran successfully"
else
logErr "setup failed"
exit 1
fi

else
logMsg "setup already done"
fi
}

run() {
logMsg "generating css report differences"
if node sizeReport.js; then
logMsg "report ran successfully"
else
logErr "report failed"
exit 1
fi
}

## execute
setup
run
14 changes: 14 additions & 0 deletions .circleci/css-size-report/package-lock.json

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

15 changes: 15 additions & 0 deletions .circleci/css-size-report/package.json
@@ -0,0 +1,15 @@
{
"name": "tmp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "",
"devDependencies": {
"@patternfly/patternfly": "^2.56.3"
}
}
118 changes: 118 additions & 0 deletions .circleci/css-size-report/sizeReport.js
@@ -0,0 +1,118 @@
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const Octokit = require('@octokit/rest');

const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });

const owner = process.env.CIRCLE_PROJECT_USERNAME; // patternfly
const repo = process.env.CIRCLE_PROJECT_REPONAME;
const prnum = process.env.CIRCLE_PR_NUMBER;

const exitCode = 0;
const results = {};
// size of the previous version cee file being tested
let prevResult;
// percentage difference of css files
let diff;
// the number of files that have changed
let totalFiles = 0;
// the color of the result size value.
let sizeCol = 'green';

let html = '<table>';
html += '<tr>';
html += `<td>Name</td>`;
html += `<td>Current(kb)</td>`;
html += `<td>Previous(kb)</td>`;
html += `<td>Diff %</td>`;
html += '</tr>';

// @todo add: 'dist/patternfly.css', 'dist/patternfly.min.css'
redallen marked this conversation as resolved.
Show resolved Hide resolved
glob
.sync('../../dist/components/**/*.css')
redallen marked this conversation as resolved.
Show resolved Hide resolved
// .filter(file => prevResults[file])
.map(file => ({ file, size: fs.statSync(file).size }))
// .sort(by size)
.forEach(({ file, size }) => {
if (size >= 10000) {
sizeCol = '#E74C3C';
} else if (size > 8000 && size < 10000) {
sizeCol = '#F1C40F';
} else {
sizeCol = '#229954';
}
prevResult = glob
redallen marked this conversation as resolved.
Show resolved Hide resolved
.sync(`node_modules/@patternfly/patternfly/**/${path.basename(file)}`)
.map(file => ({ file, size: fs.statSync(file).size }.size));

diff = size !== 0 ? Math.abs(((size - prevResult) / size) * 100).toPrecision(2) : 0;

if ( parseFloat(diff) !== parseFloat('0') ) {
totalFiles++;
html += '<tr>';
html += `<td>${path.basename(file)}</td>`; // Name
html += `<td><font color=${sizeCol}>${size}</font></td>`; // Current
html += `<td>${prevResult}</td>`; // Previous
if (diff > 0) {
html += `<td><font color='#E74C3C'>${diff}</font></td>`;
} else if (diff < 0) {
html += `<td><font color='#229954'>${diff}</font></td>`;
} else {
html += `<td>${diff}</td>`;
}
html += '<tr>';
results[file] = size;
}
});

if ( totalFiles == 0) {
html += '<tr>';
html += `<td colspan="4">There are no changes in CSS file sizes</td>`
html += '<tr>';
}

html += '</table>';
console.log(html);

if (prnum) {
octokit.issues
.listComments({
owner,
repo,
issue_number: prnum
})
.then(res => res.data)
.then(comments => {
let commentBody = '';
const existingComment = comments.find(comment => comment.user.login === 'patternfly-build');
if (existingComment) {
commentBody += existingComment.body;
}

commentBody += '\n';
commentBody += html;

if (existingComment) {
octokit.issues
.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody
})
.then(() => console.log('Updated comment!'));
} else {
octokit.issues
.createComment({
owner,
repo,
issue_number: prnum,
body: commentBody
})
.then(() => console.log('Created comment!'));
}
});
}

process.exit(exitCode);
26 changes: 1 addition & 25 deletions gulpfile.js
Expand Up @@ -301,29 +301,6 @@ function lintCSSComments() {
});
}

function lintCSSSize(cb) {
const patternflyPath = path.resolve(__dirname, './dist/patternfly.css');
const patternflyMinPath = path.resolve(__dirname, './dist/patternfly.min.css');

const patternflySize = fs.statSync(patternflyPath).size;
const patternflyMinSize = fs.statSync(patternflyMinPath).size;
const errors = [];
// At time of writing is 609013
console.log(`patternfly.css is ${patternflySize / 1000}KB`);
if (patternflySize > 650000) {
errors.push(`patternfly.css is ${patternflySize / 1000}KB > 650KB`);
}
// At time of writing is 532807
console.log(`patternfly.min.css is ${patternflyMinSize / 1000}KB`);
if (patternflyMinSize > 600000) {
errors.push(`patternfly.min.css is ${patternflyMinSize / 1000}KB > 600KB`);
}
if (errors.length > 0) {
cb(errors.join('\n'));
}
cb();
}

module.exports = {
build: series(clean, compileSASS, minifyCSS, pfIcons, copyFA, copySource),
compileSASS,
Expand All @@ -338,6 +315,5 @@ module.exports = {
copyAssets,
lintCSSFunctions,
lintCSSComments,
lintCSSSize,
lintCSS: parallel(lintCSSFunctions, lintCSSComments, lintCSSSize)
lintCSS: parallel(lintCSSFunctions, lintCSSComments)
};