0
1

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.

【Swift】BitriseでSwiftformatが失敗し、それを成功させるまで

Posted at

概要

SwiftFormatを導入したは良いけど、ローカルでは成功するがBitriseでなかなか成功してくれなかった話。

エラー内容

error: File not found at /Users/vagrant/git/modified:.

まず、SwiftFormatをどの様に導入したか

Cocoapodsでインストールし、 Build PhasesDependencies の直後にSwiftFormatを以下の様に設定しました。

SwiftFormat_before.sh
Pods/SwiftFormat/CommandLineTool/swiftformat `git status | egrep 'new file|modified'` [options...]

解決策

SwiftFormat_after.sh
for file in $(git diff --name-status | cut -f 2 | grep 'swift'); do
  Pods/SwiftFormat/CommandLineTool/swiftformat $file [options...]
done

残っている問題点

git diff だと新規追加ファイルが対象にならないのでこれを解決する方法を考えないとです。

色々

git status の出力は

$ git status
modified:       aaa/bbb/ccc.swift

となります。
この空白で区切られた二つの文字列がswiftformatコマンドの引数として渡ってしまい、 modified: なんてないよと怒られてました。
解決策としては、対象ファイル検索コマンドを正しく実行し、その内容を引数として渡す様にしてやればうまく行きました。
よくよく考えれば当たり前や。。。

備考

とはいえ、CIでSwiftFormatを実行する必要はないので、CIでは実行しないみたいに出来ればもっと良いなぁと思ったり。
そんな方法を知ってる方がいたらコメントなどで教えていただけると嬉しいです。

誰かのお役に立てば。

参考にしたサイト

https://pod.hatenablog.com/entry/2019/09/04/081801
https://www.yoheim.net/blog.php?q=20160302

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?