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

Commit 54ee80e

Browse files
feat: build for release
0 parents  commit 54ee80e

File tree

581 files changed

+189623
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

581 files changed

+189623
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Technote
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.ja.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Auto Cancel Redundant Job
2+
3+
[![CI Status](https://github.com/technote-space/auto-cancel-redundant-job/workflows/CI/badge.svg)](https://github.com/technote-space/auto-cancel-redundant-job/actions)
4+
[![codecov](https://codecov.io/gh/technote-space/auto-cancel-redundant-job/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/auto-cancel-redundant-job)
5+
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/auto-cancel-redundant-job/badge)](https://www.codefactor.io/repository/github/technote-space/auto-cancel-redundant-job)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/auto-cancel-redundant-job/blob/master/LICENSE)
7+
8+
*Read this in other languages: [English](README.md), [日本語](README.ja.md).*
9+
10+
冗長ビルドを自動キャンセルする `GitHub Actions` です。
11+
12+
## Table of Contents
13+
14+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
15+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16+
<details>
17+
<summary>Details</summary>
18+
19+
- [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95)
20+
- [スクリーンショット](#%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88)
21+
- [キャンセル中](#%E3%82%AD%E3%83%A3%E3%83%B3%E3%82%BB%E3%83%AB%E4%B8%AD)
22+
- [キャンセルされたジョブ](#%E3%82%AD%E3%83%A3%E3%83%B3%E3%82%BB%E3%83%AB%E3%81%95%E3%82%8C%E3%81%9F%E3%82%B8%E3%83%A7%E3%83%96)
23+
- [結果](#%E7%B5%90%E6%9E%9C)
24+
- [Author](#author)
25+
26+
</details>
27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
28+
29+
## 使用方法
30+
```yaml
31+
on:
32+
repository_dispatch:
33+
types: [test]
34+
# push:
35+
# ...
36+
37+
name: Broken Link Check
38+
jobs:
39+
check:
40+
name: Broken Link Check
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: technote-space/auto-cancel-redundant-job@v1
44+
# ...
45+
```
46+
47+
e.g. [update-dependencies.yml](.github/workflows/update-dependencies.yml)
48+
49+
## スクリーンショット
50+
### キャンセル中
51+
![cancelling](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/cancelling.png)
52+
53+
### キャンセルされたジョブ
54+
![cancelled](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/cancelled.png)
55+
56+
### 結果
57+
![result](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/result.png)
58+
59+
## Author
60+
[GitHub (Technote)](https://github.com/technote-space)
61+
[Blog](https://technote.space)

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Auto Cancel Redundant Job
2+
3+
[![CI Status](https://github.com/technote-space/auto-cancel-redundant-job/workflows/CI/badge.svg)](https://github.com/technote-space/auto-cancel-redundant-job/actions)
4+
[![codecov](https://codecov.io/gh/technote-space/auto-cancel-redundant-job/branch/master/graph/badge.svg)](https://codecov.io/gh/technote-space/auto-cancel-redundant-job)
5+
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/auto-cancel-redundant-job/badge)](https://www.codefactor.io/repository/github/technote-space/auto-cancel-redundant-job)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/auto-cancel-redundant-job/blob/master/LICENSE)
7+
8+
*Read this in other languages: [English](README.md), [日本語](README.ja.md).*
9+
10+
GitHub Actions to automatically cancel redundant jobs.
11+
12+
## Table of Contents
13+
14+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
15+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16+
<details>
17+
<summary>Details</summary>
18+
19+
- [Usage](#usage)
20+
- [Screenshots](#screenshots)
21+
- [Cancelling jobs](#cancelling-jobs)
22+
- [Cancelled job](#cancelled-job)
23+
- [Result](#result)
24+
- [Author](#author)
25+
26+
</details>
27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
28+
29+
## Usage
30+
```yaml
31+
on:
32+
repository_dispatch:
33+
types: [test]
34+
# push:
35+
# ...
36+
37+
name: Broken Link Check
38+
jobs:
39+
check:
40+
name: Broken Link Check
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: technote-space/auto-cancel-redundant-job@v1
44+
# ...
45+
```
46+
47+
e.g. [update-dependencies.yml](.github/workflows/update-dependencies.yml)
48+
49+
## Screenshots
50+
### Cancelling jobs
51+
![cancelling](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/cancelling.png)
52+
53+
### Cancelled job
54+
![cancelled](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/cancelled.png)
55+
56+
### Result
57+
![result](https://raw.githubusercontent.com/technote-space/auto-cancel-redundant-job/images/result.png)
58+
59+
## Author
60+
[GitHub (Technote)](https://github.com/technote-space)
61+
[Blog](https://technote.space)

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Auto Cancel Redundant Job
2+
3+
description: GitHub Actions to automatically cancel redundant jobs.
4+
5+
author: technote-space
6+
7+
inputs:
8+
GITHUB_TOKEN:
9+
description: Secret GitHub API token to use for making API requests.
10+
default: ${{ github.token }}
11+
required: true
12+
EXCLUDE_MERGED:
13+
description: Whether to exclude merge push.
14+
required: false
15+
default: 'true'
16+
MERGE_MESSAGE_PREFIX:
17+
description: Prefix to detect merge message.
18+
required: false
19+
default: 'Merge pull request'
20+
21+
branding:
22+
icon: 'x-circle'
23+
color: 'orange'
24+
25+
runs:
26+
using: node12
27+
main: lib/main.js

build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"owner":"technote-space","repo":"auto-cancel-redundant-job","sha":"dff6d6bc32ddb3137174d12d725df6473b71f7ca","ref":"refs/tags/v1.0.0","tagName":"v1.0.0","branch":"releases/v1","tags":["v1.0.0","v1.0","v1"],"updated_at":"2020-03-10T17:33:33.661Z"}

lib/main.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"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+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const path_1 = require("path");
13+
const core_1 = require("@actions/core");
14+
const context_1 = require("@actions/github/lib/context");
15+
const github_action_helper_1 = require("@technote-space/github-action-helper");
16+
const process_1 = require("./process");
17+
const run = () => __awaiter(void 0, void 0, void 0, function* () {
18+
const logger = new github_action_helper_1.Logger();
19+
const context = new context_1.Context();
20+
github_action_helper_1.ContextHelper.showActionInfo(path_1.resolve(__dirname, '..'), logger, context);
21+
yield process_1.execute(logger, github_action_helper_1.Utils.getOctokit(), context);
22+
});
23+
run().catch(error => {
24+
console.log(error);
25+
core_1.setFailed(error.message);
26+
});

lib/process.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"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+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const misc_1 = require("./utils/misc");
13+
const workflow_1 = require("./utils/workflow");
14+
exports.execute = (logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
15+
if (misc_1.isExcludeContext(context)) {
16+
logger.info('This is merge push.');
17+
return;
18+
}
19+
const runId = misc_1.getRunId();
20+
logger.info('run id: %d', runId);
21+
const workflowId = yield workflow_1.getWorkflowId(octokit, context);
22+
logger.info('workflow id: %d', workflowId);
23+
const runs = yield workflow_1.getWorkflowRuns(workflowId, logger, octokit, context);
24+
logger.log();
25+
const currentRun = runs.find(run => run.id === runId);
26+
if (!currentRun) {
27+
logger.info(logger.c('maybe canceled', { color: 'yellow' }));
28+
return;
29+
}
30+
const runsWithCreatedAtTime = runs.filter(run => run.id !== runId).map(run => (Object.assign(Object.assign({}, run), { createdAt: Date.parse(run.created_at) })));
31+
const createdAt = Date.parse(currentRun.created_at);
32+
if (runsWithCreatedAtTime.find(run => run.createdAt > createdAt)) {
33+
logger.info(logger.c('newer job exists', { color: 'yellow' }));
34+
return;
35+
}
36+
logger.startProcess('Cancelling...');
37+
yield Promise.all(runsWithCreatedAtTime.map(run => {
38+
logger.log('cancel: %d', run.id);
39+
workflow_1.cancelWorkflowRun(run.id, octokit, context);
40+
}));
41+
logger.info('total: %d', runsWithCreatedAtTime.length);
42+
logger.endProcess();
43+
});

lib/utils/misc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"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+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const core_1 = require("@actions/core");
13+
const github_action_helper_1 = require("@technote-space/github-action-helper");
14+
const getMergeMessagePrefix = () => github_action_helper_1.Utils.getPrefixRegExp(core_1.getInput('MERGE_MESSAGE_PREFIX'));
15+
const isExcludeMerged = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('EXCLUDE_MERGED'));
16+
exports.isExcludeContext = (context) => github_action_helper_1.ContextHelper.isPush(context) && isExcludeMerged() && getMergeMessagePrefix().test(context.payload.head_commit.message);
17+
exports.isNotExcludeRun = (run) => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
18+
exports.getRunId = () => Number(process.env.GITHUB_RUN_ID);
19+
exports.getTargetBranch = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
20+
if (context.payload.pull_request) {
21+
return context.payload.pull_request.head.ref;
22+
}
23+
return github_action_helper_1.Utils.getBranch(context) || undefined;
24+
});

lib/utils/workflow.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"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+
};
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
const misc_1 = require("./misc");
13+
exports.getWorkflowId = (octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
14+
const run = yield octokit.actions.getWorkflowRun({
15+
owner: context.repo.owner,
16+
repo: context.repo.repo,
17+
'run_id': Number(process.env.GITHUB_RUN_ID),
18+
});
19+
const matches = run.data.workflow_url.match(/\d+$/);
20+
if (!matches) {
21+
throw new Error('Invalid workflow run');
22+
}
23+
return Number(matches[0]);
24+
});
25+
exports.getWorkflowRuns = (workflowId, logger, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
26+
const options = Object.assign(Object.assign({}, context.repo), { 'workflow_id': workflowId, status: 'in_progress', event: context.eventName });
27+
const branch = yield misc_1.getTargetBranch(octokit, context);
28+
logger.log('target event: %s', logger.c(context.eventName, { color: 'green' }));
29+
if (branch) {
30+
logger.log('target branch: %s', logger.c(branch, { color: 'green' }));
31+
options.branch = branch;
32+
}
33+
return (yield octokit.paginate(octokit.actions.listWorkflowRuns.endpoint.merge(options))).filter(misc_1.isNotExcludeRun);
34+
});
35+
exports.cancelWorkflowRun = (runId, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
36+
return octokit.actions.cancelWorkflowRun(Object.assign(Object.assign({}, context.repo), { 'run_id': runId }));
37+
});

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)