普段Bitriseを使ってiOSアプリのCIをしていて、ビルド成果物をGoogle Cloud Storageにアップロードしたりしています。
Google Cloud Storageとやり取りするにはgcloud
やgsutil
といったコマンド群を含むGoogle Cloud SDKが必要なのですが、残念ながらmacOSスタックにはインストールされていません。
Xcode14.2 macOS Venturaのスタック情報はこちら。
https://github.com/bitrise-io/bitrise.io/blob/master/system_reports/MACOS/M1/osx-xcode-14.2.x-ventura.log
本記事では、macOSスタックにGoogle Cloud SDKをインストール&キャッシュして、次回以降のビルドですぐにコマンドを使えるようにする方法をご紹介します。
Google Cloud SDKのインストール&キャッシュ
ワークフローにScriptステップを追加し、以下のスクリプトを入れておきます。
#!/usr/bin/env bash
# fail if any commands fails
set -e
# make pipelines' return status equal the last command to exit with a non-zero status, or zero if all commands exit successfully
set -o pipefail
# debug log
set -x
# write your script here
if [ ! -d $HOME/google-cloud-sdk ]; then
curl https://sdk.cloud.google.com | bash
fi
source $HOME/google-cloud-sdk/path.bash.inc
gcloud components update
次に、ワークフローにCache:Pushステップを追加し、以下のパスを入力します。
$HOME/google-cloud-sdk
これらのステップの追加により、以下の処理が行われます。
-
$HOME/google-cloud-sdk
ディレクトリがなければSDKをインストールする - SDKを最新にアップデートする
-
$HOME/google-cloud-sdk
ディレクトリをキャッシュする
私は上記ステップを加えたワークフローを毎晩ビルドするようにして、常に最新のSDKがキャッシュされた状態にしています。
こうすることで、他のワークフローではSDKをインストールする必要がなく、すぐにgsutil
等のコマンドを使用することができます。