Skip to content

Commit

Permalink
feat: Setup bundlesize GH action
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyef committed Oct 18, 2019
1 parent 23a0626 commit f72d295
Show file tree
Hide file tree
Showing 8 changed files with 3,999 additions and 40 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
name: "Test typescript-action"
on:
pull_request:
push:
branches:
- master
- 'releases/*'
pull_request: [syncronize, created]

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

- run: npm ci
- run: npm run build
- run: npm test
- uses: ./
with:
milliseconds: 1000
build-script: npm run build
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"
}
15 changes: 8 additions & 7 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'
using: 'node10'
main: 'lib/main.js'
16 changes: 8 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Expand All @@ -16,16 +17,15 @@ 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 child = __importStar(require("child_process"));
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());
const buildScript = core.getInput('build-script');
core.debug(`Running: npm run ${buildScript}`);
child.execSync(`npm run ${buildScript}`);
core.debug(`Running: bundlesize`);
child.execSync(`npm run bundlesize`);
}
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
26 changes: 19 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "typescript-action",
"name": "bundlesize-gh-action",
"version": "0.0.0",
"private": true,
"description": "TypeScript template action",
"description": "bundlesize-gh-action",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/actions/typescript-action.git"
"url": "git+https://github.com/jackyef/bundlesize-gh-action.git"
},
"keywords": [
"actions",
"node",
"setup"
"bundlesize"
],
"author": "YourNameOrOrganization",
"author": "Jacky Efendi",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.0.0"
"@actions/core": "^1.0.0",
"bundlesize": "^0.18.0"
},
"devDependencies": {
"@types/jest": "^24.0.13",
Expand All @@ -29,5 +31,15 @@
"jest-circus": "^24.7.1",
"ts-jest": "^24.0.2",
"typescript": "^3.5.1"
}
},
"bundlesize": [
{
"path": "./lib/main.js",
"maxSize": "5 kB"
},
{
"path": "./lib/wait.js",
"maxSize": "1 kB"
}
]
}
15 changes: 7 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import * as core from '@actions/core';
import {wait} from './wait'
import * as child from 'child_process';

async function run() {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`)
const buildScript = core.getInput('build-script');

core.debug((new Date()).toTimeString())
await wait(parseInt(ms, 10));
core.debug((new Date()).toTimeString())

core.setOutput('time', new Date().toTimeString());
core.debug(`Running: npm run ${buildScript}`);
child.execSync(`npm run ${buildScript}`);

core.debug(`Running: bundlesize`);
child.execSync(`npm run bundlesize`);
} catch (error) {
core.setFailed(error.message);
}
Expand Down
Loading

0 comments on commit f72d295

Please sign in to comment.