0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【GitHub Actions × Windows Self-hosted Runner】Git Bashのパス変換でハマった話と解決方法まとめ

Last updated at Posted at 2025-03-19

はじめに:この記事でわかること

この記事では、GitHub Actions の Self-hosted Runner(Windows)上で Git Bash のパス変換による不具合に遭遇した際の対処方法を、実際の事例ベースでわかりやすく解説します。

「aws s3 cp が突然Segmentation fault!?」「でもLinux runnerでは問題ない…」そんなときの原因とベストプラクティスをまとめました。


背景と課題:Git Bash の自動パス変換は善か悪か?

Git Bash は Windows 環境でも UNIX ライクな操作を提供してくれる便利ツールですが、一方で 「自動パス変換」という罠が存在します。

例:

/my/path → C:\my\path 

# 勝手に変換される:
#  (1)ドライブレターC:がつく
#  (2)スラッシュがバックスラッシュに)

特に aws, docker, kubectl など WindowsネイティブのCLI に引数が渡る場合、この変換が原因で クラッシュや想定外の動作を招くことがあります。


発生した問題・エラーログ:Segmentation faultの正体

実際のGitHub Actionsジョブの例:

- name: Upload artifacts to S3
  shell: bash
  env:
    ARTIFACT_TOP_PATH: ./tmp
    S3_ARTIFACT_PATH: s3://{target-bucket}/{target-folder}
  run: |
    echo "S3_ARTIFACT_PATH: $S3_ARTIFACT_PATH"
    aws s3 cp $ARTIFACT_TOP_PATH $S3_ARTIFACT_PATH --recursive

エラーログ(一部抜粋):

Segmentation fault      aws s3 cp $ARTIFACT_TOP_PATH $S3_ARTIFACT_PATH --recursive

Linux runnerでは発生せず、Windows Self-hosted Runnerでのみ発生 → Git Bashのパス変換が主犯格でした。


解決方法:MSYS_NO_PATHCONVで自動変換を抑制!

対策コード:

- name: Upload artifacts to S3
  shell: bash
  env:
    ARTIFACT_TOP_PATH: ./tmp
    S3_ARTIFACT_PATH: s3://{target-bucket}/{target-folder}
  run: |
    export MSYS_NO_PATHCONV=1
    aws s3 cp $ARTIFACT_TOP_PATH $S3_ARTIFACT_PATH --recursive

解説ポイント:

  • MSYS_NO_PATHCONV=1 を設定することで、Git Bash の「自動パス変換」をオフにできます。
  • Git Bash 特有の挙動を無効化し、aws CLI に正しいパスが渡るようになります。

補足Tips:PATH更新と変換無効化を前処理で自動化

より堅牢な環境整備のため、Windowsランナーかどうかを判定し、PATHを再読み込み&MSYS_NO_PATHCONVを自動設定する前処理も有効です。

実践コード例:

- name: Tweaks for Windows Self-Hosted Runners if needed
  shell: bash
  run: |
    echo " === Step 1: Check OS ==="
    if [ "$OS" = "Windows_NT" ]; then
      echo "[IMPORTANT] This is Windows runner. Adding some magic dust now"
      echo " === Step 2: Invalidate Auto PATH translation ==="
      export MSYS_NO_PATHCONV=1
    else
      echo "=== Step [SKIP]: This is not Windows runner."
    fi

まとめ:WindowsランナーではMSYS_NO_PATHCONVをデフォルトで使おう!

  • Git Bash のパス変換は便利な反面、ネイティブCLIツールと組み合わせるとバグの温床になりやすいです。
  • 特に GitHub Actions の Self-hosted Runner(Windows) では、MSYS_NO_PATHCONV=1 をセットしておくのがベストプラクティスです。
  • 最初からこの対策を入れておくことで、想定外のクラッシュを未然に防ぐことができます。

参考リンク

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?