Skip to content

Commit

Permalink
Merge pull request #13 from vio/add-status
Browse files Browse the repository at this point in the history
feature: Set total bundle size as a status
  • Loading branch information
vio authored May 8, 2020
2 parents 0b3343a + 6628418 commit bdf9a34
Show file tree
Hide file tree
Showing 235 changed files with 32,136 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ jobs:
uses: ./
with:
webpack-stats-path: examples/app/artifacts/webpack-stats.json
repo-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [BundleStats](https://github.com/relative-ci/bundle-stats) Github Action

This action generates [bundle-stats](https://github.com/relative-ci/bundle-stats) reports for webpack stats.
This action generates [bundle-stats](https://github.com/relative-ci/bundle-stats) reports for webpack stats and sets the total bundle size as status description for the commit.

## Inputs

Expand All @@ -10,6 +10,11 @@ This action generates [bundle-stats](https://github.com/relative-ci/bundle-stats

[bundle-stats webpack configuration options](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli#webpack-configuration)

### `repo-token`

Github action repo token (eg: `${{ secrets.GITHUB_TOKEN }}`). If provided, the bundle size will be
added as a status.

## Outputs

`bundle-stats` artifact with `html` and `json` reports:
Expand All @@ -26,4 +31,5 @@ jobs:
uses: vio/bundle-stats-action@v1
with:
webpack-stats-path: 'static/stats.json'
repo-token: ${{ secrets.GITHUB_TOKEN }}
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ inputs:
descript: 'Webpack stats filepath'
required: true
default: 'dist/webpack-stats.json'
repo-token:
description: 'Github action auth token'
required: false
default: ''
28 changes: 27 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const fs = require('fs').promises;
const path = require('path');
const { get } = require('lodash');
const got = require('got');
const core = require('@actions/core');
const artifact = require('@actions/artifact');
const { createArtifacts } = require('@bundle-stats/cli-utils');
const { createJobs, createReport } = require('@bundle-stats/utils');
const { filter, validate } = require('@bundle-stats/utils/lib/webpack');

const { GITHUB_REPOSITORY, GITHUB_SHA } = process.env;

(async () => {
const statsPath = core.getInput('webpack-stats-path', { required: true });
const token = core.getInput('repo-token', { required: false });

try {
core.debug(`Read webpack stats file from ${statsPath}`);
Expand Down Expand Up @@ -59,7 +63,29 @@ const { filter, validate } = require('@bundle-stats/utils/lib/webpack');
});

const info = get(report, 'insights.webpack.assetsSizeTotal.data.info.displayValue');
if (info) {

if (!info) {
core.warning(`Something went wrong, no information available.`);
return;
}

if (token) {
await got.post(
`https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}`,
{
json: {
state: 'success',
context: 'bundle-stats',
description: info
},
responseType: 'json',
headers: {
authorization: `Bearer ${token}`,
'content-type': 'application/json'
}
}
);
} else {
core.warning(`Total Bundle Size: ${info}`);
}
} catch (error) {
Expand Down
261 changes: 261 additions & 0 deletions node_modules/@sindresorhus/is/dist/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bdf9a34

Please sign in to comment.