|
| 1 | +# Release GitHub Actions |
| 2 | + |
| 3 | +[](https://github.com/technote-space/release-github-actions/actions) |
| 4 | +[](https://coveralls.io/github/technote-space/release-github-actions?branch=master) |
| 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 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 | +  |
| 51 | +1. リリースを作成 (タグを作成) |
| 52 | +  |
| 53 | +1. GitHub Action 実行中 |
| 54 | +  |
| 55 | +1. GitHub Action 実行後 |
| 56 | +  |
| 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 | + |
| 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) |
0 commit comments