CircleCISaaS / FaaS

husky + lint-stagedでコミット時にCircleCIのyamlを検証する

CircleCIのCLIには、yamlの検証ができるcircleci config validateがあります。 これをpackage.jsonなどのlint-stagedの設定に追加してやると、.circleci/co […]

広告ここから
広告ここまで

CircleCIのCLIには、yamlの検証ができるcircleci config validateがあります。

これをpackage.jsonなどのlint-stagedの設定に追加してやると、.circleci/config.ymlを更新したときに構文エラーが出ていないか確認できます。


  "lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix"
    ],
    ".circleci/config.yml": [
      "circleci config validate"
    ]
  },

問題なければコミットできます。

% git commit -m "chore: update ci config"
husky > npm run -s precommit (node v12.9.1)

 ↓ Running tasks for *.{js,jsx,ts,tsx} [skipped]
   → No staged files match *.{js,jsx,ts,tsx}
 ✔ Running tasks for .circleci/config.yml

構文エラーがあると、コミット前にrejectされます。

% git commit -m "chore: update ci config"
husky > npm run -s precommit (node v12.9.1)

 ↓ Running tasks for *.{js,jsx,ts,tsx} [skipped]
   → No staged files match *.{js,jsx,ts,tsx}
 ❯ Running tasks for .circleci/config.yml
   ✖ circleci config validate
     →                ^
✖ circleci config validate found some errors. Please fix them and try committing again.
             
             Error: Unable to parse YAML
while scanning a simple key
in 'string', line 121, column 3:
     deploy-dev
     ^
could not find expected ':'
in 'string', line 122, column 13:
       executor: node
               ^

husky > pre-commit hook failed (add --no-verify to bypass)

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts