-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 38c6731
Showing
6 changed files
with
792 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require('esm')(); | ||
require('./action'); |
Oops, something went wrong.