아요 개발 일기

[iOS] Fastlane - Slack으로 TestFlight 알림보내기 본문

iOS

[iOS] Fastlane - Slack으로 TestFlight 알림보내기

소진이 2023. 10. 26. 18:53

 

안녕하세요 @.@

이번에는 Fastlane을 이용하여

AppStoreConnect에 testFlight가 업데이트되었을때

Slack에 알람이갈 수 있도록 해보겠습니다!

 

해당부분의 자세한 설명은 공식 사이트를 참고해주세요 :)

https://docs.fastlane.tools/actions/slack/

 

slack - fastlane docs

Create an Incoming WebHook and export this as SLACK_URL. Can send a message to #channel (by default), a direct message to @username or a message to a private group group with success (green) or failure (red) status. It is recommended to add the above actio

docs.fastlane.tools

 

혹시 fastlane 설정하는 법 모르시는 분은 아래 글을 참고해주세요!

[iOS] fastlane - AppStoreConnect 자동 배포 설정하기


Slack 채널 설정하기

아래 이미지 순서에 따라서 진행해주세요!!

 

 

 

웹후크 URL -> URL 복사

 

Fastlane의 Lane 수정하기

 

프로젝트 파일 -> Fastlane -> Fastlane 누른 후 파일을 수정해서

슬랙 전송 기능을 추가해주겠습니다!

 

 

  lane :send_slack do |options| # send_slack lane에 대한 설명 정의 / |options|: 전달된 인자를 받기 위해 사용
    version = get_version_number( # get_version_number 액션으로 프로젝트의 버전 번호를 가져옴
	xcodeproj: "프로젝트명.xcodeproj",
	target: "프로젝트명"
    )
    build = get_build_number(xcodeproj: "프로젝트명.xcodeproj") # get_build_number 액션을 통해서 빌드 번호를 가져옴
    

    slack(
      message: options[:message], # Slack 메세지의 본문
      channel: "슬랙채널명",
      slack_url: "슬랙주소",
      default_payloads: [:lane, :test_result, :git_branch, :git_author], # Slack 메시지에 포함되는 기본 payload 정보 / :lane(실행된 lane 이름), :test_result(테스트 결과), :git_branch(현재 Git 브랜치), :git_author(최신 커밋 작성자)
      payload: {
        "version": version + " (" + build + ")" # Slack 메시지에 포함될 커스텀 payload 정의
      }
    ) 

   end

 

 

 

전체 코드

# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do
  desc "Push a new release build to the App Store"
  lane :release do
    increment_build_number(xcodeproj: "프로젝트명.xcodeproj")
    build_app(scheme: "프로젝트명")

    upload_to_app_store(
      force: true, # Skip HTMl report verification
      skip_metadata: true,
      skip_screenshots: true,
    )

  api_key = app_store_connect_api_key(
    key_id: "key_id값",
    issuer_id: "issuer_id값",
    key_filepath: "-",
    duration: 500,
    in_house: false
  )

    send_slack({"message": "Release 버전이 AppConnect에 성공적으로 업로드 되었습니다."})

  pilot(api_key: api_key)
  end

  lane :send_slack do |options|
    version = get_version_number(
	xcodeproj: "프로젝트명.xcodeproj", 
	target: "프로젝트명"
    )
    build = get_build_number(xcodeproj: "프로젝트명.xcodeproj") 
    

    slack(
      message: options[:message],
      channel: "ios_개발",
      slack_url: "슬랙 채널 주소",
      default_payloads: [:lane, :test_result, :git_branch, :git_author],
      payload: {
        "version": version + " (" + build + ")"
      }
    ) 

   end

  desc "Push a new beta build to TestFlight"
  lane :beta do
    increment_build_number(xcodeproj: "프로젝트명.xcodeproj")
    build_app(scheme: "프로젝트명.xcodeproj")
    upload_to_testflight(skip_submission: true, skip_waiting_for_build_processing: true)

    send_slack(message: "beta 버전이 TestFlight에 성공적으로 업로드 되었습니다.")
  end
end

 

 

Fastlane 실행하기

 

  lane :beta do 의 beta가 이름이라고 생각하시면 됩니다!

저는 beta를 실행시킬 것이기때문에

 fastlane beta  를 입력해주고 실행해줍니다

 

 

사실 그냥 fastlane ios 쳐도 괜찮아요 (platform 이름)

그러면 선택할 수 있게 이미지처럼 나와요 ㅎㅎ

 


 

 

짠! 잘 완료되었죠?!!!

 

Slack을 확인해보면 위 처럼 알림이 잘 들어오는 것을 볼 수 있습니다!!!

아주아주 유용하네요!!

혹시 변경 사항이나 틀린 부분은 댓글로 알려주시면 적극 반영하겠습니다!

오늘도 읽어주셔서 감사합니다

감기 조심하세요 ㅎㅎ :)

 

'iOS' 카테고리의 다른 글

[iOS] Fastlane - AppStoreConnect 자동 배포 설정하기  (1) 2023.10.26
[iOS] TextView에 Placeholder 구현하기  (0) 2023.07.30
[iOS] Lottie  (0) 2023.01.29
[iOS] GCD + DispatchQueue  (0) 2023.01.29
[iOS] Framework와 Library  (0) 2023.01.29