Skip to content

Commit b602e5a

Browse files
feat: Build for release
1 parent a8a3f07 commit b602e5a

Some content is hidden

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

66 files changed

+3881
-698
lines changed

README.ja.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
1. リリース用ブランチに[タグ](#tags)を張り替え
1515
1. 同じタグ名 かつ 公開済みのリリースが存在する場合、再度公開 (タグを張り替えた場合、リリースが下書き状態になるため)
1616

17+
## Table of Contents
18+
1719
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1820
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
19-
**Table of Contents**
21+
<details>
22+
<summary>Details</summary>
2023

2124
- [スクリーンショット](#%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)
2225
- [インストール](#%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
@@ -48,6 +51,7 @@
4851
- [このアクションを使用しているアクションの例](#%E3%81%93%E3%81%AE%E3%82%A2%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E3%81%84%E3%82%8B%E3%82%A2%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E4%BE%8B)
4952
- [Author](#author)
5053

54+
</details>
5155
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5256

5357
## スクリーンショット
@@ -74,7 +78,7 @@
7478
runs-on: ubuntu-latest
7579
steps:
7680
- name: Release GitHub Actions
77-
uses: technote-space/release-github-actions@v2
81+
uses: technote-space/release-github-actions@v3
7882
with:
7983
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8084
```
@@ -88,7 +92,7 @@ default: `''`
8892
8993
### CLEAN_TARGETS
9094
リリース前に掃除するファイルやディレクトリ (カンマ区切り)
91-
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
95+
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml`
9296
絶対パスや `..` は使用できません。
9397
[More details of execute command](#execute-commands)
9498

@@ -172,17 +176,21 @@ yarn install --production
172176
そして `GitHub Actions` は使用されるたびにダウンロードされるため、ファイルは少ないほうが良いです。
173177

174178
`CLEAN_TARGETS` オプションはこの目的のために使用されます。
175-
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
179+
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml`
176180

177181
```shell
178182
rm -rdf .[!.]*
179183
rm -rdf *.js
180184
rm -rdf *.ts
181185
rm -rdf *.json
182186
rm -rdf *.lock
183-
rm -rdf __tests__ src '_config.yml'
187+
rm -rdf *.yml
188+
rm -rdf *.yaml
189+
rm -rdf __tests__ src
184190
```
185191

192+
(action.yml は削除の対象ではありません)
193+
186194
このデフォルト値は「TypeScriptのActionテンプレート」や「JavaScriptのActionテンプレート」の使用を想定した値になっています。
187195
https://github.com/actions/typescript-action
188196
https://github.com/actions/javascript-action
@@ -247,6 +255,12 @@ https://github.com/technote-space/release-github-actions/tree/gh-actions
247255
- [release.yml](https://github.com/technote-space/toc-generator/blob/master/.github/workflows/release.yml)
248256
- [Package Version Check Action](https://github.com/technote-space/package-version-check-action)
249257
- [release.yml](https://github.com/technote-space/package-version-check-action/blob/master/.github/workflows/release.yml)
258+
- [Get Diff Action](https://github.com/technote-space/get-diff-action)
259+
- [release.yml](https://github.com/technote-space/get-diff-action/blob/master/.github/workflows/release.yml)
260+
- [Create Project Card Action](https://github.com/technote-space/create-project-card-action)
261+
- [release.yml](https://github.com/technote-space/create-project-card-action/blob/master/.github/workflows/release.yml)
262+
- [Get git comment action](https://github.com/technote-space/get-git-comment-action)
263+
- [release.yml](https://github.com/technote-space/get-git-comment-action/blob/master/.github/workflows/release.yml)
250264

251265
## Author
252266
[GitHub (Technote)](https://github.com/technote-space)

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ Once you create a new tag, this action will automatically
1414
1. Change [tags](#tags) to release branch
1515
1. If there is release which has same tag name and has been published, re-publish it (Because if the tag is changed, the release will be in a draft state).
1616

17+
## Table of Contents
18+
1719
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1820
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
19-
**Table of Contents**
21+
<details>
22+
<summary>Details</summary>
2023

2124
- [Screenshots](#screenshots)
2225
- [Installation](#installation)
@@ -48,6 +51,7 @@ Once you create a new tag, this action will automatically
4851
- [Sample GitHub Actions using this Action](#sample-github-actions-using-this-action)
4952
- [Author](#author)
5053

54+
</details>
5155
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
5256

5357
## Screenshots
@@ -88,7 +92,7 @@ default: `''`
8892
8993
### CLEAN_TARGETS
9094
Files or directories to clean before release (Comma separated).
91-
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
95+
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml`
9296
Absolute path and `..` are not permitted to use.
9397
[More details of execute command](#execute-commands)
9498

@@ -173,17 +177,21 @@ To execute `GitHub Actions`, `src files used for build`, `test files`, `test set
173177
And `GitHub Actions` is downloaded every time when it is used, so fewer files are better.
174178

175179
`CLEAN_TARGETS` option is used for this purpose.
176-
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
180+
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml`
177181

178182
```shell
179183
rm -rdf .[!.]*
180184
rm -rdf *.js
181185
rm -rdf *.ts
182186
rm -rdf *.json
183187
rm -rdf *.lock
184-
rm -rdf __tests__ src '_config.yml'
188+
rm -rdf *.yml
189+
rm -rdf *.yaml
190+
rm -rdf __tests__ src
185191
```
186192

193+
(action.yml is not subject to deletion.)
194+
187195
The default setting assumes the use of `Action template for TypeScript` or `Action template for JavaScript`.
188196
https://github.com/actions/typescript-action
189197
https://github.com/actions/javascript-action
@@ -248,6 +256,12 @@ The following tags will be created.
248256
- [release.yml](https://github.com/technote-space/toc-generator/blob/master/.github/workflows/release.yml)
249257
- [Package Version Check Action](https://github.com/technote-space/package-version-check-action)
250258
- [release.yml](https://github.com/technote-space/package-version-check-action/blob/master/.github/workflows/release.yml)
259+
- [Get Diff Action](https://github.com/technote-space/get-diff-action)
260+
- [release.yml](https://github.com/technote-space/get-diff-action/blob/master/.github/workflows/release.yml)
261+
- [Create Project Card Action](https://github.com/technote-space/create-project-card-action)
262+
- [release.yml](https://github.com/technote-space/create-project-card-action/blob/master/.github/workflows/release.yml)
263+
- [Get git comment action](https://github.com/technote-space/get-git-comment-action)
264+
- [release.yml](https://github.com/technote-space/get-git-comment-action/blob/master/.github/workflows/release.yml)
251265

252266
## Author
253267
[GitHub (Technote)](https://github.com/technote-space)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inputs:
3434
required: true
3535
CLEAN_TARGETS:
3636
description: Files or directories to clean before release. (Comma separated)
37-
default: '.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml'
37+
default: '.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml'
3838
required: true
3939
BUILD_COMMAND_TARGET:
4040
description: Command for search build command.

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"owner":"technote-space","repo":"release-github-actions","sha":"9243a4c988f80ea64e55012e41690c5aabcb7a6f","ref":"refs/tags/v2.0.11","tagName":"v2.0.11","branch":"gh-actions","tags":["v2.0.11","v2.0","v2"],"updated_at":"2020-01-28T05:13:43.355Z"}
1+
{"owner":"technote-space","repo":"release-github-actions","sha":"fde32629a6be708aeaffecfa38139679608a6666","ref":"refs/tags/test/v3.0.0","tagName":"test/v3.0.0","branch":"gh-actions","tags":["test/v3.0.0","test/v3.0","test/v3"],"updated_at":"2020-02-06T18:29:25.970Z"}

lib/main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const path_1 = __importDefault(require("path"));
1616
const core_1 = require("@actions/core");
17-
const github_1 = require("@actions/github");
17+
const context_1 = require("@actions/github/lib/context");
1818
const filter_github_action_1 = require("@technote-space/filter-github-action");
1919
const github_action_helper_1 = require("@technote-space/github-action-helper");
2020
const command_1 = require("./utils/command");
@@ -25,12 +25,13 @@ const constant_1 = require("./constant");
2525
function run() {
2626
return __awaiter(this, void 0, void 0, function* () {
2727
const logger = new github_action_helper_1.Logger();
28-
github_action_helper_1.ContextHelper.showActionInfo(path_1.default.resolve(__dirname, '..'), logger, github_1.context);
29-
if (!filter_github_action_1.isTargetEvent(constant_1.TARGET_EVENTS, github_1.context)) {
28+
const context = new context_1.Context();
29+
github_action_helper_1.ContextHelper.showActionInfo(path_1.default.resolve(__dirname, '..'), logger, context);
30+
if (!filter_github_action_1.isTargetEvent(constant_1.TARGET_EVENTS, context)) {
3031
logger.info('This is not target event.');
3132
return;
3233
}
33-
yield command_1.deploy(new github_1.GitHub(github_action_helper_1.Utils.getAccessToken(true)), github_1.context);
34+
yield command_1.deploy(github_action_helper_1.Utils.getOctokit(), context);
3435
});
3536
}
3637
run().catch(error => core_1.setFailed(error.message));

lib/utils/command.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const logger = new github_action_helper_1.Logger(exports.replaceDirectory);
2727
const command = new github_action_helper_1.Command(logger);
2828
const { startProcess, info } = logger;
2929
exports.prepareFiles = (helper, context) => __awaiter(void 0, void 0, void 0, function* () {
30-
const { buildDir } = misc_1.getParams();
30+
const { buildDir, pushDir } = misc_1.getParams();
3131
fs_1.default.mkdirSync(buildDir, { recursive: true });
3232
startProcess('Cloning the remote repo for build...');
3333
yield helper.checkout(buildDir, context);
3434
startProcess('Running build for release...');
35-
yield helper.runCommand(buildDir, misc_1.getBuildCommands(buildDir));
35+
yield helper.runCommand(buildDir, misc_1.getBuildCommands(buildDir, pushDir));
3636
});
3737
exports.createBuildInfoFile = (context) => __awaiter(void 0, void 0, void 0, function* () {
3838
const filename = misc_1.getOutputBuildInfoFilename();
@@ -61,7 +61,7 @@ exports.createBuildInfoFile = (context) => __awaiter(void 0, void 0, void 0, fun
6161
exports.clone = (helper, context) => __awaiter(void 0, void 0, void 0, function* () {
6262
const { pushDir, branchName } = misc_1.getParams();
6363
startProcess('Fetching...');
64-
yield helper.fetchOrigin(pushDir, context, ['--no-tags'], [`+refs/heads/${branchName}:refs/remotes/origin/${branchName}`]);
64+
yield helper.fetchOrigin(pushDir, context, ['--no-tags'], [`refs/heads/${branchName}:refs/remotes/origin/${branchName}`]);
6565
startProcess('Switching branch to [%s]...', branchName);
6666
yield helper.switchBranch(pushDir, branchName);
6767
});
@@ -81,7 +81,7 @@ exports.config = (helper) => __awaiter(void 0, void 0, void 0, function* () {
8181
startProcess('Configuring git committer to be %s <%s>...', name, email);
8282
yield helper.config(pushDir, name, email);
8383
});
84-
exports.commit = (helper) => __awaiter(void 0, void 0, void 0, function* () { return helper.commit(misc_1.getParams().pushDir, misc_1.getCommitMessage()); });
84+
exports.commit = (helper) => __awaiter(void 0, void 0, void 0, function* () { return helper.commit(misc_1.getParams().pushDir, misc_1.getCommitMessage(), { allowEmpty: true }); });
8585
exports.getDeleteTestTag = (tagName, prefix, helper) => __awaiter(void 0, void 0, void 0, function* () {
8686
return (yield helper.getTags(misc_1.getParams().pushDir))
8787
.filter(tag => getPrefixRegExp(prefix).test(tag))
@@ -158,9 +158,7 @@ exports.prepareCommit = (helper, context) => __awaiter(void 0, void 0, void 0, f
158158
});
159159
const executeCommit = (release, helper, octokit, context) => __awaiter(void 0, void 0, void 0, function* () {
160160
yield exports.config(helper);
161-
if (!(yield exports.commit(helper))) {
162-
return false;
163-
}
161+
yield exports.commit(helper);
164162
yield exports.push(helper, context);
165163
yield exports.updateRelease(release, octokit, context);
166164
return true;

lib/utils/misc.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ exports.detectBuildCommand = (dir) => {
3737
}
3838
return false;
3939
};
40+
exports.getBackupCommands = (buildDir, pushDir) => [
41+
{
42+
command: 'mv',
43+
args: ['-f', path_1.default.resolve(buildDir, 'action.yaml'), path_1.default.resolve(pushDir, 'action.yml')],
44+
suppressError: true,
45+
quiet: true,
46+
},
47+
{
48+
command: 'mv',
49+
args: ['-f', path_1.default.resolve(buildDir, 'action.yml'), path_1.default.resolve(pushDir, 'action.yml')],
50+
suppressError: true,
51+
quiet: true,
52+
},
53+
];
54+
exports.getRestoreBackupCommands = (buildDir, pushDir) => [
55+
{
56+
command: 'mv',
57+
args: ['-f', path_1.default.resolve(pushDir, 'action.yml'), path_1.default.resolve(buildDir, 'action.yml')],
58+
suppressError: true,
59+
quiet: true,
60+
},
61+
];
4062
exports.getClearFilesCommands = (targets) => {
4163
const commands = [];
4264
const searchValues = '?<>:|"\'@#$%^& ;';
@@ -56,10 +78,10 @@ exports.getClearFilesCommands = (targets) => {
5678
}
5779
return commands;
5880
};
59-
exports.getBuildCommands = (dir) => {
81+
exports.getBuildCommands = (buildDir, pushDir) => {
6082
let commands = getArrayInput('BUILD_COMMAND', false, '&&').map(normalizeCommand);
61-
const pkgManager = useNpm(dir, core_1.getInput('PACKAGE_MANAGER')) ? 'npm' : 'yarn';
62-
const buildCommand = exports.detectBuildCommand(dir);
83+
const pkgManager = useNpm(buildDir, core_1.getInput('PACKAGE_MANAGER')) ? 'npm' : 'yarn';
84+
const buildCommand = exports.detectBuildCommand(buildDir);
6385
const runSubCommand = pkgManager === 'npm' ? ' run ' : ' ';
6486
const hasInstallCommand = !!commands.filter(command => typeof command === 'string' && (command.includes('npm run install') || command.includes(`${pkgManager} install`))).length;
6587
if (typeof buildCommand === 'string') {
@@ -75,7 +97,9 @@ exports.getBuildCommands = (dir) => {
7597
}
7698
commands.push(`${pkgManager} install --production`);
7799
}
100+
commands.push(...exports.getBackupCommands(buildDir, pushDir));
78101
commands.push(...exports.getClearFilesCommands(getCleanTargets()));
102+
commands.push(...exports.getRestoreBackupCommands(buildDir, pushDir));
79103
return commands;
80104
};
81105
exports.getCommitMessage = () => core_1.getInput('COMMIT_MESSAGE') || constant_1.DEFAULT_COMMIT_MESSAGE;

0 commit comments

Comments
 (0)