Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit ae414df

Browse files
feat: build for release
1 parent 10b863a commit ae414df

File tree

13 files changed

+368
-366
lines changed

13 files changed

+368
-366
lines changed

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"owner":"technote-space","repo":"auto-cancel-redundant-workflow","sha":"5c44f420067b062bdbe9ae76d276e9bd0e4c73d8","ref":"refs/tags/test/v1.6.5.403732371","tagName":"test/v1.6.5.403732371","branch":"gh-actions","tags":["test/v1.6.5.403732371","test/v1.6.5","test/v1.6","test/v1"],"updated_at":"2020-12-06T09:09:33.534Z"}
1+
{"owner":"technote-space","repo":"auto-cancel-redundant-workflow","sha":"FETCH_HEAD","ref":"refs/heads/master","tagName":"test/v1.6.5","branch":"gh-actions","tags":["test/v1.6.5","test/v1.6","test/v1"],"updated_at":"2020-12-07T13:54:56.876Z"}

lib/main.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
"use strict";
2-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4-
return new (P || (P = Promise))(function (resolve, reject) {
5-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8-
step((generator = generator.apply(thisArg, _arguments || [])).next());
9-
});
10-
};
112
Object.defineProperty(exports, "__esModule", { value: true });
123
const path_1 = require("path");
134
const core_1 = require("@actions/core");
145
const context_1 = require("@actions/github/lib/context");
156
const github_action_helper_1 = require("@technote-space/github-action-helper");
167
const github_action_log_helper_1 = require("@technote-space/github-action-log-helper");
178
const process_1 = require("./process");
18-
const run = () => __awaiter(void 0, void 0, void 0, function* () {
9+
const run = async () => {
1910
const logger = new github_action_log_helper_1.Logger();
2011
const context = new context_1.Context();
2112
github_action_helper_1.ContextHelper.showActionInfo(path_1.resolve(__dirname, '..'), logger, context);
22-
yield process_1.execute(logger, github_action_helper_1.Utils.getOctokit(), context);
23-
});
13+
await process_1.execute(logger, github_action_helper_1.Utils.getOctokit(), context);
14+
};
2415
run().catch(error => {
2516
console.log(error);
2617
core_1.setFailed(error.message);

lib/process.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
11
"use strict";
2-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4-
return new (P || (P = Promise))(function (resolve, reject) {
5-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8-
step((generator = generator.apply(thisArg, _arguments || [])).next());
9-
});
10-
};
112
Object.defineProperty(exports, "__esModule", { value: true });
123
exports.execute = void 0;
134
const core_1 = require("@actions/core");
145
const misc_1 = require("./utils/misc");
156
const workflow_1 = require("./utils/workflow");
16-
const execute = (logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
7+
const execute = async (logger, octokit, context) => {
178
if (misc_1.isExcludeContext(context)) {
189
logger.info('This is not target context.');
1910
core_1.setOutput('ids', '');
2011
return;
2112
}
2213
const runId = misc_1.getRunId();
2314
logger.info('run id: %d', runId);
24-
const run = yield workflow_1.getWorkflowRun(octokit, context);
15+
const run = await workflow_1.getWorkflowRun(octokit, context);
2516
logger.startProcess('run:');
2617
console.log(misc_1.getFilteredRun(run));
2718
logger.endProcess();
28-
const workflowId = yield workflow_1.getWorkflowId(run);
19+
const workflowId = await workflow_1.getWorkflowId(run);
2920
logger.info('workflow id: %d', workflowId);
30-
const runs = yield workflow_1.getWorkflowRuns(workflowId, logger, octokit, context);
21+
const runs = await workflow_1.getWorkflowRuns(workflowId, logger, octokit, context);
3122
logger.startProcess('workflow runs:');
3223
console.log(runs.map(run => misc_1.getFilteredRun(run)));
3324
logger.endProcess();
3425
logger.log();
35-
const runsWithCreatedAtTime = runs.filter(run => run.id !== runId).map(run => (Object.assign(Object.assign({}, run), { createdAt: Date.parse(workflow_1.getWorkflowRunCreatedAt(run)) })));
26+
const runsWithCreatedAtTime = runs.filter(run => run.id !== runId).map(run => ({ ...run, createdAt: Date.parse(workflow_1.getWorkflowRunCreatedAt(run)) }));
3627
const createdAt = Date.parse(workflow_1.getWorkflowRunCreatedAt(run));
3728
const runNumber = workflow_1.getWorkflowRunNumber(run);
3829
if (runsWithCreatedAtTime.find(run => run.createdAt > createdAt || (run.createdAt === createdAt && workflow_1.getWorkflowRunNumber(run) > runNumber))) {
@@ -41,12 +32,12 @@ const execute = (logger, octokit, context) => __awaiter(void 0, void 0, void 0,
4132
return;
4233
}
4334
logger.startProcess('Cancelling...');
44-
yield Promise.all(runsWithCreatedAtTime.map(run => {
35+
await Promise.all(runsWithCreatedAtTime.map(run => {
4536
logger.log('cancel: %d', run.id);
4637
return workflow_1.cancelWorkflowRun(run.id, octokit, context);
4738
}));
4839
logger.info('total: %d', runsWithCreatedAtTime.length);
4940
core_1.setOutput('ids', runsWithCreatedAtTime.map(run => run.id).join(','));
5041
logger.endProcess();
51-
});
42+
};
5243
exports.execute = execute;

lib/utils/misc.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
"use strict";
2-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4-
return new (P || (P = Promise))(function (resolve, reject) {
5-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8-
step((generator = generator.apply(thisArg, _arguments || [])).next());
9-
});
10-
};
112
Object.defineProperty(exports, "__esModule", { value: true });
123
exports.getFilteredRun = exports.getTargetBranch = exports.getRunId = exports.isNotExcludeRun = exports.isExcludeContext = void 0;
134
const core_1 = require("@actions/core");
@@ -23,12 +14,12 @@ const isNotExcludeRun = (run) => !isExcludeMerged() || !getMergeMessagePrefix().
2314
exports.isNotExcludeRun = isNotExcludeRun;
2415
const getRunId = () => Number(process.env.GITHUB_RUN_ID);
2516
exports.getRunId = getRunId;
26-
const getTargetBranch = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
17+
const getTargetBranch = async (octokit, context) => {
2718
if (context.payload.pull_request) {
2819
return context.payload.pull_request.head.ref;
2920
}
3021
return github_action_helper_1.Utils.getBranch(context) || undefined;
31-
});
22+
};
3223
exports.getTargetBranch = getTargetBranch;
3324
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3425
const getFilteredRun = (run) => Object.assign({}, ...constant_1.SHOW_PROPERTIES.map(key => ({ [key]: run[key] })));

lib/utils/workflow.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
"use strict";
2-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4-
return new (P || (P = Promise))(function (resolve, reject) {
5-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8-
step((generator = generator.apply(thisArg, _arguments || [])).next());
9-
});
10-
};
112
Object.defineProperty(exports, "__esModule", { value: true });
123
exports.cancelWorkflowRun = exports.getWorkflowRuns = exports.getWorkflowRunNumber = exports.getWorkflowRunCreatedAt = exports.getWorkflowId = exports.getWorkflowRun = void 0;
4+
const github_action_helper_1 = require("@technote-space/github-action-helper");
135
const misc_1 = require("./misc");
14-
const getWorkflowRun = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
15-
return (yield octokit.actions.getWorkflowRun({
6+
const getWorkflowRun = async (octokit, context) => {
7+
return (await octokit.actions.getWorkflowRun({
168
owner: context.repo.owner,
179
repo: context.repo.repo,
1810
'run_id': Number(process.env.GITHUB_RUN_ID),
1911
})).data;
20-
});
12+
};
2113
exports.getWorkflowRun = getWorkflowRun;
2214
const getWorkflowId = (run) => {
2315
const matches = run.workflow_url.match(/\d+$/);
@@ -27,28 +19,33 @@ const getWorkflowId = (run) => {
2719
return Number(matches[0]);
2820
};
2921
exports.getWorkflowId = getWorkflowId;
30-
const getWorkflowRunCreatedAt = (run) => run.created_at;
22+
const getWorkflowRunCreatedAt = (run) => github_action_helper_1.Utils.ensureNotNull(run.created_at);
3123
exports.getWorkflowRunCreatedAt = getWorkflowRunCreatedAt;
3224
const getWorkflowRunNumber = (run) => run.run_number;
3325
exports.getWorkflowRunNumber = getWorkflowRunNumber;
34-
const getWorkflowRuns = (workflowId, logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
35-
const options = Object.assign(Object.assign({}, context.repo), { 'workflow_id': workflowId, status: 'in_progress' });
36-
const branch = yield misc_1.getTargetBranch(octokit, context);
26+
const getWorkflowRuns = async (workflowId, logger, octokit, context) => {
27+
const options = {
28+
...context.repo,
29+
'workflow_id': workflowId,
30+
status: 'in_progress',
31+
};
32+
const branch = await misc_1.getTargetBranch(octokit, context);
3733
logger.log('target event: %s', logger.c(context.eventName, { color: 'green' }));
3834
if (branch) {
3935
logger.log('target branch: %s', logger.c(branch, { color: 'green' }));
4036
options.branch = branch;
4137
}
42-
return (yield octokit.paginate(octokit.actions.listWorkflowRuns,
38+
return (await octokit.paginate(octokit.actions.listWorkflowRuns,
4339
// eslint-disable-next-line no-warning-comments
4440
// TODO: remove ts-ignore after fixed types (https://github.com/octokit/types.ts/issues/122)
4541
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4642
// @ts-ignore
4743
options)).map(run => run).filter(run => run.event === context.eventName).filter(misc_1.isNotExcludeRun);
48-
});
44+
};
4945
exports.getWorkflowRuns = getWorkflowRuns;
5046
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51-
const cancelWorkflowRun = (runId, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
52-
return octokit.actions.cancelWorkflowRun(Object.assign(Object.assign({}, context.repo), { 'run_id': runId }));
47+
const cancelWorkflowRun = async (runId, octokit, context) => octokit.actions.cancelWorkflowRun({
48+
...context.repo,
49+
'run_id': runId,
5350
});
5451
exports.cancelWorkflowRun = cancelWorkflowRun;

node_modules/.yarn-integrity

Lines changed: 10 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)