|
| 1 | +# Release GitHub Actions |
| 2 | + |
| 3 | +[](https://github.com/technote-space/release-github-actions/actions) |
| 4 | +[](https://codecov.io/gh/technote-space/release-github-actions) |
| 5 | +[](https://www.codefactor.io/repository/github/technote-space/release-github-actions) |
| 6 | +[](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 Actions` のリリースを自動化するための `GitHub Actions` です。 |
| 11 | +タグを作成するとこのアクションは自動で以下を行います。 |
| 12 | +1. ビルド実行 |
| 13 | +1. リリース用ブランチ作成 |
| 14 | +1. リリース用ブランチに[タグ](#tags)を張り替え |
| 15 | +1. 同じタグ名 かつ 公開済みのリリースが存在する場合、再度公開 (タグを張り替えた場合、リリースが下書き状態になるため) |
| 16 | + |
| 17 | +## Table of Contents |
| 18 | + |
| 19 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 20 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 21 | +<details> |
| 22 | +<summary>Details</summary> |
| 23 | + |
| 24 | +- [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95) |
| 25 | +- [CLI ツール](#cli-%E3%83%84%E3%83%BC%E3%83%AB) |
| 26 | +- [スクリーンショット](#%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) |
| 27 | +- [オプション](#%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3) |
| 28 | +- [Execute commands](#execute-commands) |
| 29 | + - [ビルド](#%E3%83%93%E3%83%AB%E3%83%89) |
| 30 | + - [ファイル削除](#%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%89%8A%E9%99%A4) |
| 31 | +- [Action イベント詳細](#action-%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E8%A9%B3%E7%B4%B0) |
| 32 | + - [対象イベント](#%E5%AF%BE%E8%B1%A1%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88) |
| 33 | + - [condition](#condition) |
| 34 | +- [動機](#%E5%8B%95%E6%A9%9F) |
| 35 | +- [補足](#%E8%A3%9C%E8%B6%B3) |
| 36 | + - [Tags](#tags) |
| 37 | +- [このアクションを使用しているアクションの例](#%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) |
| 38 | +- [Author](#author) |
| 39 | + |
| 40 | +</details> |
| 41 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 42 | + |
| 43 | +## 使用方法 |
| 44 | +例:`.github/workflows/release.yml` |
| 45 | +```yaml |
| 46 | +#on: |
| 47 | +# push: |
| 48 | +# tags: |
| 49 | +# - "v*" |
| 50 | + |
| 51 | +on: create |
| 52 | + |
| 53 | +name: Release |
| 54 | +jobs: |
| 55 | + release: |
| 56 | + name: Release GitHub Actions |
| 57 | + runs-on: ubuntu-latest |
| 58 | + steps: |
| 59 | + - uses: technote-space/release-github-actions@v5 |
| 60 | +``` |
| 61 | +
|
| 62 | +[対象イベントの詳細](#action-%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E8%A9%B3%E7%B4%B0) |
| 63 | +
|
| 64 | +## CLI ツール |
| 65 | +[](https://github.com/technote-space/release-github-actions-cli) |
| 66 | +
|
| 67 | +## スクリーンショット |
| 68 | + |
| 69 | +
|
| 70 | +## オプション |
| 71 | +| name | description | default | required | e.g. | |
| 72 | +|:---:|:---|:---:|:---:|:---:| |
| 73 | +| BUILD_COMMAND | ビルド用コマンド<br>[コマンドの詳細](#execute-commands) | | | `yarn build:all` | |
| 74 | +| CLEAN_TARGETS | リリース前に掃除するファイルやディレクトリ (カンマ区切り)<br>絶対パスや `..` は使用できません<br>[コマンドの詳細](#execute-commands) |`.[!.]*,__tests__,docs,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml` | true | `.[!.]*,*.txt` | |
| 75 | +| PACKAGE_MANAGER | 依存関係のインストールに使用するパッケージマネージャー<br>`yarn.lock` や `package-lock.json` がある場合は自動で使用するパッケージマネージャーを決定しますが、このオプションで強制することができます<br>(`npm` または `yarn`) | | | `yarn` | |
| 76 | +| COMMIT_MESSAGE | コミット時に設定するメッセージ | `feat: build for release` | true | `feat: release` | |
| 77 | +| COMMIT_NAME | コミット時に設定する名前 | `github-actions[bot]` | true | | |
| 78 | +| COMMIT_EMAIL | コミット時に設定する名前 | `41898282+github-actions[bot]@users.noreply.github.com` | true | | |
| 79 | +| BRANCH_NAME | GitHub Actions 用のブランチ名 | `releases/${MAJOR}` | true | `releases/${MINOR}`, `releases/${PATCH}` | |
| 80 | +| BUILD_COMMAND_TARGET | ビルド用コマンド検索ターゲット | `build, production, prod, package, pack` | | `compile` | |
| 81 | +| CREATE_MAJOR_VERSION_TAG | メジャーバージョンタグ(例:v1)を作成するかどうか<br>[タグの詳細](#tags) | `true` | | `false` | |
| 82 | +| CREATE_MINOR_VERSION_TAG | マイナーバージョンタグ(例:v1.2)を作成するかどうか<br>[タグの詳細](#tags) | `true` | | `false` | |
| 83 | +| CREATE_PATCH_VERSION_TAG | パッチバージョンタグ(例:v1.2.3)を作成するかどうか<br>[タグの詳細](#tags) | `true` | | `false` | |
| 84 | +| FETCH_DEPTH | 取得するコミット履歴の制限数 | `3` | | `5` | |
| 85 | +| TEST_TAG_PREFIX | テスト用タグのプリフィックス | | | `test/` | |
| 86 | +| CLEAN_TEST_TAG | テストタグを掃除するかどうか | `false` | | `true` | |
| 87 | +| ORIGINAL_TAG_PREFIX | 元のタグを残す際に付与するプリフィックス | | | `original/` | |
| 88 | +| GITHUB_TOKEN | アクセストークン | `${{github.token}}` | true | `${{secrets.ACCESS_TOKEN}}` | |
| 89 | + |
| 90 | +## Execute commands |
| 91 | +### ビルド |
| 92 | +- `build`、 `production`、 `prod`、 `package` または `pack` が package.json の scripts に含まれる場合、ビルド用のコマンドとしてそれらを使用します。([BUILD_COMMAND_TARGET](#%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3) で変更可能です) |
| 93 | +- `npm run install` や `yarn install` のようなインストール用コマンドが存在しない場合、インストール用コマンドが追加されます。 |
| 94 | + |
| 95 | +したがって、`BUILD_COMMAND` が設定されていない かつ package.json に `build` が存在する場合、以下のコマンドが実行されます。 |
| 96 | + |
| 97 | +```shell |
| 98 | +yarn install |
| 99 | +yarn build |
| 100 | +yarn install --production |
| 101 | +``` |
| 102 | + |
| 103 | +`build` と `pack` が含まれる場合は、以下のコマンドになります。 |
| 104 | + |
| 105 | +```shell |
| 106 | +yarn install |
| 107 | +yarn build |
| 108 | +yarn pack |
| 109 | +yarn install --production |
| 110 | +``` |
| 111 | + |
| 112 | +### ファイル削除 |
| 113 | +`GitHub Actions` の実行には「ビルドに使用するソース」や「テストファイル」、「テストの設定」などを必要としません。 |
| 114 | +そして `GitHub Actions` は使用されるたびにダウンロードされるため、ファイルは少ないほうが良いです。 |
| 115 | + |
| 116 | +`CLEAN_TARGETS` オプションはこの目的のために使用されます。 |
| 117 | +default: `.[!.]*,__tests__,docs,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml` |
| 118 | + |
| 119 | +```shell |
| 120 | +rm -rdf .[!.]* |
| 121 | +rm -rdf *.js |
| 122 | +rm -rdf *.ts |
| 123 | +rm -rdf *.json |
| 124 | +rm -rdf *.lock |
| 125 | +rm -rdf *.yml |
| 126 | +rm -rdf *.yaml |
| 127 | +rm -rdf __tests__ docs src |
| 128 | +``` |
| 129 | + |
| 130 | +(action.yml は削除の対象ではありません) |
| 131 | + |
| 132 | +このデフォルト値は「TypeScriptのActionテンプレート」や「JavaScriptのActionテンプレート」の使用を想定した値になっています。 |
| 133 | +https://github.com/actions/typescript-action |
| 134 | +https://github.com/actions/javascript-action |
| 135 | + |
| 136 | +ただし上記テンプレートにはセキュリティ上の問題などがあるため、以下の対応が必要です。 |
| 137 | + |
| 138 | +#### JavaScriptのActionテンプレート |
| 139 | + |
| 140 | +プルリクエストにビルドしたファイルが含まれる場合、悪意のあるコードが埋め込まれていてもレビューで見逃す可能性が高いため、`.gitignore` を次のように修正する必要があります。 |
| 141 | + |
| 142 | +`.gitignore` |
| 143 | +```diff |
| 144 | ++ /dist |
| 145 | +``` |
| 146 | + |
| 147 | +#### TypeScriptのActionテンプレート |
| 148 | + |
| 149 | +`ncc` による処理は不要なため、コマンド及びパッケージを削除し `tsc` でビルドされたスクリプトを使用するように修正します。 |
| 150 | + |
| 151 | +`action.yml` |
| 152 | +```diff |
| 153 | + name: 'Your name here' |
| 154 | + description: 'Provide a description here' |
| 155 | + author: 'Your name or organization here' |
| 156 | + inputs: |
| 157 | + myInput: # change this |
| 158 | + description: 'input description here' |
| 159 | + default: 'default value if applicable' |
| 160 | + runs: |
| 161 | + using: 'node12' |
| 162 | +- main: 'dist/index.js' |
| 163 | ++ main: 'lib/main.js' |
| 164 | +``` |
| 165 | + |
| 166 | +`package.json` |
| 167 | +```diff |
| 168 | + "scripts": { |
| 169 | + "build": "tsc", |
| 170 | + "format": "prettier --write **/*.ts", |
| 171 | + "format-check": "prettier --check **/*.ts", |
| 172 | + "lint": "eslint src/**/*.ts", |
| 173 | +- "pack": "ncc build", |
| 174 | +- "test": "jest", |
| 175 | +- "all": "npm run build && npm run format && npm run lint && npm run pack && npm test" |
| 176 | ++ "test": "jest" |
| 177 | + }, |
| 178 | +``` |
| 179 | + |
| 180 | +```diff |
| 181 | + "devDependencies": { |
| 182 | + "@types/jest": "^24.0.23", |
| 183 | + "@types/node": "^12.7.12", |
| 184 | + "@typescript-eslint/parser": "^2.8.0", |
| 185 | +- "@zeit/ncc": "^0.20.5", |
| 186 | + "eslint": "^5.16.0", |
| 187 | + "eslint-plugin-github": "^2.0.0", |
| 188 | + "eslint-plugin-jest": "^22.21.0", |
| 189 | + "jest": "^24.9.0", |
| 190 | + "jest-circus": "^24.9.0", |
| 191 | + "js-yaml": "^3.13.1", |
| 192 | + "prettier": "^1.19.1", |
| 193 | + "ts-jest": "^24.2.0", |
| 194 | + "typescript": "^3.6.4" |
| 195 | + } |
| 196 | +``` |
| 197 | + |
| 198 | +または、私が作成したテンプレートを使用してください。 |
| 199 | + |
| 200 | +[](https://github.com/technote-space/gh-actions-template) |
| 201 | + |
| 202 | + |
| 203 | +不要なファイルが削除された`GitHub Actions`の例は以下で確認できます。 |
| 204 | +https://github.com/technote-space/release-github-actions/tree/gh-actions |
| 205 | + |
| 206 | +## Action イベント詳細 |
| 207 | +### 対象イベント |
| 208 | +| eventName: action | condition | |
| 209 | +|:---:|:---:| |
| 210 | +|push: *|[condition](#condition)| |
| 211 | +|release: published|[condition](#condition)| |
| 212 | +|create: *|[condition](#condition)| |
| 213 | +### condition |
| 214 | +- tags |
| 215 | + - semantic versioning tag (例:`v1.2.3`) |
| 216 | + - [テストタグ](#%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3) (例:`test/v1.2.3`) |
| 217 | + |
| 218 | +## 動機 |
| 219 | +`GitHub Actions`をリリースするには、すべてのビルドファイルと `node_modules` のような依存関係が必要ですが、通常はそれらをコミットしません。 |
| 220 | +したがって`GitHub Actions`リリースする際には以下のような手順が必要です。 |
| 221 | +1. ローカルの開発用ブランチで開発 |
| 222 | +1. リリース用にビルド |
| 223 | +1. `node_modules` のような依存モジュールを含めて必要なソースをリリース用ブランチにコミット |
| 224 | +1. タグを付与 (メジャー、マイナー、パッチバージョンの考慮が必要) |
| 225 | +1. GitHub にプッシュ |
| 226 | +1. リリースを作成 |
| 227 | + |
| 228 | +リリースの度にこれらの手順を実行するのはとても面倒です。 |
| 229 | + |
| 230 | +この `GitHub Actions` を使用することで手順は単純になります。 |
| 231 | +1. ローカルの開発用ブランチで開発 |
| 232 | +1. リリースを作成 (タグを作成) |
| 233 | +1. 自動化された手順が完了するのを待つ |
| 234 | + 1. リリース用にビルド |
| 235 | + 1. `node_modules` のような依存モジュールを含めて必要なソースをリリース用ブランチにコミット |
| 236 | + 1. タグを付与 (メジャー、マイナー、パッチバージョンの考慮が必要) |
| 237 | + 1. GitHub にプッシュ |
| 238 | + |
| 239 | +## 補足 |
| 240 | +### Tags |
| 241 | +タグ名は [Semantic Versioning](https://semver.org/) に従っている必要があります。 |
| 242 | +以下のタグが作成されます。 |
| 243 | +- 指定されたタグ名 |
| 244 | +- メジャーバージョンのタグ名 (指定されたタグ名から生成) |
| 245 | + - 例:`v1` |
| 246 | +- マイナーバージョンのタグ名 (指定されたタグ名から生成) |
| 247 | + - 例:`v1.2` |
| 248 | +- パッチバージョンのタグ名 (指定されたタグ名から生成) |
| 249 | + - 例:`v1.2.3` |
| 250 | + |
| 251 | +## このアクションを使用しているアクションの例 |
| 252 | +- [Release GitHub Actions](https://github.com/technote-space/release-github-actions) |
| 253 | + - [ci.yml](https://github.com/technote-space/release-github-actions/blob/master/.github/workflows/ci.yml) |
| 254 | +- [Auto card labeler](https://github.com/technote-space/auto-card-labeler) |
| 255 | + - [ci.yml](https://github.com/technote-space/auto-card-labeler/blob/master/.github/workflows/ci.yml) |
| 256 | +- [Assign Author](https://github.com/technote-space/assign-author) |
| 257 | + - [ci.yml](https://github.com/technote-space/assign-author/blob/master/.github/workflows/ci.yml) |
| 258 | +- [TOC Generator](https://github.com/technote-space/toc-generator) |
| 259 | + - [ci.yml](https://github.com/technote-space/toc-generator/blob/master/.github/workflows/ci.yml) |
| 260 | +- [Package Version Check Action](https://github.com/technote-space/package-version-check-action) |
| 261 | + - [ci.yml](https://github.com/technote-space/package-version-check-action/blob/master/.github/workflows/ci.yml) |
| 262 | +- [Get Diff Action](https://github.com/technote-space/get-diff-action) |
| 263 | + - [ci.yml](https://github.com/technote-space/get-diff-action/blob/master/.github/workflows/ci.yml) |
| 264 | +- [Create Project Card Action](https://github.com/technote-space/create-project-card-action) |
| 265 | + - [ci.yml](https://github.com/technote-space/create-project-card-action/blob/master/.github/workflows/ci.yml) |
| 266 | +- [Get git comment action](https://github.com/technote-space/get-git-comment-action) |
| 267 | + - [ci.yml](https://github.com/technote-space/get-git-comment-action/blob/master/.github/workflows/ci.yml) |
| 268 | +- [PR Commit Body Action](https://github.com/technote-space/pr-commit-body-action) |
| 269 | + - [ci.yml](https://github.com/technote-space/pr-commit-body-action/blob/master/.github/workflows/ci.yml) |
| 270 | +- [WP Version Check Action](https://github.com/technote-space/wp-version-check-action) |
| 271 | + - [ci.yml](https://github.com/technote-space/wp-version-check-action/blob/master/.github/workflows/ci.yml) |
| 272 | + |
| 273 | +## Author |
| 274 | +[GitHub (Technote)](https://github.com/technote-space) |
| 275 | +[Blog](https://technote.space) |
0 commit comments