LoginSignup
3
1

More than 3 years have passed since last update.

自動生成したSandBoxテスターを自動削除する

Last updated at Posted at 2020-02-15

先日のpotatotips#68で発表した「SandBox Tester Tips」の続きです。
今回の記事を見る前に、こちらのSandBoxテスターの作成数の上限についても見ていただけるとやりたいことがよりイメージしやすいかと思います

忙しい人向け要約

SandBox Tester Tips」の要約

  • fastlaneのspaceshipによって、SandBoxテスターを生成
  • BitriseなどのCIでアプリの配布時に、SandBoxテスターも自動生成
  • 自動生成の重複を回避するため、メールアドレスは日付やCIのビルド番号を利用

SandBoxテスターの作成数の上限についての要約

  • 明確に上限数があるのかわからないが、SandBoxテスターを作りすぎるのにメリットはない

やりたいこと

SandBoxテスターの作成数の上限についてで検証したようにむやみにSandBoxテスターを自動生成をしつづけるのは良くないことがわかったので、どこかしらでSandBoxテスターを削除する必要が出てきました。

削除方針

SandBoxテスターの生成は自動なのに削除は手動という状態は避けたかったので、メールアドレスに日付を含め以下のような方針で削除を行うことを考えました。

  1. fastlaneのspaceshipでSandBoxテスターの一覧を取得
  2. 自動生成したSandBoxテスターのメールアドレスに日付が含まれているので、ある日よりも○日前に作成されたSandBoxテスターを抽出
  3. 抽出したSandBoxテスターを削除

自動削除のタイミング

あとはどのタイミングでSandBoxテスターの削除を実行するかです。

そんなに頻繁に削除をする必要性は感じなかったので、Bitriseのスケジューリングを利用して、週1単位で削除を行うfastlane actionを実行するようにしました。

サンプルコード

メールアドレスの形式例: 日付-CIビルド番号-index@test.com

e.g.

20200212-1111-1@test.com
20200212-1111-2@test.com
20200212-1111-3@test.com
.
.
.
20200212-1111-3@test.com

Fastfileのサンプル

require 'date'
require 'spaceship'

platform :ios do
  desc "1週間前よりも前に自動作成したSandboxテスターを削除する"
  lane :remove_old_sandbox_testers do
    username = "username" # you should change to your username
    password = "password" # you should change to your password

    Spaceship::Tunes.login(username, password)

    all_sandbox_testers = Spaceship::Tunes::SandboxTester.all
    old_sandbox_testers = all_sandbox_testers.filter {|sandbox_tester|

      # 自動作成したSandBoxテスターは日付がprefixになっているので抽出
      created_date_str = sandbox_tester.email.split("-").first
      if /^\d{4}\d{1,2}\d{1,2}$/.match(created_date_str) != nil then
        created_date = Date.strptime(created_date_str,'%Y%m%d')

        deletion_criteria_date = Date.today - 7
        if created_date < deletion_criteria_date then
          next(true)
        else
          next(false)
        end
      end

      next(false)
    }

    # 削除対象のSandBoxテスターが含まれる場合
    if !old_sandbox_testers.empty? then
      emails = old_sandbox_testers.map {|sandbox_tester| sandbox_tester.email }
      Spaceship::Tunes::SandboxTester.delete!(emails)
    end
  end
end

実行例

$ fastlane remove_old_sandbox_testers

このactionを実行することで、実行日よりも7日前のユーザーを削除するということが自動化されます。

まとめ

  • SandBoxテスターの生成・削除を自動化することで手作業で行っていたSandBoxテスターからの解放
  • なかなかSandBoxテスターに関連する情報がなかったので参考にしていただけるとうれしいです

関連URL

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