2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

GitHub Actions で Android アプリを手動ビルドできるようにする

Posted at

下記のようなyamlファイルをAndroidプロジェクトのリポジトリに置きます。

.github/workflows/manual-build.yml

name: Manual build

on:
  workflow_dispatch:
    inputs:
      variant:
        description: 'Build variant'
        required: true
      ref:
        description: 'branch name|tag name|commit SHA'
        required: true
        default: master

jobs:
  build:
    name: Build
    runs-on: ubuntu-18.04
    steps:
      - name: Check out
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.ref }}
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Restore gradle cache
        uses: actions/cache@v2
        with:
          path: ~/.gradle
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}-${{ hashFiles('**/*.gradle.kts') }}
      - name: Run Android Lint
        run: ./gradlew lint${{ github.event.inputs.variant }}
      - name: Run unit test
        run: ./gradlew test${{ github.event.inputs.variant }}UnitTest
      - name: Build with Gradle
        run: |
          # 署名まわり。https://qiita.com/hkusu/items/cadb572c979c4d729567 を参照
          if [[ -n '${{ secrets.KEYSTORE_BASE64 }}' ]]; then
            echo '${{ secrets.KEYSTORE_BASE64 }}' | base64 -d > release.keystore
            export KEYSTORE_PASSWORD='${{ secrets.KEYSTORE_PASSWORD }}'
            export KEY_ALIAS='${{ secrets.KEY_ALIAS }}'
            export KEY_PASSWORD='${{ secrets.KEY_PASSWORD }}'
          fi
          ./gradlew assemble${{ github.event.inputs.variant }}
      - name: Get apk path
        id: apk-path
        run: |
          path=$(find **/build/outputs/apk -name '*.apk' -type f | head -1)
          echo "::set-output name=path::$path"
      - name: Upload apk file
        uses: actions/upload-artifact@v2
        with:
          name: apk
          path: ${{ steps.apk-path.outputs.path }}

そうすると、下図のように GitHub の画面からワークフローを実行してアプリがビルドできるようになります。

スクリーンショット_2020-07-29_13_03_35.png

apk ファイルは、下図のように結果画面からダウンロードできます。

スクリーンショット_2020-07-29_13_06_24.png
2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?