LoginSignup
33
21

More than 5 years have passed since last update.

AppVeyor で Node.js を CI する

Last updated at Posted at 2014-11-13

AppVeyor とは?

AppVeyor は OS に Windows を使っていることを特徴とした CI (継続的インテグレーション) サービスです。Travis CI と同じように、オープンソースプロジェクトでは、無料で使用できます。

Node.js とは

サーバーサイド JavaScript 環境の一つで、公式に Windows 環境での動作がサポートされています。node-gyp を用いた、ネイティブモジュールのコンパイルも利用できます (コンパイラとしては、Visual C++ が使われます。)。

なぜ、Windows で Node.js を CI するのか ?

オープンソースプロジェクトでは、Node.js の CI として、Travis CI が一般に使われています。Travis CI は Linux (Ubuntu) で動作しており、apt-get や Xvfb も利用でき、CI としては十分です。

しかし、プロジェクトの開発者は、Unix 系 OS を利用している人だけとは限りません。ネイティブモジュールの中には、Windows では正常に動作しないものもあります。そのような事態を、Windows でも並行して CI することにより、未然に防ぐことができます。

AppVeyor の特徴

  • オープンソースプロジェクト 無料
  • GitHub 連携が可能
  • appveyor.yml にビルドスクリプト記述し実行
  • Windows 系 OS (Windows Server 2012)
  • 管理者権限 (Administrators グループ) を持つユーザーで動作
  • Ruby, Python など、標準でインストール (ソフトウェア一覧)
  • Selenium (IE, Firefox, Chrome) を標準でインストール
    • Internet Explorer での自動テストが可能
  • Chocolatey が利用可能 (Windows 版パッケージマネージャー)
    • 必要なソフトウェアをコマンドから簡単にインストール可能

AppVeyor の利用方法

まず、AppVeyor に GitHub アカウントでサインアップし、有効にします。そして、appveyor.yml を対象のリポジトリに配置すれば OK です。

appveyor.yml サンプル

実際に動作する appveyor.yml のサンプルを以下に載せます。

# appveyor file
# http://www.appveyor.com/docs/appveyor-yml

install:
  # Update Node.js
  # 標準で入っている Node.js を更新します (2014/11/13 時点では、v0.10.32 が標準)
  - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)
  - node --version

  # Update NPM
  - npm install -g npm
  - npm --version

  # Update node-gyp
  # 必須! node-gyp のバージョンを上げないと、ネイティブモジュールのコンパイルに失敗します
  - npm install -g node-gyp

  # Install dependencies & devDependencies
  # Visual Studio のバージョンを指定しないとコンパイルが通らない場合あり
  - npm install --build-from-source --msvs_version=2013

  # 以下は、プロジェクトに合わせてください
  # 例として、パッケージ管理に bower, ビルドツールに grunt を用いている場合

  # Install build tools
  - npm install -g grunt-cli bower
  - grunt --version
  - bower --version

  # Install bower packages
  - bower install

  # Build
  - grunt build

test_script:
# テスト用のコマンドを指定します
  - npm test

environment:
  matrix:
    - nodejs_version: 0.10

init:
# git clone の際の改行を変換しないようにします
  - git config --global core.autocrlf false

branches:
# ビルドするブランチを制限する場合に記述します
  only:
    - master
  except:
    - gh-pages

build: off
deploy: off

参考: Testing with Node.js and io.js - Appveyor

注意点など

  • コマンドは、cmd.exe 経由で実行されます。ps: と行頭に付けた場合、PowerShell 経由で実行されます。
  • Unix 環境で用いている & (バックグラウンド実行) などは Windows では利用できないので、注意してください。

その他

AppVeyor はビルドまでの時間、ビルドの時間が Travis CI と比較すると著しく遅いです。そのため、ビルドするブランチを master, develop に絞ったり、他の CI と併用するなどして利用することをオススメします。

33
21
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
33
21