Skip to content

Commit 8ecb7fb

Browse files
feat: Build for release
1 parent 4913e43 commit 8ecb7fb

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/release-github-actions/badge)](https://www.codefactor.io/repository/github/technote-space/release-github-actions)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/release-github-actions/blob/master/LICENSE)
77

8-
GitHub action for release automation.
8+
This is a GitHub Action that automates the release of GitHub Action.
99
Once you publish the release, this action will automatically
1010
1. Run build
1111
1. Create branch for release
@@ -153,6 +153,10 @@ The following tags will be created or attached to latest release.
153153
- minor tag name (generated by tag name)
154154
- e.g. `v1.2`
155155

156+
## Sample GitHub Actions
157+
- [Auto card labeler](https://github.com/technote-space/auto-card-labeler)
158+
- [Assign Author](https://github.com/technote-space/assign-author)
159+
156160
## Author
157161
[GitHub (Technote)](https://github.com/technote-space)
158162
[Blog](https://technote.space)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Release GitHub Actions
2-
description: GitHub actions to auto release.
2+
description: This is a GitHub Action that automates the release of GitHub Action.
33
author: technote-space
44
inputs:
55
GITHUB_TOKEN:

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tagName":"v1.1.4","branch":"gh-actions","tags":["v1.1.4","v1","v1.1"],"updated_at":"2019-08-28T09:21:43.095Z"}
1+
{"tagName":"v1.1.5","branch":"gh-actions","tags":["v1.1.5","v1","v1.1"],"updated_at":"2019-08-29T10:14:45.645Z"}

lib/constant.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ exports.DEFAULT_COMMIT_EMAIL = '[email protected]';
66
exports.DEFAULT_BRANCH_NAME = 'gh-actions';
77
exports.DEFAULT_CLEAN_TARGETS = '.github,__tests__,src,.gitignore,*.js,*.json,*.lock,_config.yml';
88
exports.DEFAULT_OUTPUT_BUILD_INFO_FILENAME = '';
9-
exports.TARGET_EVENT_NAME = 'release';
10-
exports.TARGET_EVENT_ACTION = 'published';
9+
exports.TARGET_EVENTS = {
10+
'release': 'published'
11+
};
1112
exports.SEARCH_BUILD_COMMAND_TARGETS = [
1213
'build',
1314
'production',

lib/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use strict";
22
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); }); }
34
return new (P || (P = Promise))(function (resolve, reject) {
45
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
56
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
78
step((generator = generator.apply(thisArg, _arguments || [])).next());
89
});
910
};

lib/utils/command.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use strict";
22
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); }); }
34
return new (P || (P = Promise))(function (resolve, reject) {
45
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
56
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
78
step((generator = generator.apply(thisArg, _arguments || [])).next());
89
});
910
};
@@ -12,12 +13,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1213
};
1314
Object.defineProperty(exports, "__esModule", { value: true });
1415
const fs_1 = __importDefault(require("fs"));
16+
const moment_1 = __importDefault(require("moment"));
1517
const path_1 = __importDefault(require("path"));
1618
const signale_1 = __importDefault(require("signale"));
17-
const moment_1 = __importDefault(require("moment"));
1819
const child_process_1 = require("child_process");
1920
const misc_1 = require("./misc");
20-
exports.deploy = (tagName, octokit, context) => __awaiter(this, void 0, void 0, function* () {
21+
exports.deploy = (tagName, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
2122
const workDir = path_1.default.resolve(misc_1.getWorkspace(), '.work');
2223
const buildDir = path_1.default.resolve(workDir, 'build');
2324
const pushDir = path_1.default.resolve(workDir, 'push');
@@ -40,14 +41,14 @@ exports.deploy = (tagName, octokit, context) => __awaiter(this, void 0, void 0,
4041
return;
4142
yield updateRelease(tagName, octokit, context);
4243
});
43-
exports.prepareFiles = (buildDir, pushDir, tagName, context) => __awaiter(this, void 0, void 0, function* () {
44+
exports.prepareFiles = (buildDir, pushDir, tagName, context) => __awaiter(void 0, void 0, void 0, function* () {
4445
signale_1.default.info('Preparing files for release');
4546
fs_1.default.mkdirSync(buildDir, { recursive: true });
4647
yield cloneForBuild(buildDir, context);
4748
yield runBuild(buildDir);
4849
return true;
4950
});
50-
const createBuildInfoFile = (buildDir, tagName, branchName) => __awaiter(this, void 0, void 0, function* () {
51+
const createBuildInfoFile = (buildDir, tagName, branchName) => __awaiter(void 0, void 0, void 0, function* () {
5152
const filename = misc_1.getOutputBuildInfoFilename();
5253
if (!filename)
5354
return true;
@@ -65,7 +66,7 @@ const createBuildInfoFile = (buildDir, tagName, branchName) => __awaiter(this, v
6566
}));
6667
return true;
6768
});
68-
const cloneForBranch = (pushDir, branchName, context) => __awaiter(this, void 0, void 0, function* () {
69+
const cloneForBranch = (pushDir, branchName, context) => __awaiter(void 0, void 0, void 0, function* () {
6970
signale_1.default.info('Cloning the branch %s from the remote repo', branchName);
7071
const url = misc_1.getGitUrl(context);
7172
yield execAsync(`git -C ${pushDir} clone --quiet --branch=${branchName} --depth=1 ${url} .`, true, 'git clone', true);
@@ -80,29 +81,29 @@ const cloneForBranch = (pushDir, branchName, context) => __awaiter(this, void 0,
8081
}
8182
return true;
8283
});
83-
const getCurrentBranchName = (pushDir) => __awaiter(this, void 0, void 0, function* () {
84+
const getCurrentBranchName = (pushDir) => __awaiter(void 0, void 0, void 0, function* () {
8485
if (!fs_1.default.existsSync(path_1.default.resolve(pushDir, '.git'))) {
8586
return '';
8687
}
8788
return (yield execAsync(`git -C ${pushDir} branch -a | grep -E '^\\*' | cut -b 3-`)).trim();
8889
});
89-
const gitInit = (pushDir) => __awaiter(this, void 0, void 0, function* () {
90+
const gitInit = (pushDir) => __awaiter(void 0, void 0, void 0, function* () {
9091
signale_1.default.info('Initializing local git repo');
9192
yield execAsync(`git -C ${pushDir} init .`);
9293
});
93-
const gitCheckout = (pushDir, branchName) => __awaiter(this, void 0, void 0, function* () {
94+
const gitCheckout = (pushDir, branchName) => __awaiter(void 0, void 0, void 0, function* () {
9495
signale_1.default.info('Checking out orphan branch %s', branchName);
9596
yield execAsync(`git -C ${pushDir} checkout --orphan "${branchName}"`);
9697
});
97-
const config = (pushDir) => __awaiter(this, void 0, void 0, function* () {
98+
const config = (pushDir) => __awaiter(void 0, void 0, void 0, function* () {
9899
const name = misc_1.getCommitName();
99100
const email = misc_1.getCommitEmail();
100101
signale_1.default.info('Configuring git committer to be %s <%s>', name, email);
101102
yield execAsync(`git -C ${pushDir} config user.name "${name}"`);
102103
yield execAsync(`git -C ${pushDir} config user.email "${email}"`);
103104
return true;
104105
});
105-
const commit = (pushDir) => __awaiter(this, void 0, void 0, function* () {
106+
const commit = (pushDir) => __awaiter(void 0, void 0, void 0, function* () {
106107
const message = misc_1.getCommitMessage();
107108
yield execAsync(`git -C ${pushDir} add --all --force`);
108109
if (!(yield checkDiff(pushDir))) {
@@ -113,7 +114,7 @@ const commit = (pushDir) => __awaiter(this, void 0, void 0, function* () {
113114
yield execAsync(`git -C ${pushDir} show --stat-count=10 HEAD`);
114115
return true;
115116
});
116-
const push = (pushDir, tagName, branchName, context) => __awaiter(this, void 0, void 0, function* () {
117+
const push = (pushDir, tagName, branchName, context) => __awaiter(void 0, void 0, void 0, function* () {
117118
signale_1.default.info('Pushing to %s@%s (tag: %s)', misc_1.getRepository(context), branchName, tagName);
118119
const url = misc_1.getGitUrl(context);
119120
const tagNames = misc_1.getCreateTags(tagName);
@@ -128,7 +129,7 @@ const push = (pushDir, tagName, branchName, context) => __awaiter(this, void 0,
128129
yield execAsync(`git -C ${pushDir} push --quiet --tags "${url}" "${branchName}":"refs/heads/${branchName}"`, true, `git push --tags "${branchName}":"refs/heads/${branchName}"`);
129130
return true;
130131
});
131-
const updateRelease = (tagName, octokit, context) => __awaiter(this, void 0, void 0, function* () {
132+
const updateRelease = (tagName, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
132133
const releases = yield octokit.repos.listReleases({
133134
owner: context.repo.owner,
134135
repo: context.repo.repo,
@@ -146,27 +147,27 @@ const updateRelease = (tagName, octokit, context) => __awaiter(this, void 0, voi
146147
});
147148
return true;
148149
});
149-
const cloneForBuild = (buildDir, context) => __awaiter(this, void 0, void 0, function* () {
150+
const cloneForBuild = (buildDir, context) => __awaiter(void 0, void 0, void 0, function* () {
150151
signale_1.default.info('Cloning the working commit from the remote repo for build');
151152
const url = misc_1.getGitUrl(context);
152153
yield execAsync(`git -C ${buildDir} clone --depth=1 ${url} .`, true, 'git clone --depth=1');
153154
yield execAsync(`git -C ${buildDir} fetch "${url}" ${context.ref}`, true, `git fetch origin ${context.ref}`);
154155
yield execAsync(`git -C ${buildDir} checkout -qf ${context.sha}`);
155156
});
156-
const runBuild = (buildDir) => __awaiter(this, void 0, void 0, function* () {
157+
const runBuild = (buildDir) => __awaiter(void 0, void 0, void 0, function* () {
157158
signale_1.default.info('=== Running build for release ===');
158159
const current = process.cwd();
159160
for (const command of misc_1.getBuildCommands(buildDir)) {
160161
yield execAsync(`cd ${buildDir} && ${command}`);
161162
}
162163
yield execAsync(`cd ${current}`);
163164
});
164-
const copyFiles = (buildDir, pushDir) => __awaiter(this, void 0, void 0, function* () {
165+
const copyFiles = (buildDir, pushDir) => __awaiter(void 0, void 0, void 0, function* () {
165166
signale_1.default.info('=== Copying %s contents to %s ===', buildDir, pushDir);
166167
yield execAsync(`rsync -rl --exclude .git --delete "${buildDir}/" ${pushDir}`);
167168
return true;
168169
});
169-
const checkDiff = (pushDir) => __awaiter(this, void 0, void 0, function* () {
170+
const checkDiff = (pushDir) => __awaiter(void 0, void 0, void 0, function* () {
170171
return (yield execAsync(`git -C ${pushDir} status --short -uno`, false, null, false, true)).split(/\r\n|\n/).filter(line => line.match(/^[MDA]\s+/)).length > 0;
171172
});
172173
const execAsync = (command, quiet = false, altCommand = null, suppressError = false, suppressOutput = false) => new Promise((resolve, reject) => {

lib/utils/misc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path_1 = __importDefault(require("path"));
88
const js_yaml_1 = __importDefault(require("js-yaml"));
99
const core_1 = require("@actions/core");
1010
const constant_1 = require("../constant");
11-
exports.isTargetEvent = (context) => constant_1.TARGET_EVENT_NAME === context.eventName && constant_1.TARGET_EVENT_ACTION === context.payload.action;
11+
exports.isTargetEvent = (context) => 'string' === typeof context.payload.action && context.eventName in constant_1.TARGET_EVENTS && constant_1.TARGET_EVENTS[context.eventName] === context.payload.action;
1212
exports.parseConfig = (content) => js_yaml_1.default.safeLoad(Buffer.from(content, 'base64').toString()) || {};
1313
exports.getRepository = (context) => `${context.repo.owner}/${context.repo.repo}`;
1414
exports.getGitUrl = (context) => {

node_modules/.yarn-integrity

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

0 commit comments

Comments
 (0)