Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/10minute timeout action #278

Merged
merged 9 commits into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 26 additions & 26 deletions action/main.js
Expand Up @@ -78,23 +78,16 @@ var getCommit = function (event) {
case 'pull_request_review':
case 'pull_request_target': {
return {
// @ts-ignore
owner: event.payload.repository.owner.login,
// @ts-ignore
repo: event.payload.repository.name,
// @ts-ignore
branch: event.payload.pull_request.head.ref,
// @ts-ignore
ref: event.ref || event.payload.pull_request.head.ref,
// @ts-ignore
sha: event.payload.pull_request.head.sha
};
}
case 'push': {
return {
// @ts-ignore
owner: event.payload.repository.owner.login,
// @ts-ignore
repo: event.payload.repository.name,
branch: event.payload.ref.replace('refs/heads/', ''),
ref: event.payload.ref,
Expand All @@ -108,51 +101,53 @@ var getCommit = function (event) {
}
};
function runChromatic(options) {
var _a;
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var sessionId, env, log, packagePath, packageJson, ctx;
return __generator(this, function (_b) {
switch (_b.label) {
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
sessionId = uuid_1.v4();
env = getEnv_1["default"]();
log = log_1.createLogger(sessionId, env);
return [4 /*yield*/, pkg_up_1["default"]()];
case 1:
packagePath = _b.sent();
packagePath = _d.sent();
return [4 /*yield*/, jsonfile_1.readFile(packagePath)];
case 2:
packageJson = _b.sent();
packageJson = _d.sent();
ctx = __assign(__assign({}, parseArgs_1["default"]([])), { packagePath: packagePath,
packageJson: packageJson,
env: env,
log: log,
sessionId: sessionId, flags: options });
return [4 /*yield*/, main_1.runAll(ctx)];
case 3:
_b.sent();
_d.sent();
return [2 /*return*/, {
url: (_a = ctx.build) === null || _a === void 0 ? void 0 : _a.webUrl,
code: ctx.exitCode
code: ctx.exitCode,
buildUrl: (_b = ctx.build) === null || _b === void 0 ? void 0 : _b.webUrl,
storybookUrl: (_c = ctx.build) === null || _c === void 0 ? void 0 : _c.isolatorUrl
}];
}
});
});
}
function run() {
return __awaiter(this, void 0, void 0, function () {
var commit, branch, sha, projectToken, workingDir, buildScriptName, scriptName, exec, skip, doNotStart, storybookPort, storybookUrl, storybookBuildDir, storybookHttps, storybookCert, storybookKey, storybookCa, preserveMissing, autoAcceptChanges, allowConsoleErrors, exitZeroOnChanges, exitOnceUploaded, ignoreLastBuildOnBranch, chromatic, _a, url, code, e_1;
return __generator(this, function (_b) {
switch (_b.label) {
var commit, branch, sha, projectToken, workingDir, buildScriptName, scriptName, exec, skip, doNotStart, storybookPort, storybookUrl, storybookBuildDir, storybookHttps, storybookCert, storybookKey, storybookCa, preserveMissing, autoAcceptChanges, allowConsoleErrors, exitZeroOnChanges, exitOnceUploaded, ignoreLastBuildOnBranch, chromatic, output, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
commit = getCommit(github_1.context);
if (!commit) {
return [2 /*return*/];
}
branch = commit.branch, sha = commit.sha;
_b.label = 1;
_a.label = 1;
case 1:
_b.trys.push([1, 3, , 4]);
_a.trys.push([1, 3, , 4]);
projectToken = core_1.getInput('projectToken') || core_1.getInput('appCode');
workingDir = core_1.getInput('workingDir');
buildScriptName = core_1.getInput('buildScriptName');
Expand Down Expand Up @@ -200,17 +195,20 @@ function run() {
allowConsoleErrors: maybe(allowConsoleErrors, false),
ignoreLastBuildOnBranch: maybe(ignoreLastBuildOnBranch)
});
return [4 /*yield*/, Promise.all([chromatic])];
return [4 /*yield*/, chromatic];
case 2:
_a = (_b.sent())[0], url = _a.url, code = _a.code;
core_1.setOutput('url', url);
core_1.setOutput('code', code.toString());
if (code !== 0) {
output = _a.sent();
core_1.setOutput('url', output.url);
core_1.setOutput('buildUrl', output.buildUrl);
core_1.setOutput('storybookUrl', output.storybookUrl);
core_1.setOutput('code', output.code.toString());
if (output.code !== 0) {
core_1.setFailed('non-zero exit code');
}
process.exit(output.code);
return [3 /*break*/, 4];
case 3:
e_1 = _b.sent();
e_1 = _a.sent();
if (e_1.message)
core_1.error(e_1.message);
if (e_1.stack)
Expand All @@ -219,7 +217,9 @@ function run() {
core_1.error(e_1.description);
core_1.setFailed(e_1.message);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
case 4:
process.exit(1);
return [2 /*return*/];
}
});
});
Expand Down
24 changes: 13 additions & 11 deletions action/main.ts
Expand Up @@ -28,23 +28,16 @@ const getCommit = (event: typeof context) => {
case 'pull_request_review':
case 'pull_request_target': {
return {
// @ts-ignore
owner: event.payload.repository.owner.login,
// @ts-ignore
repo: event.payload.repository.name,
// @ts-ignore
branch: event.payload.pull_request.head.ref,
// @ts-ignore
ref: event.ref || event.payload.pull_request.head.ref,
// @ts-ignore
sha: event.payload.pull_request.head.sha,
};
}
case 'push': {
return {
// @ts-ignore
owner: event.payload.repository.owner.login,
// @ts-ignore
repo: event.payload.repository.name,
branch: event.payload.ref.replace('refs/heads/', ''),
ref: event.payload.ref,
Expand All @@ -61,6 +54,8 @@ const getCommit = (event: typeof context) => {

interface Output {
url: string;
buildUrl: string;
storybookUrl: string;
code: number;
}

Expand All @@ -85,6 +80,8 @@ async function runChromatic(options): Promise<Output> {
return {
url: ctx.build?.webUrl,
code: ctx.exitCode,
buildUrl: ctx.build?.webUrl,
storybookUrl: ctx.build?.isolatorUrl,
};
}

Expand Down Expand Up @@ -148,19 +145,24 @@ async function run() {
ignoreLastBuildOnBranch: maybe(ignoreLastBuildOnBranch),
});

const [{ url, code }] = await Promise.all([chromatic]);
const output = await chromatic;
ndelangen marked this conversation as resolved.
Show resolved Hide resolved

setOutput('url', url);
setOutput('code', code.toString());
setOutput('url', output.url);
setOutput('buildUrl', output.buildUrl);
setOutput('storybookUrl', output.storybookUrl);
setOutput('code', output.code.toString());

if (code !== 0) {
if (output.code !== 0) {
setFailed('non-zero exit code');
}

process.exit(output.code);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's the fix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspired from:

await runAll(ctx);
log.info('');
process.exit(ctx.exitCode);

} catch (e) {
if (e.message) error(e.message);
if (e.stack) error(e.stack);
if (e.description) error(e.description);
setFailed(e.message);
}
process.exit(1);
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
}
run();
44 changes: 22 additions & 22 deletions bin/lib/parseArgs.js
Expand Up @@ -38,43 +38,43 @@ export default function parseArgs(argv) {
booleanDefault: undefined,
flags: {
// Required options
'project-token': { type: 'string', alias: 't' },
'app-code': { type: 'string', alias: 'a' }, // for backwards compatibility
projectToken: { type: 'string', alias: 't' },
appCode: { type: 'string', alias: 'a' }, // for backwards compatibility

// Storybook options
'build-script-name': { type: 'string', alias: 'b' },
'output-dir': { type: 'string', alias: 'o' },
'storybook-build-dir': { type: 'string', alias: 'd' },
buildScriptName: { type: 'string', alias: 'b' },
outputDir: { type: 'string', alias: 'o' },
storybookBuildDir: { type: 'string', alias: 'd' },

// Chromatic options
'allow-console-errors': { type: 'boolean' },
'auto-accept-changes': { type: 'string' },
'exit-once-uploaded': { type: 'string' },
'exit-zero-on-changes': { type: 'string' },
'ignore-last-build-on-branch': { type: 'string' },
allowConsoleErrors: { type: 'boolean' },
autoAcceptChanges: { type: 'string' },
exitOnceUploaded: { type: 'string' },
exitZeroOnChanges: { type: 'string' },
ignoreLastBuildOnBranch: { type: 'string' },
only: { type: 'string' },
'branch-name': { type: 'string' },
'patch-build': { type: 'string' },
'preserve-missing': { type: 'boolean' },
branchName: { type: 'string' },
patchBuild: { type: 'string' },
preserveMissing: { type: 'boolean' },
skip: { type: 'string' },

// Debug options
ci: { type: 'boolean' },
debug: { type: 'boolean' },
'junit-report': { type: 'string' },
junitReport: { type: 'string' },
list: { type: 'boolean' },
interactive: { type: 'boolean', default: true },

// Deprecated options for tunneled builds
'do-not-start': { type: 'boolean', alias: 'S' }, // assumes already started
doNotStart: { type: 'boolean', alias: 'S' }, // assumes already started
exec: { type: 'string', alias: 'e' }, // aka commandName; start via spawn
'script-name': { type: 'string', alias: 's' }, // start via npm/yarn run
'storybook-port': { type: 'string', alias: 'p' },
'storybook-url': { type: 'string', alias: 'u' },
'storybook-https': { type: 'boolean' },
'storybook-cert': { type: 'string' },
'storybook-key': { type: 'string' },
'storybook-ca': { type: 'string' },
scriptName: { type: 'string', alias: 's' }, // start via npm/yarn run
storybookPort: { type: 'string', alias: 'p' },
storybookUrl: { type: 'string', alias: 'u' },
storybookHttps: { type: 'boolean' },
storybookCert: { type: 'string' },
storybookKey: { type: 'string' },
storybookCa: { type: 'string' },
},
}
);
Expand Down
2 changes: 1 addition & 1 deletion dist/storybook-addon.js

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

2 changes: 1 addition & 1 deletion dist/storybook-addon.js.map

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

36 changes: 18 additions & 18 deletions package.json
Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/github": "^4.0.0",
"@babel/runtime": "^7.12.1",
"@babel/runtime": "^7.12.13",
"@chromaui/localtunnel": "^2.0.2",
"async-retry": "^1.3.1",
"chalk": "^4.0.0",
Expand All @@ -76,11 +76,11 @@
"esm": "^3.2.25",
"execa": "^5.0.0",
"fake-tag": "^2.0.0",
"fs-extra": "^9.0.0",
"fs-extra": "^9.1.0",
"jsonfile": "^6.0.1",
"junit-report-builder": "2.1.0",
"listr": "0.14.3",
"meow": "^8.0.0",
"meow": "^9.0.0",
"node-ask": "^1.0.1",
"node-fetch": "^2.6.0",
"node-loggly-bulk": "^2.2.4",
Expand All @@ -100,30 +100,30 @@
"yarn-or-npm": "^3.0.1"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "7.12.10",
"@babel/cli": "^7.12.13",
"@babel/core": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "7.12.13",
"@storybook/eslint-config-storybook": "^3.0.0",
"@storybook/linter-config": "^3.0.0",
"@storybook/react": "6.1.11",
"@types/node": "^14.14.13",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"@storybook/react": "6.1.17",
"@types/node": "^14.14.25",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"ansi-html": "0.0.7",
"cpy": "^8.1.1",
"cross-env": "^7.0.3",
"eslint": "^7.15.0",
"husky": "4.3.6",
"eslint": "^7.19.0",
"husky": "5.0.9",
"jest": "^26.6.1",
"lint-staged": "^10.5.3",
"lint-staged": "^10.5.4",
"npm-run-all": "^4.0.2",
"prettier": "^2.2.1",
"prop-types": "^15.7.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"sort-package-json": "1.48.0",
"typescript": "^4.1.3",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"sort-package-json": "1.48.1",
"typescript": "^4.1.4",
"why-is-node-running": "^2.1.2"
},
"docs": "https://www.chromatic.com/docs/cli"
Expand Down