Skip to content

Commit

Permalink
Require a workflow ID to be given
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrandwoo committed Jun 29, 2021
1 parent eee01a5 commit e144627
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Add the following step to a workflow, after the Next.js project has been built (
- name: Analyze bundle sizes
uses: transferwise/actions-next-bundle-analyzer@master
with:
# Filename of the workflow this step is defined in
workflow-id: my-workflow.yml
# Optional, defaults to master
base-branch: master
env:
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
name: 'Next.js bundle analyzer'
inputs:
workflow-id:
description: 'Workflow ID containing this step'
base-branch:
description: 'Base branch of the repo (master or main)'
default: master
runs:
using: 'node12'
main: 'dist/index.js'
9 changes: 5 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15422,14 +15422,14 @@ var download_artifacts_generator = (undefined && undefined.__generator) || funct
};


function downloadArtifactAsJson(octokit, branch, workflow, artifactName, fileName) {
function downloadArtifactAsJson(octokit, branch, workflowId, artifactName, fileName) {
return download_artifacts_awaiter(this, void 0, void 0, function () {
var runs, artifacts, bundleSizeArtifact, zip, adm, bundleSizeEntry, e_1;
return download_artifacts_generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 4, , 5]);
return [4 /*yield*/, octokit.rest.actions.listWorkflowRuns(download_artifacts_assign(download_artifacts_assign({}, github.context.repo), { branch: branch, workflow_id: workflow, per_page: 1 }))];
return [4 /*yield*/, octokit.rest.actions.listWorkflowRuns(download_artifacts_assign(download_artifacts_assign({}, github.context.repo), { branch: branch, workflow_id: workflowId, per_page: 1 }))];
case 1:
runs = _a.sent();
if (runs.data.workflow_runs.length === 0) {
Expand Down Expand Up @@ -15577,16 +15577,17 @@ var FILE_NAME = 'bundle-sizes.json';
function run() {
var _a;
return src_awaiter(this, void 0, void 0, function () {
var baseBranch, octokit, issueNumber, masterBundleSizes, bundleSizes, prefix, markdownTable, body, e_1;
var workflowId, baseBranch, octokit, issueNumber, masterBundleSizes, bundleSizes, prefix, markdownTable, body, e_1;
return src_generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 3, , 4]);
workflowId = core.getInput('workflow-id', { required: true });
baseBranch = core.getInput('base-branch') || 'master';
octokit = github.getOctokit(process.env.GITHUB_TOKEN || '');
issueNumber = (_a = github.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number;
console.log("> Downloading bundle sizes from " + baseBranch);
return [4 /*yield*/, downloadArtifactAsJson(octokit, baseBranch, github.context.workflow, ARTIFACT_NAME, FILE_NAME)];
return [4 /*yield*/, downloadArtifactAsJson(octokit, baseBranch, workflowId, ARTIFACT_NAME, FILE_NAME)];
case 1:
masterBundleSizes = (_b.sent()) || [];
console.log(masterBundleSizes);
Expand Down
4 changes: 2 additions & 2 deletions src/download-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Octokit } from './types';
export async function downloadArtifactAsJson(
octokit: Octokit,
branch: string,
workflow: string,
workflowId: string,
artifactName: string,
fileName: string
): Promise<any | null> {
Expand All @@ -15,7 +15,7 @@ export async function downloadArtifactAsJson(
const runs = await octokit.rest.actions.listWorkflowRuns({
...github.context.repo,
branch,
workflow_id: workflow,
workflow_id: workflowId,
per_page: 1,
});
if (runs.data.workflow_runs.length === 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const FILE_NAME = 'bundle-sizes.json';

async function run() {
try {
const workflowId = core.getInput('workflow-id', { required: true });
const baseBranch = core.getInput('base-branch') || 'master';

const octokit = github.getOctokit(process.env.GITHUB_TOKEN || '');
Expand All @@ -25,7 +26,7 @@ async function run() {
(await downloadArtifactAsJson(
octokit,
baseBranch,
github.context.workflow,
workflowId,
ARTIFACT_NAME,
FILE_NAME
)) || [];
Expand Down

0 comments on commit e144627

Please sign in to comment.