LoginSignup
12
9

More than 3 years have passed since last update.

【Android】Github Actions と Firebase App Distribution で特定のブランチ毎にベータ配布する

Last updated at Posted at 2019-12-22

GitHub Actions

公式ページ

Firebase App Distribution

公式ページ

:computer:環境構築


事前準備

FIREBASE_APP_IDFIREBASE_TOKEN をGithub ActionsのSecret Tokenで使用するので準備しておく。

  • FIREBASE_APP_ID


    ↑Firebaseコンソールで確認できる。赤枠の部分

  • FIREBASE_TOKEN

    firebase-toolsをインストールして以下のコマンドを実施、対象のGoogleアカウトで認証するとtokenが取得できる。

    $ firebase login:ci
    

:pencil: 実装


ベータ配布用の .github/workflows/deploy.yml を作成

まずは、debugビルドでベータ配布するworkflowを作成します。
事前に準備した FIREBASE_APP_ID とは別に debug用の FIREBASE_DEV_APP_ID (application idが異なる分) を用意して使用してます。

name: deploy

on:
  push:
    branches:
    - feature/test-deploy

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Setup JDK
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Debug build
        run: ./gradlew assembleDebug
      - name: Deploy Firebase App Distribution [DEV]
        uses: wzieba/Firebase-Distribution-Github-Action@v1.1.1
        with:
          appId: ${{secrets.FIREBASE_DEV_APP_ID}}
          token: ${{secrets.FIREBASE_TOKEN}}
          groups: developer
          file: app/build/outputs/apk/debug/app-debug.apk

無事配布されるとFirebaseのコンソール上では以下の様に表示されます。

また、招待を受けたユーザーには以下の様なメールが配信されるはずです。

特定のブランチ毎に特定の処理を実施させたい場合

Github Actionsでは if で条件分岐できるので、現在のブランチを判定し処理を分岐させます。
https://help.github.com/ja/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions

例) masterブランチのみ何か処理を行う場合

name: release build
if: github.ref == 'refs/heads/master'
run: ./gradlew assembleRelease

debugビルドとreleaseビルドをそれぞれ develop ブランチ, master ブランチで行う場合の設定ファイルは以下になります。

name: deploy

on:
  push:
    branches:
      - develop
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Setup JDK
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Debug build
        if: github.ref == 'refs/heads/develop'
        run: ./gradlew assembleDebug
      - name: Release build
        if: github.ref == 'refs/heads/master'
        run: ./gradlew assembleRelease
      - name: Deploy Firebase App Distribution [DEV]
        if: github.ref == 'refs/heads/develop'
        uses: wzieba/Firebase-Distribution-Github-Action@v1.1.1
        with:
          appId: ${{secrets.FIREBASE_DEV_APP_ID}}
          token: ${{secrets.FIREBASE_TOKEN}}
          groups: developer
          file: app/build/outputs/apk/debug/app-debug.apk
      - name: Deploy Firebase App Distribution [PRO]
        if: github.ref == 'refs/heads/master'
        uses: wzieba/Firebase-Distribution-Github-Action@v1.1.1
        with:
          appId: ${{secrets.FIREBASE_APP_ID}}
          token: ${{secrets.FIREBASE_TOKEN}}
          groups: developer
          file: app/build/outputs/apk/release/app-release.apk

※ 他に良いやり方がある場合ご指摘頂けると助かります :bow:

:link: 参考になったURL


12
9
4

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
12
9