Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 22, 2020
0 parents commit 38c6731
Show file tree
Hide file tree
Showing 6 changed files with 792 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
49 changes: 49 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { getInput, setFailed } from '@actions/core';
import { GitHub, context } from '@actions/github';
import { exec } from '@actions/exec';
import SizePlugin from 'size-plugin-core';


async function run(octokit, context) {
const { owner, repo, number: pull_number } = context.issue;
const pr = (await octokit.pulls.get({ owner, repo, pull_number })).data;

const plugin = new SizePlugin({
pattern: process.env.PATTERN || [
'dist/*.js',
'**/dist/*.js'
],
exclude: '*.map'
});

const cwd = process.cwd();

console.log('computing new sizes');
await exec(`npm ci && npm run build`);
const newSizes = await plugin.readFromDisk(cwd);

console.log('computing old sizes');
await exec(`git checkout ${pr.base.sha}`);
await exec(`npm ci && npm run build`);
const oldSizes = await plugin.readFromDisk(cwd);

const diff = await plugin.getDiff(oldSizes, newSizes);

const text = await plugin.printSizes(diff);

await octokit.issues.createComment({
...context.repo,
issue_number: pull_number,
body: `Size updates:\n\n\n\n\`\`\`\n${text}\n\`\`\``,
});
}

export default async () => {
try {
const token = getInput('repo-token', { required: true });
const octokit = new GitHub(token);
await run(octokit, context);
} catch (e) {
setFailed(e.message);
}
};
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'gzip-size action'
description: 'Get compressed size differences for every PR'
author: 'Jason Miller'
branding:
icon: 'archive'
color: 'purple'
inputs:
repo-token:
description: 'The GITHUB_TOKEN secret'
runs:
using: 'node12'
main: 'index.js'
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('esm')();
require('./action');
Loading

0 comments on commit 38c6731

Please sign in to comment.