Open wada811 opened 4 years ago
Bitrise is a CI service for mobile platforms that allows you to easily configure workflows with a GUI.
Bitrise makes it easy to set up a workflow with a GUI. Settings such as workflow can also be described in a setting file called bitrise.yml.
There are steps by Bitrise official and user community, It is common to build a workflow by selecting that step in the GUI. Because the name of the step and the input items are not known unless you set it once in the GUI, I do n’t write bitrise.yml directly, Even if it exists, it just copies the steps to other workflows.
Bitrise.yml is in Bitrise for setting up on the Bitrise website. Does not manage configuration files in the repository like other CI services.
By managing bitrise.yml version, I want to create an environment where anyone can easily change the settings so that CI / CD can be improved. The following two were necessary for that.
It can be set easily with the GUI, but I think there is something wrong with it and I want to change it back. The bitrise.yml at that point remains for each build (*), so there is nothing that can not be restored, It’s a bit cumbersome to identify the version of the build you want to revert and revert. It’s easy to get it back if it’s versioned.
* Accessing the bitrise.yml file online — Bitrise Docs
I can’t review due to the following factors, so I think Bitrise will be an easy-to-unform environment.
If you want to manage in the repository, you can manage it in the following way. Using the bitrise.yml from repository — Bitrise Docs However, this method has the following problems.
Regardless of the last problem, the benefits of Bitrise will be lost if it cannot be set in the GUI. Steps that you haven’t used aren’t practically usable and can be difficult to improve.
The method of reading and executing bitrise.yml in the repository has the above problem, I would like the settings to be done on Bitrise and executed with the settings on Bitrise. The Bitrise settings are the master, and the repository bitrise.yml is just a copy. Then you can manage the version of bitrise.yml without losing the benefits of Bitrise. The following describes the Bitrise workflow for managing bitrise.yml in the repository.
Build the following three workflows:
pr-bitrise-yml
: Check the difference of bitrise.yml regularly and send PRno-op
: Prevent normal workflow from working with the above PRmerge-bitrise-yml
: When PR is merged, the repository bitrise.yml is reflected in Bitrisepr-bitrise-yml
: Check the difference of bitrise.yml periodically and send PRThe following workflow is executed (*) periodically such as daily.
* Scheduling your builds — Bitrise Docs
no-op
: Prevent normal workflow from working with the above PRI think that some workflow is usually set to work when you commit to PR. So create a no-op workflow that does nothing, In the above PR, the trigger is set so that the no-op workflow is executed.
merge-bitrise-yml
: When PR is merged, reflect bitrise.yml of repository to BitriseThe following workflow is executed by pushing the above PR to the target branch as a trigger.
The overall workflow is as follows.
By building this flow, you can manage bitrise.yml in the repository.
@startuml
|__Bitrise__|
start
:Bitrise による定期実行;
partition pr-bitrise-yml {
:リポジトリをクローン;
:Bitrise から bitrise.yml をダウンロード;
if (差分があるか?) then (no)
:差分がない場合は終了;
end
else (yes)
:差分をコミット;
if (PR が存在するか?) then (no)
:PR 作成;
else (yes)
endif
endif
}
|#AntiqueWhite|__GitHub__|
:レビュー;
while (マージ可能か?) is (no)
:修正をコミット;
fork
|__Bitrise__|
partition no-op {
:何も実行しない;
stop
}
|__GitHub__|
fork again
:レビュー;
end fork
endwhile (yes)
:PRマージ;
|__Bitrise__|
partition merge-bitrise-yml {
:リポジトリをクローン;
if (pr-bitrise-yml で作成したブランチか?) then (yes)
:Bitrise に bitrise.yml をアップロード;
end
else (no)
:異なるブランチの場合は終了;
end
endif
}
@enduml
@startuml
|__Bitrise__|
start
:Schedule Build by Bitrise;
partition pr-bitrise-yml {
:Clone repository;
:Download bitrise.yml from Bitrise;
if (Is there a difference?) then (no)
:End if there is no difference;
end
else (yes)
:Commit the difference;
if (does PR exist?) then (no)
:Create PR;
else (yes)
endif
endif
}
|#AntiqueWhite|__GitHub__|
:Review;
while (Can merge?) is (no)
:Commit the fix;
fork
|__Bitrise__|
partition no-op {
:Do nothing;
end
}
|__GitHub__|
fork again
:Review;
end fork
endwhile (yes)
:Merge PR;
|__Bitrise__|
partition merge-bitrise-yml {
:Clone repository;
if (A branch created with pr-bitrise-yml?) then (yes)
:Upload bitrise.yml to Bitrise;
stop
else (no)
:End if different branch;
end
endif
}
@enduml
Bitrise とは
Bitrise は GUI で簡単にワークフローを設定できるモバイルプラットフォーム向けの CI サービスです。
bitrise.yml とは
GUI で簡単にワークフローを設定できる Bitrise ですが、 bitrise.yml という設定ファイルにワークフローなどの設定を記述することもできます。
bitrise.yml による設定は一般的ではない
Bitrise 公式やユーザコミュニティによるステップがあり、 そのステップを GUI で選択してワークフローを構築することが一般的です。 ステップの名称や入力項目は一度 GUI で設定してみないとわからないため、 いきなり bitrise.yml を直接記述することはなく、 あっても他のワークフローにステップをコピペするくらいです。
bitrise.yml は Bitrise にある
Bitrise のウェブサイトで設定するため bitrise.yml は Bitrise にあります。 他の CI サービスのように設定ファイルをリポジトリで管理しません。
bitrise.yml をバージョン管理したい
bitrise.yml をバージョン管理することで、 誰でも設定を変更しやすい環境を作り、CI/CD の改善が回るようにしたいです。
そのために以下の2つが必要でした。
設定を簡単に確実に元に戻せるようにする
GUI で簡単に設定できるのですが、変更して何か問題あり元に戻したい事があると思います。 ビルドごとにその時点の bitrise.yml が残っている(※)ので戻せないことはないのですが、 戻したいバージョンのビルドを特定して元に戻すのが少し面倒です。 バージョン管理されていれば元に戻すのは簡単です。
※ bitrise.ymlファイルへのオンラインアクセス - Bitrise Docs
設定変更をレビューできるようにする
以下の要因によりレビューできず、Bitrise おじさん化しやすい環境になると思います。
bitrise.yml をバージョン管理する方法
Bitrise 公式: リポジトリの bitrise.yml を読み込み実行する方法
リポジトリで管理したい場合、以下の方法で管理することができます。
Use bitrise.yml from repository - Bitrise Docs
しかし、この方法では以下の問題があります。
最後の問題はともかく、GUI で設定できないのは Bitrise のメリットが無くなってしまいます。 使ったことないステップは実質的に利用できないので改善にしくくなってしまいます。
Bitrise 公式の方法には問題がある。ではどうするか?
リポジトリの bitrise.yml を読み込み実行する方法は上記の問題があるので、 設定は Bitrise 上で行い、Bitrise 上の設定で実行して欲しいです。
Bitrise の設定をマスターとし、リポジトリの bitrise.yml は単なるコピーとします。 そうすれば Bitrise のメリットが無くならず、bitrise.yml をバージョン管理することができます。
以下で bitrise.yml をリポジトリで管理するための Bitrise ワークフローについて説明します。
bitrise.yml をリポジトリで管理する Bitrise ワークフロー
以下の3つのワークフローを構築します。
pr-bitrise-yml
: 定期的に bitrise.yml の差分をチェックして PR を送るno-op
: 上記の PR で通常のワークフローが動作しないようにするmerge-bitrise-yml
: PR がマージされたらリポジトリの bitrise.yml を Bitrise に反映する1.
pr-bitrise-yml
: 定期的に bitrise.yml の差分をチェックして PR を送る下記のワークフローを日次など定期的に実行(※)します。
※ ビルドをスケジューリングする - Bitrise Docs
2.
no-op
: 上記の PR で通常のワークフローが動作しないようにする通常、PR にコミットすると何かしらのワークフローが動作するように設定してあると思います。 そのため、何も実行しない
no-op
ワークフローを作成し、 上記の PR ではno-op
ワークフローが実行されるようにトリガーを設定します。3.
merge-bitrise-yml
: PR がマージされたらリポジトリの bitrise.yml を Bitrise に反映する上記の PR のターゲットブランチへの Push をトリガーに以下のワークフローを実行します。
ワークフロー全体イメージ
上記のワークフローの動作イメージは以下のようになります。 このフローを構築することによって bitrise.yml をリポジトリで管理することが可能となります。
Ref
Articles