6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[GitHub 奮闘記] リリースの自動化

Posted at

わたしが GitHub で開発している OSS のリリース自動化の忘備録。
自動化はしたものの、たまに実施する際に自動リリースって何してるんだっけ?と忘れがちなので書いておきます。

参考までにリポジトリのリンクです。

そもそも、みなさんどうやって GitHub リリースやってます?
こんなふうにやってるよーというコメントもお待ちしてます。

リリースの自動化

npm scripts を実行すればリリースのあれやこれやをほとんどやってくれる…

package.json
"scripts": {
    "release": "./scripts/release.sh"
  },

シェル スクリプトを作っちゃうというところがゴールですね。

リリース自動化の実体は release.sh というシェル スクリプトと gh-release という npm パッケージの組み合わせです。
依存モジュールさえインストールすればそのまま使えるのでよかったらどうぞ。

release.sh
# config
VERSION=$(node --eval "console.log(require('./package.json').version);")
NAME=$(node --eval "console.log(require('./package.json').name);")

# build and test
npm test || exit 1

# checkout temp branch for release
git checkout -b gh-release

# run prepublish to build files
npm run prepublish

# force add files
git add dist -f

# commit changes with a versioned commit message
git commit -m "build $VERSION"

# push commit so it exists on GitHub when we run gh-release
git push upstream gh-release

# create a ZIP archive of the dist files
zip -r $NAME-v$VERSION.zip dist

# run gh-release to create the tag and push release to github
gh-release --assets $NAME-v$VERSION.zip

# checkout master and delete release branch locally and on GitHub
git checkout master
git branch -D gh-release
git push upstream :gh-release

# publish release on NPM
npm publish

シェルの内容はざっとこんな感じ。

  1. # config
    • バージョン番号とプロジェクト名の取得
  2. # build and test
    • テスト スクリプトの実行 (Karma と mocha による簡単なテストです)
  3. # checkout temp branch for release
    • リリース用のテンポラルなブランチ (gh-release) を作成&チェックアウト
  4. # run prepublish to build files
    • npm prebuild = mkdirp dist です
    • ビルド ファイルを配置する dist ディレクトリを作成
  5. # force add files
    • dist ディレクトリは .gitignore の対象
    • 強制的に dist ディレクトリを含めます
  6. # commit changes with a versioned commit message
    • ビルド ファイルをコミット
    • コミット名:build [バージョン番号]
  7. # push commit so it exists on GitHub when we run gh-release
    • GitHub (リモート リポジトリ) にプッシュ
  8. # create a ZIP archive of the dist files
    • dist ディレクトリ内のファイル群を zip 化
  9. # run gh-release to create the tag and push release to github
    • gh-release コマンドで自動リリース
    • GitHub のリリース タグ作成
    • zip アーカイブのプッシュ
  10. # checkout master and delete release branch locally and on GitHub
    • master ブランチにチェックアウト
    • gh-release ブランチの削除 (ローカルと GitHub 両方)
  11. # publish release on NPM
    • npm publish

gh-release

GitHub リリースのための npm パッケージです。

Github Releases API を使って GitHub リリースを CLI から実施できます。
しかも CHANGELOG.md に更新内容を記述すると、リリース内容に自動で転載してくれます。

お試しあれ~。

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?