Skip to content

Commit

Permalink
Merge pull request #6 from jackyef/v0.0.5
Browse files Browse the repository at this point in the history
chore: build and preparation for release
  • Loading branch information
jackyef authored Jan 14, 2020
2 parents 2c01713 + 3149dbe commit 92c6f64
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/tracked.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Bundlewatch Github Action - on Tracked Branches Push"

on:
push:
branches:
- master

jobs:
bundlewatch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: Borales/[email protected]
- run: yarn install
- uses: ./
with:
bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This GitHub action allows you to easily run [bundlewatch](https://github.com/bun
```
You would probably want to change the `build-script` to whatever script you want to run to produce your output bundle.
_Note: `build-script` is actually optional, just in case your workflow does not need build step and you are measuring the size of already committed files_
5. For adding statuses on pull requests, you can add another workflow for pull requests `synchronize` and `opened` events as following:
```yml
name: "Bundlewatch Github Action"
Expand Down
19 changes: 12 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23762,35 +23762,40 @@ function run() {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
_a.trys.push([0, 4, , 5]);
buildScript = core_5('build-script');
bundlesizeGithubToken = core_5('bundlewatch-github-token');
githubPayload = github_1.payload;
if (!githubPayload)
throw new Error('Failed when trying to get GitHub Payload');
commitSHA = githubPayload.pull_request ? githubPayload.pull_request.head.sha : githubPayload.after;
branchName = githubPayload.pull_request ? githubPayload.pull_request.head.ref : getBranchNameFromRef(githubPayload.ref);
branchName = githubPayload.pull_request
? githubPayload.pull_request.head.ref
: getBranchNameFromRef(githubPayload.ref);
repoOwner = githubPayload.repository ? githubPayload.repository.owner.login : '';
repoName = githubPayload.repository ? githubPayload.repository.name : '';
core_2('CI_REPO_OWNER', repoOwner);
core_2('CI_REPO_NAME', repoName);
core_2('CI_COMMIT_SHA', commitSHA);
core_2('CI_BRANCH', branchName);
core_2('BUNDLEWATCH_GITHUB_TOKEN', bundlesizeGithubToken);
if (!buildScript) return [3 /*break*/, 2];
console.log("Running build script: \"" + buildScript + "\"");
return [4 /*yield*/, exec_2("" + buildScript, undefined)];
case 1:
_a.sent();
_a.label = 2;
case 2:
console.log("Running: bundlewatch");
return [4 /*yield*/, exec_2("npx bundlewatch", undefined)];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
_a.sent();
return [3 /*break*/, 5];
case 4:
error_1 = _a.sent();
core_7(error_1.message);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
return [3 /*break*/, 5];
case 5: return [2 /*return*/];
}
});
});
Expand Down
8 changes: 0 additions & 8 deletions lib/wait.js

This file was deleted.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bundlesize-gh-action",
"version": "0.0.0",
"version": "0.0.5",
"private": true,
"description": "bundlesize-gh-action",
"main": "lib/main.js",
Expand Down Expand Up @@ -47,11 +47,7 @@
"files": [
{
"path": "./lib/main.js",
"maxSize": "2 KB"
},
{
"path": "./lib/wait.js",
"maxSize": "500 B"
"maxSize": "100 KB"
}
]
}
Expand Down
10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as github from '@actions/github';

const getBranchNameFromRef = (ref: string) => {
return ref.replace(/^refs\/heads\//, '');
}
};

async function run() {
try {
Expand All @@ -14,9 +14,11 @@ async function run() {
const githubPayload = github.context.payload;

if (!githubPayload) throw new Error('Failed when trying to get GitHub Payload');

const commitSHA = githubPayload.pull_request ? githubPayload.pull_request.head.sha : githubPayload.after;
const branchName = githubPayload.pull_request ? githubPayload.pull_request.head.ref : getBranchNameFromRef(githubPayload.ref);
const branchName = githubPayload.pull_request
? githubPayload.pull_request.head.ref
: getBranchNameFromRef(githubPayload.ref);
const repoOwner = githubPayload.repository ? githubPayload.repository.owner.login : '';
const repoName = githubPayload.repository ? githubPayload.repository.name : '';

Expand All @@ -26,7 +28,7 @@ async function run() {
core.exportVariable('CI_BRANCH', branchName);
core.exportVariable('BUNDLEWATCH_GITHUB_TOKEN', bundlesizeGithubToken);

if(buildScript) {
if (buildScript) {
console.log(`Running build script: "${buildScript}"`);
await exec.exec(`${buildScript}`, undefined);
}
Expand Down
10 changes: 0 additions & 10 deletions src/wait.ts

This file was deleted.

0 comments on commit 92c6f64

Please sign in to comment.