Skip to content

Commit

Permalink
feat: add a continuous integration pipeline (strimzi#45)
Browse files Browse the repository at this point in the history
* feat: add a continuous integration pipeline

Includes:
 - Run build
 - Run unit and e2e tests
 - Deploy storybook to github pages on merge to master
 - Create bundle size report (as a comment on PR)
 - Create test coverage report (as a comment on PR)
 - Upload storybook artifact on PR
 - Lint commit messages
 - Lint all code
 - Mark stale issues and remove dead ones

Signed-off-by: Jordan <[email protected]>

* chore: update workflows to use node 14

Signed-off-by: Jordan <[email protected]>
  • Loading branch information
Jordan Tucker authored Oct 27, 2020
1 parent db2cc95 commit 0a710e5
Show file tree
Hide file tree
Showing 25 changed files with 1,711 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .github/actions/bundle/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Strimzi authors.
# License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
FROM node:slim

COPY index.js .
COPY package.json .
COPY package-lock.json .

RUN npm install

ENTRYPOINT ["node", "/index.js"];
15 changes: 15 additions & 0 deletions .github/actions/bundle/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright Strimzi authors.
# License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
name: "Bundle size"
description: "Check the size of the bundle"
inputs:
MASTER_REPORT:
description: "Bundle report from master branch"
outputs:
bundle_report:
description: "Markdown representation of bundle sizes"
overall_bundle_size_change:
description: "Overall percentage change of bundle sizes between master and current"
runs:
using: "docker"
image: "Dockerfile"
73 changes: 73 additions & 0 deletions .github/actions/bundle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright Strimzi authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
const core = require("@actions/core");
const fs = require("fs");

const BUNDLE_LABELS = {
'main.bundle.js': "Strimzi UI JS Bundle",
};
const TABLE_HEADINGS = ['Bundle', 'New Size', 'Original Size', 'Increase/Decrese', 'File'];

const round = (value) => Math.round(value * 100) / 100;

const getReports = () => {
let masterReport = JSON.parse(core.getInput('MASTER_REPORT'));
const currentReport = JSON.parse(fs.readFileSync('./generated/bundle-analyser/report.json'));
return {masterReport, currentReport};
};

const initBundleSizeObject = (masterReport) => {
let bundleSizes = Object.keys(BUNDLE_LABELS).reduce((sizes, file) => {
sizes[file] = {master: 0, current: 0};
return sizes;
}, {});
masterReport.forEach(bundle => {bundleSizes[bundle.label] = {master: bundle.parsedSize, current: null};});
return bundleSizes;
};

const createTableHeader = (tableHeadings) => {
return `|${tableHeadings.join('|')}|\n${tableHeadings.reduce(text => text + '---|', '|')}\n`;
};

const createBundleReportTable = (bundleReport, bundleSizes) => bundleReport.reduce((previousbundleText, bundle) => {
bundleSizes[bundle.label].current = bundle.parsedSize;
const currentSizeBytes = bundleSizes[bundle.label].current;
const masterSizeBytes = bundleSizes[bundle.label].master;

const currentSize = round(currentSizeBytes / 1024);
const masterSize = round(masterSizeBytes / 1024);
const bundleLabel = BUNDLE_LABELS[bundle.label] || bundle.label;
const sizeDiff = round(currentSizeBytes / masterSizeBytes) - 1;
const sizeDiffText = `${round(sizeDiff * 100)}%`;

return `${previousbundleText} |${bundleLabel}|${currentSize}KB|${masterSize}KB|${sizeDiffText}|${bundle.label}|\n`;
}, createTableHeader(TABLE_HEADINGS));

const calculateOverallChange = (bundleSizes) => {
const sizes = Object.values(bundleSizes).reduce(({totalMasterSize, totalCurrentSize}, bundleSize) => {
return {
totalMasterSize: totalMasterSize + bundleSize.master,
totalCurrentSize: totalCurrentSize + bundleSize.current
};
}, {totalMasterSize: 0, totalCurrentSize: 0});

return `${round(((sizes.totalCurrentSize / sizes.totalMasterSize) - 1) * 100)}%`;
};

async function buildBundleReport() {
try {
const {masterReport, currentReport} = getReports();
const bundleSizes = initBundleSizeObject(masterReport);
const bundleReportTable = createBundleReportTable(currentReport, bundleSizes);
const overallBundleSizeChange = calculateOverallChange(bundleSizes);

core.setOutput('bundle_report', bundleReportTable);
core.setOutput('overall_bundle_size_change', overallBundleSizeChange);
} catch (error) {
core.setFailed(error.message);
}
}

buildBundleReport();
Loading

0 comments on commit 0a710e5

Please sign in to comment.