Skip to content

Commit 7d56219

Browse files
feat: Build for release
1 parent 5e7428a commit 7d56219

31 files changed

+1027
-188
lines changed

README.ja.md

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# Release GitHub Actions
2+
3+
[![Build Status](https://github.com/technote-space/release-github-actions/workflows/Build/badge.svg)](https://github.com/technote-space/release-github-actions/actions)
4+
[![Coverage Status](https://coveralls.io/repos/github/technote-space/release-github-actions/badge.svg?branch=master)](https://coveralls.io/github/technote-space/release-github-actions?branch=master)
5+
[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/release-github-actions/badge)](https://www.codefactor.io/repository/github/technote-space/release-github-actions)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/release-github-actions/blob/master/LICENSE)
7+
8+
*Read this in other languages: [English](README.md), [日本語](README.ja.md).*
9+
10+
これは GitHub Action のリリースを自動化するための GitHub Action です。
11+
タグを作成するとこのアクションは自動で以下を行います。
12+
1. ビルド実行
13+
1. リリース用ブランチ作成
14+
1. リリース用ブランチに[タグ](#tags)を張り替え
15+
1. 同じタグ名 かつ 公開済みのリリースが存在する場合、再度公開 (タグを張り替えた場合、リリースが下書き状態になるため)
16+
17+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
18+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
19+
**Table of Contents**
20+
21+
- [スクリーンショット](#%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)
22+
- [インストール](#%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
23+
- [必要なパラメータ](#%E5%BF%85%E8%A6%81%E3%81%AA%E3%83%91%E3%83%A9%E3%83%A1%E3%83%BC%E3%82%BF)
24+
- [ACCESS_TOKEN](#access_token)
25+
- [オプション](#%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3)
26+
- [BUILD_COMMAND](#build_command)
27+
- [COMMIT_MESSAGE](#commit_message)
28+
- [COMMIT_NAME](#commit_name)
29+
- [COMMIT_EMAIL](#commit_email)
30+
- [BRANCH_NAME](#branch_name)
31+
- [CLEAN_TARGETS](#clean_targets)
32+
- [CREATE_MAJOR_VERSION_TAG](#create_major_version_tag)
33+
- [CREATE_MINOR_VERSION_TAG](#create_minor_version_tag)
34+
- [OUTPUT_BUILD_INFO_FILENAME](#output_build_info_filename)
35+
- [FETCH_DEPTH](#fetch_depth)
36+
- [TEST_TAG_PREFIX](#test_tag_prefix)
37+
- [ORIGINAL_TAG_PREFIX](#original_tag_prefix)
38+
- [Action イベント詳細](#action-%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E8%A9%B3%E7%B4%B0)
39+
- [対象イベント](#%E5%AF%BE%E8%B1%A1%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88)
40+
- [動機](#%E5%8B%95%E6%A9%9F)
41+
- [補足](#%E8%A3%9C%E8%B6%B3)
42+
- [Tags](#tags)
43+
- [このアクションを使用しているアクションの例](#%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)
44+
- [Author](#author)
45+
46+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
47+
48+
## スクリーンショット
49+
1. リリース作成前
50+
![Before publish release](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-1.png)
51+
1. リリースを作成 (タグを作成)
52+
![Publish release](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-2.png)
53+
1. GitHub Action 実行中
54+
![Running GitHub Action](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-3.png)
55+
1. GitHub Action 実行後
56+
![After running GitHub Action](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-4.png)
57+
58+
## インストール
59+
1. workflow を設定
60+
例: `.github/workflows/release.yml`
61+
```yaml
62+
on: push
63+
name: Release
64+
jobs:
65+
release:
66+
name: Release GitHub Actions
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Release GitHub Actions
70+
uses: technote-space/release-github-actions@v1
71+
with:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
74+
```
75+
76+
## 必要なパラメータ
77+
### ACCESS_TOKEN
78+
1. public_repo または repo のスコープで [personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) を生成。
79+
(プライベートリポジトリの場合 repo が必要です)
80+
1. [Secretsに保存](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables)
81+
82+
## オプション
83+
### BUILD_COMMAND
84+
ビルド用コマンド
85+
default: `''`
86+
- build、 production または prod package.json の scripts に含まれる場合、ビルド用のコマンドとしてそれを使用します。
87+
- `npm run install` や `yarn install` のようなインストール用コマンドが存在しない場合、インストール用コマンドが追加されます。
88+
- ビルド用コマンドが空の場合、いくつかのファイルが削除されます。 (詳細:[CLEAN_TARGETS](#clean_targets)).
89+
90+
したがって、`BUILD_COMMAND` が設定されていない かつ package.json に `build` が存在する場合、以下のコマンドが実行されます。
91+
```shell
92+
yarn install
93+
yarn build
94+
yarn install --production
95+
rm -rdf .[!.]*
96+
...
97+
rm -rdf _config.yml
98+
```
99+
100+
### COMMIT_MESSAGE
101+
コミット時に設定するメッセージ
102+
default: `'feat: Build for release'`
103+
104+
### COMMIT_NAME
105+
コミット時に設定する名前
106+
default: `'GitHub Actions'`
107+
108+
### COMMIT_EMAIL
109+
コミット時に設定するメールアドレス
110+
default: `'[email protected]'`
111+
112+
### BRANCH_NAME
113+
GitHub Action 用のブランチ名
114+
default: `'gh-actions'`
115+
116+
### CLEAN_TARGETS
117+
リリース前に削除するファイルやディレクトリ (カンマ区切り)
118+
default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
119+
絶対パスや `..` は使用できません。
120+
121+
### CREATE_MAJOR_VERSION_TAG
122+
メジャーバージョンタグ(例:v1)を作成するかどうか
123+
default: `true`
124+
[タグの詳細](#tags)
125+
126+
### CREATE_MINOR_VERSION_TAG
127+
マイナーバージョンタグ(例:v1.2)を作成するかどうか
128+
default: `true`
129+
[タグの詳細](#tags)
130+
131+
### OUTPUT_BUILD_INFO_FILENAME
132+
ビルド情報を出力するファイル名
133+
default: `''`
134+
絶対パスや `..` は使用できません。
135+
この設定が空でない場合、以下のような情報が出力されます。
136+
```json
137+
{
138+
"tagName": "${tagName}",
139+
"branch": "${branch}",
140+
"tags": [
141+
"${created_tag_1}",
142+
"...",
143+
"${created_tag_n}"
144+
],
145+
"updated_at": "${updated_at}"
146+
}
147+
```
148+
149+
### FETCH_DEPTH
150+
取得するコミット履歴の制限数
151+
default: `3`
152+
153+
### TEST_TAG_PREFIX
154+
テスト用タグのプリフィックス
155+
default: `''`
156+
例:`'test/'`
157+
158+
### ORIGINAL_TAG_PREFIX
159+
元のタグを残す際に付与するプリフィックス
160+
default: `''`
161+
例:`'original/'`
162+
163+
## Action イベント詳細
164+
### 対象イベント
165+
- push: *
166+
- tags
167+
- semantic versioning tag (例:`v1.2.3`)
168+
- [テストタグ](#test_tag_prefix) (例:`test/v1.2.3`)
169+
- push: rerequested
170+
171+
## 動機
172+
`GitHub Action`をリリースするには、すべてのビルドファイルと `node_modules` のような依存関係が必要ですが、通常はそれらをコミットしません。
173+
したがって`GitHub Action`リリースする際には以下のような手順が必要です。
174+
1. ローカルの開発用ブランチで開発
175+
1. リリース用にビルド
176+
1. `node_modules` のような依存モジュールを含めて必要なソースをリリース用ブランチにコミット
177+
1. タグを付与 (メジャーバージョンやマイナーバージョンの考慮が必要)
178+
1. GitHub にプッシュ
179+
1. リリースを作成
180+
181+
リリースの度にこれらの手順を実行するのはとても面倒です。
182+
183+
この `GitHub Action` を使用することで手順は単純になります。
184+
1. ローカルの開発用ブランチで開発
185+
1. リリースを作成 (タグを作成)
186+
1. 自動化された手順が完了するのを待つ
187+
1. リリース用にビルド
188+
1. `node_modules` のような依存モジュールを含めて必要なソースをリリース用ブランチにコミット
189+
1. タグを付与 (メジャーバージョンやマイナーバージョンの考慮が必要)
190+
1. GitHub にプッシュ
191+
192+
## 補足
193+
### Tags
194+
タグ名は [Semantic Versioning](https://semver.org/) に従っている必要があります。
195+
以下のタグが作成されます。
196+
- 指定されたタグ名
197+
- メジャーバージョンのタグ名 (指定されたタグ名から生成)
198+
- 例:`v1`
199+
- マイナーバージョンのタグ名 (指定されたタグ名から生成)
200+
- 例:`v1.2`
201+
202+
## このアクションを使用しているアクションの例
203+
- [Release GitHub Actions](https://github.com/technote-space/release-github-actions)
204+
- [released.yml](https://github.com/technote-space/release-github-actions/blob/master/.github/workflows/released.yml)
205+
- [Auto card labeler](https://github.com/technote-space/auto-card-labeler)
206+
- [released.yml](https://github.com/technote-space/auto-card-labeler/blob/master/.github/workflows/released.yml)
207+
- [Assign Author](https://github.com/technote-space/assign-author)
208+
- [released.yml](https://github.com/technote-space/assign-author/blob/master/.github/workflows/released.yml)
209+
- [TOC Generator](https://github.com/technote-space/toc-generator)
210+
- [released.yml](https://github.com/technote-space/toc-generator/blob/master/.github/workflows/released.yml)
211+
212+
## Author
213+
[GitHub (Technote)](https://github.com/technote-space)
214+
[Blog](https://technote.space)

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
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-
This is a GitHub Action that automates the release of GitHub Action.
9-
Once you publish the release, this action will automatically
8+
*Read this in other languages: [English](README.md), [日本語](README.ja.md).*
9+
10+
This is a `GitHub Action` that automates the release of `GitHub Action`.
11+
Once you create a new tag, this action will automatically
1012
1. Run build
1113
1. Create branch for release
1214
1. Change [tags](#tags) to release branch
@@ -37,8 +39,8 @@ Once you publish the release, this action will automatically
3739
- [Target events](#target-events)
3840
- [Motivation](#motivation)
3941
- [Addition](#addition)
40-
- [tags](#tags)
41-
- [GitHub Actions using this Action](#github-actions-using-this-action)
42+
- [Tags](#tags)
43+
- [Sample GitHub Actions using this Action](#sample-github-actions-using-this-action)
4244
- [Author](#author)
4345

4446
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -48,9 +50,9 @@ Once you publish the release, this action will automatically
4850
![Before publish release](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-1.png)
4951
1. Publish release (Create tag)
5052
![Publish release](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-2.png)
51-
1. Running GitHub Action
53+
1. Running `GitHub Action`
5254
![Running GitHub Action](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-3.png)
53-
1. After running GitHub Action
55+
1. After running `GitHub Action`
5456
![After running GitHub Action](https://raw.githubusercontent.com/technote-space/release-github-actions/images/screenshot-4.png)
5557

5658
## Installation
@@ -109,7 +111,7 @@ Commit email.
109111
default: `'[email protected]'`
110112

111113
### BRANCH_NAME
112-
Branch name for GitHub Action release.
114+
Branch name for `GitHub Action` release.
113115
default: `'gh-actions'`
114116

115117
### CLEAN_TARGETS
@@ -118,15 +120,13 @@ default: `.[!.]*,__tests__,src,*.js,*.ts,*.json,*.lock,_config.yml`
118120
Absolute path and `..` are not permitted to use.
119121

120122
### CREATE_MAJOR_VERSION_TAG
121-
Whether to create major version tag.
123+
Whether to create major version tag (e.g. v1).
122124
default: `true`
123-
Set to `false` if you do not want to create a major version tag.
124125
[Detail of tags](#tags)
125126

126127
### CREATE_MINOR_VERSION_TAG
127-
Whether to create minor version tag.
128+
Whether to create minor version tag (e.g. v1.2).
128129
default: `true`
129-
Set to `false` if you do not want to create a minor version tag.
130130
[Detail of tags](#tags)
131131

132132
### OUTPUT_BUILD_INFO_FILENAME
@@ -170,11 +170,11 @@ e.g. `'original/'`
170170
- push: rerequested
171171

172172
## Motivation
173-
Release package needs all build files and dependencies like `node_modules`, but are not usually committed.
173+
Releasing `GitHub Action` needs all build files and dependencies like `node_modules`, but are not usually committed.
174174
So if you want to release `GitHub Action`, you have to do following steps.
175175
1. Develop locally on the branch for develop
176176
1. Build for release
177-
1. Commit all source code including dependencies like `node_modules`
177+
1. Commit all source code including dependencies like `node_modules` to branch for release
178178
1. Add tags (consider major and minor versions)
179179
1. Push to GitHub
180180
1. Publish release
@@ -186,12 +186,12 @@ If you use this `GitHub Action`, the steps to do are simpler.
186186
1. Publish release (Create tag)
187187
1. Wait for the automated steps to finish
188188
1. Build for release
189-
1. Commit all source code including dependencies like `node_modules`
189+
1. Commit all source code including dependencies like `node_modules` to branch for release
190190
1. Add tags (consider major and minor versions)
191191
1. Push to GitHub
192192

193193
## Addition
194-
### tags
194+
### Tags
195195
Tag name format must be [Semantic Versioning](https://semver.org/).
196196
The following tags will be created.
197197
- tag name
@@ -200,11 +200,15 @@ The following tags will be created.
200200
- minor tag name (generated by tag name)
201201
- e.g. `v1.2`
202202

203-
## GitHub Actions using this Action
203+
## Sample GitHub Actions using this Action
204204
- [Release GitHub Actions](https://github.com/technote-space/release-github-actions)
205+
- [released.yml](https://github.com/technote-space/release-github-actions/blob/master/.github/workflows/released.yml)
205206
- [Auto card labeler](https://github.com/technote-space/auto-card-labeler)
207+
- [released.yml](https://github.com/technote-space/auto-card-labeler/blob/master/.github/workflows/released.yml)
206208
- [Assign Author](https://github.com/technote-space/assign-author)
209+
- [released.yml](https://github.com/technote-space/assign-author/blob/master/.github/workflows/released.yml)
207210
- [TOC Generator](https://github.com/technote-space/toc-generator)
211+
- [released.yml](https://github.com/technote-space/toc-generator/blob/master/.github/workflows/released.yml)
208212

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

build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"tagName":"v1.2.4","branch":"gh-actions","tags":["v1.2.4","v1","v1.2"],"updated_at":"2019-09-19T15:36:37.939Z"}
1+
{"tagName":"test/v1.3.0","branch":"gh-actions","tags":["test/v1.3.0","test/v1","test/v1.3"],"updated_at":"2019-09-20T15:59:11.936Z"}

lib/main.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
1515
const path_1 = __importDefault(require("path"));
1616
const core_1 = require("@actions/core");
1717
const github_1 = require("@actions/github");
18-
const signale_1 = __importDefault(require("signale"));
18+
const filter_github_action_1 = require("@technote-space/filter-github-action");
19+
const github_action_helper_1 = require("@technote-space/github-action-helper");
1920
const command_1 = require("./utils/command");
2021
const misc_1 = require("./utils/misc");
22+
const constant_1 = require("./constant");
23+
const { showActionInfo, getTagName } = github_action_helper_1.Utils;
2124
/**
2225
* run
2326
*/
2427
function run() {
2528
return __awaiter(this, void 0, void 0, function* () {
2629
try {
27-
const version = misc_1.getBuildVersion(path_1.default.resolve(__dirname, '..', 'build.json'));
28-
const tagName = misc_1.getTagName(github_1.context);
29-
if ('string' === typeof version) {
30-
signale_1.default.info('Version: %s', version);
31-
}
32-
signale_1.default.info('Event: %s', github_1.context.eventName);
33-
signale_1.default.info('Action: %s', github_1.context.payload.action);
34-
signale_1.default.info('Tag name: %s', tagName);
35-
if (!misc_1.isTargetEvent(github_1.context) || !misc_1.isValidTagName(tagName)) {
36-
signale_1.default.complete('This is not target event.');
30+
const logger = new github_action_helper_1.Logger();
31+
const tagName = getTagName(github_1.context);
32+
showActionInfo(path_1.default.resolve(__dirname, '..'), logger, github_1.context);
33+
if (!filter_github_action_1.isTargetEvent(constant_1.TARGET_EVENTS, github_1.context) || !misc_1.isValidTagName(tagName)) {
34+
logger.complete('This is not target event.');
3735
return;
3836
}
3937
const directories = misc_1.getReplaceDirectory();
40-
Object.keys(directories).forEach(directory => signale_1.default.info('%s: %s', directories[directory], directory));
38+
Object.keys(directories).forEach(directory => logger.info('%s: %s', directories[directory], directory));
4139
yield command_1.deploy(new github_1.GitHub(core_1.getInput('GITHUB_TOKEN', { required: true })), github_1.context);
4240
}
4341
catch (error) {

0 commit comments

Comments
 (0)