Brendan Dash

Brendan Dash

WindowsのGitでは、改行コードをLFに設定します。

原因#

Debbl/eslint-config のテストを書いている間に問題が発生しました。

await Promise.all(
  files.map(async (file) => {
    let content = await fs.readFile(join(target, file), "utf-8");
    const source = await fs.readFile(join(from, file), "utf-8");

    if (content === source) {
      content = "// 変更なし\n";
    }

    await expect.soft(content).toMatchFileSnapshot(join(output, file));
  }),
);

GitHub アクションでは、複数のシステムでテストを実行しています。

strategy:
  matrix:
    node: [lts/*]
    os: [ubuntu-latest, windows-latest, macos-latest]
  fail-fast: false

しかし、Windows でのテスト実行時に常にエラーが発生し、testで入力と出力が一致しないと表示されます。テストの後、問題は Windows のデフォルトの git ダウンロード時にeolcrlfに設定されていることがわかりました。

そのため、GitHub アクションでeollfに設定する方法を調べました actions/checkout#135

最終的に、以下のコマンドを追加しました ci.yml

Windows では、次のコマンドでlfに設定できます。

git config --global core.autocrlf false
git config --global core.eol lf
- name: Set git to use LF
  run: |
    git config --global core.autocrlf false
    git config --global core.eol lf

.gitattributes で設定する方法#

* text=auto eol=lf

引用#

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。