body method

  1. @override
String body(
  1. String path,
  2. String baseName,
  3. String className
)
override

Defines the actual body code. path is passed relative to lib, baseName is the filename, and className is the filename converted to Pascal case.

実際の本体コードを定義します。pathlibからの相対パス、baseNameにファイル名が渡され、classNameにファイル名をパスカルケースに変換した値が渡されます。

Implementation

@override
String body(String path, String baseName, String className) {
  final workingPath = workingDirectory?.difference(Directory.current);
  return """
# Build and upload your Flutter Android app.
#
# apk and aab files will be stored in Github storage. (Storage period is 1 day)
#
# The app is uploaded to GooglePlayConsole in an internal test draft.
#
# Please create a keystore for your app in advance with `katana app keystore`.
#
# Also, please create your app in Google PlayConsole, upload the aab file for the first time, and complete the app settings except for the store listing information settings.
#
# FlutterのAndroidアプリをビルドしアップロードします。
#
# apkファイルとaabファイルがGithubのストレージに保管されます。(保管期限1日)
#
# GooglePlayConsoleへアプリが内部テストのドラフトでアップロードされます。
#
# 事前に`katana app keystore`でアプリ用のキーストアを作成しておいてください。
#
# また、GooglePlayConsoleでアプリを作成し、aabファイルの初回アップロード、アプリの設定でストア掲載情報設定以外を済ませておいてください。
name: AndroidProductionWorkflow

on:
# This workflow runs when there is a push on the publish branch.
# publish branch に push があったらこの workflow が走る。
push:
  branches: [ publish ]

jobs:
# ----------------------------------------------------------------- #
# Build for Android
# ----------------------------------------------------------------- #
build_android:

  runs-on: ubuntu-latest

  defaults:
    run:
      working-directory: ${workingPath.isEmpty ? "." : workingPath}

  steps:
    # Check-out.
    # チェックアウト。
    - name: Checks-out my repository
      uses: actions/checkout@v2

    # Set up JDK 17.
    # JDK 17のセットアップ
    - name: Set up JDK 17
      uses: actions/setup-java@v4
      with:
        distribution: microsoft
        java-version: "17.0.10"

    # Install flutter.
    # Flutterのインストール。
    - name: Install flutter
      uses: subosito/flutter-action@v2
      with:
        channel: stable
        cache: true

    # Check flutter version.
    # Flutterのバージョン確認。
    - name: Run flutter version
      run: flutter --version

    # Download package.
    # パッケージのダウンロード。
    - name: Download flutter packages
      run: flutter pub get

    # Creation of the Assets folder.
    # Assetsフォルダの作成。
    - name: Create assets folder
      run: mkdir -p assets

    # Running flutter analyze.
    # Flutter analyzeの実行。
    - name: Analyzing flutter project
      run: flutter analyze

    # Running the flutter test.
    # Flutter testの実行。
    - name: Testing flutter project
      run: flutter test

    # Generate appkey.keystore from Secrets.
    # Secretsからappkey.keystoreを生成。
    - name: Create appkey.keystore
      run: echo -n \${{ secrets.ANDROID_KEYSTORE_#### REPLACE_APP_NAME #### }} | base64 -d > android/app/appkey.keystore

    # Generate service_account_key.json from Secrets.
    # Secretsからservice_account_key.jsonを生成。
    - name: Create service_account_key.json
      run: echo -n \${{ secrets.ANDROID_SERVICE_ACCOUNT_KEY_JSON_#### REPLACE_APP_NAME #### }} | base64 -d > android/service_account_key.json

    # Generate key.properties from Secrets.
    # Secretsからkey.propertiesを生成。
    - name: Create key.properties
      run: echo \${{ secrets.ANDROID_KEY_PROPERTIES_#### REPLACE_APP_NAME #### }} | base64 -d > android/key.properties

    # Generate Apk.
    # Apkを生成。
    - name: Building Android apk
      run: flutter build apk --build-number \$((\$GITHUB_RUN_NUMBER+$defaultIncrementNumber)) --release --dart-define=FLAVOR=prod

    # Generate app bundle.
    # App Bundleを生成。
    - name: Building Android AppBundle
      run: flutter build appbundle --build-number \$((\$GITHUB_RUN_NUMBER+$defaultIncrementNumber)) --release --dart-define=FLAVOR=prod

    # Upload the generated files.
    # 生成されたファイルのアップロード。
    - name: Upload apk artifacts
      uses: actions/upload-artifact@v4
      with:
        name: andoroid_apk_release
        path: ${workingPath.isEmpty ? "." : workingPath}/build/app/outputs/apk/release
        retention-days: 1

    # Upload the generated files.
    # 生成されたファイルのアップロード。
    - name: Upload aab artifacts
      uses: actions/upload-artifact@v4
      with:
        name: andoroid_aab_release
        path: ${workingPath.isEmpty ? "." : workingPath}/build/app/outputs/bundle/release
        retention-days: 1

    # Upload to Google Play Store.
    # Google Play Storeにアップロード。
    - name: Deploy to Google Play Store
      id: deploy
      uses: r0adkll/upload-google-play@v1
      with:
        track: internal
        # Change to completed after the app is released.
        # アプリをリリースした後は completed に変更してください。
        status: $status
        serviceAccountJson: ${workingPath.isEmpty ? "." : workingPath}/android/service_account_key.json
        changesNotSentForReview: ${changesNotSentForReview ? "true" : "false"}
        packageName: #### REPLACE_ANDROID_PACKAGE_NAME ####
        releaseFiles: ${workingPath.isEmpty ? "." : workingPath}/build/app/outputs/bundle/release/*.aab
""";
}