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: Setup bundlesize GH action #1

Open
wants to merge 6 commits into
base: master
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
17 changes: 9 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name: "Test typescript-action"

on:
pull_request:
push:
branches:
- master
- 'releases/*'
pull_request:
types: [synchronize, opened]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

# install based on package-lock.json file
- run: npm ci
# build the /lib so we can test it on our own repo
- run: npm run build
- run: npm test

# run our own action
- uses: ./
with:
milliseconds: 1000
build-script: build
bundlesize-github-token: ${{ secrets.BUNDLESIZE_GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ __tests__/runner/*
# comment out in distribution branches
node_modules/

lib/

# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"bracketSpacing": true,
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
}
13 changes: 7 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'Bundlesize Github Action'
description: 'Run bundlesize against your PR to keep those bundles in check! Update your package.json according to bundlesize config'
author: 'Jacky Efendi'
inputs:
myInput: # change this
description: 'input description here'
default: 'default value if applicable'
build-script:
description: 'The build script to run before running bundlesize'
required: true

runs:
using: 'node12'
main: 'lib/main.js'
43 changes: 36 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const wait_1 = require("./wait");
const exec = __importStar(require("@actions/exec"));
const github = __importStar(require("@actions/github"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`);
core.debug((new Date()).toTimeString());
wait_1.wait(parseInt(ms));
core.debug((new Date()).toTimeString());
core.setOutput('time', new Date().toTimeString());
let output = '';
let error = '';
const options = {};
options.listeners = {
stdout: (data) => {
output += data.toString();
},
stderr: (data) => {
error += data.toString();
}
};
const buildScript = core.getInput('build-script');
const bundlesizeGithubToken = core.getInput('bundlesize-github-token');
const githubPayload = github.context.payload;
if (!githubPayload)
throw new Error('Failed when trying to get PR information');
const commitSHA = githubPayload.pull_request ? githubPayload.pull_request.head.sha : '';
const prTitle = githubPayload.pull_request ? githubPayload.pull_request.title : '';
const repoOwner = githubPayload.repository ? githubPayload.repository.owner.login : '';
const repoName = githubPayload.repository ? githubPayload.repository.name : '';
core.exportVariable('CI_REPO_OWNER', repoOwner);
core.exportVariable('CI_REPO_NAME', repoName);
core.exportVariable('CI_COMMIT_MESSAGE', prTitle);
core.exportVariable('CI_COMMIT_SHA', commitSHA);
core.exportVariable('CI', 'true');
core.exportVariable('BUNDLESIZE_GITHUB_TOKEN', bundlesizeGithubToken);
console.log(`Running: npm run ${buildScript}`);
yield exec.exec(`npm run ${buildScript}`, undefined);
console.log(`Running: bundlesize`);
yield exec.exec(`npx bundlesize`, undefined, options);
if (output)
console.info(output);
if (error)
throw new Error(error);
}
catch (error) {
core.setFailed(error.message);
Expand Down
4 changes: 2 additions & 2 deletions lib/wait.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function wait(milliseconds) {
return new Promise((resolve, reject) => {
if (typeof (milliseconds) !== 'number') {
return new Promise((resolve) => {
if (isNaN(milliseconds)) {
throw new Error('milleseconds not a number');
}
setTimeout(() => resolve("done!"), milliseconds);
Expand Down
Loading