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 a Flutter IOS app.
#
# Nothing is stored in Github storage.
#
# Create a `CertificateSigningRequest.certSigningRequest` with `katana app csr` in advance and download the Apple Development Certificate.
#
# Create an AuthKey in AppStoreConnect and put the Issuer ID and Team ID in katana.yaml.
#
# Also, please make sure you have created your app in AppStoreConnect.
#
# FlutterのIOSアプリをビルドしアップロードします。
#
# Githubのストレージにはなにも保管されません。
#
# AppStoreConnectへアプリがアップロードされます。
#
# 事前に`katana app csr`で`CertificateSigningRequest.certSigningRequest`を作成し、Apple DevelopmentのCertificateをダウンロードしてください。
#
# AppStoreConnectでAuthKeyを作成し、Issuer IDとチームIDをkatana.yamlに記載しておきます。
#
# また、AppStoreConnectでアプリを作成しておいてください。
name: IOSProductionWorkflow

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

jobs:
# ----------------------------------------------------------------- #
# Build for IOS
# ----------------------------------------------------------------- #
build_ios:

  runs-on: macos-latest

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

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

    # 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

    # Updating pod files.
    # Podファイルのアップデート。
    - name: Pod file update
      run: |
        cd ios
        pod repo update
        rm Podfile.lock
        pod install
        cd ..

    # 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

    # Certificate settings.
    # Certificateの設定。
    - name: Import Apple Development Certificate
      env:
          IOS_KEYCHAIN_PASSWORD: \${{ secrets.IOS_KEYCHAIN_PASSWORD_#### REPLACE_APP_NAME #### }}
          IOS_CERTIFICATES_P12: \${{ secrets.IOS_CERTIFICATES_P12_#### REPLACE_APP_NAME #### }}
          IOS_CERTIFICATE_PASSWORD: \${{ secrets.IOS_CERTIFICATE_PASSWORD_#### REPLACE_APP_NAME #### }}
      run: |
          APPLE_DEVELOPMENT_CERTIFICATE=\$RUNNER_TEMP/development_certificate.p12
          KEYCHAIN_PATH=\$RUNNER_TEMP/app-signing.keychain-db

          # import certificate from secrets
          echo -n "\$IOS_CERTIFICATES_P12" | base64 --decode --output \$APPLE_DEVELOPMENT_CERTIFICATE

          # create temporary keychain
          security create-keychain -p "\$IOS_KEYCHAIN_PASSWORD" \$KEYCHAIN_PATH
          security set-keychain-settings -lut 21600 \$KEYCHAIN_PATH
          security unlock-keychain -p "\$IOS_KEYCHAIN_PASSWORD" \$KEYCHAIN_PATH

          # import certificate to keychain
          security import \$APPLE_DEVELOPMENT_CERTIFICATE -P "\$IOS_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k \$KEYCHAIN_PATH
          security list-keychain -d user -s \$KEYCHAIN_PATH

    # Create AppStoreConnectAPI key.
    # AppStoreConnectAPIキーを作成。
    - name: Create App Store Connect API Private Key in `pwd`/private_keys
      env:
        IOS_API_KEY_ID: \${{ secrets.IOS_API_KEY_ID_#### REPLACE_APP_NAME #### }}
        IOS_API_AUTHKEY_P8: \${{ secrets.IOS_API_AUTHKEY_P8_#### REPLACE_APP_NAME #### }}
      run: |
        mkdir `pwd`/private_keys
        echo -n "\$IOS_API_AUTHKEY_P8" | base64 --decode --output `pwd`/private_keys/AuthKey_\$IOS_API_KEY_ID.p8

    # Flutter build.
    # Flutterのビルド。
    - name: Run flutter build
      id: build
      run: flutter build ios --release --no-codesign --release --dart-define=FLAVOR=prod --build-number \$((\$GITHUB_RUN_NUMBER+$defaultIncrementNumber))

    # Archive of built data.
    # ビルドされたデータのアーカイブ。
    - name: Archive by xcodebuild
      env:
        IOS_API_ISSUER_ID: \${{ secrets.IOS_API_ISSUER_ID_#### REPLACE_APP_NAME #### }}
        IOS_API_KEY_ID: \${{ secrets.IOS_API_KEY_ID_#### REPLACE_APP_NAME #### }}
      run: xcodebuild archive -workspace ./ios/Runner.xcworkspace -scheme Runner -configuration Release -destination generic/platform=iOS -archivePath ./build/ios/Runner.xcarchive -allowProvisioningUpdates -authenticationKeyIssuerID \$IOS_API_ISSUER_ID -authenticationKeyID \$IOS_API_KEY_ID -authenticationKeyPath `pwd`/private_keys/AuthKey_\$IOS_API_KEY_ID.p8

    # Export of built archives.
    # ビルドされたアーカイブのエクスポート。
    - name: Export by xcodebuild
      env:
        IOS_API_ISSUER_ID: \${{ secrets.IOS_API_ISSUER_ID_#### REPLACE_APP_NAME #### }}
        IOS_API_KEY_ID: \${{ secrets.IOS_API_KEY_ID_#### REPLACE_APP_NAME #### }}
      run: xcodebuild -exportArchive -archivePath ./build/ios/Runner.xcarchive -exportPath ./build/ios/ipa -exportOptionsPlist ./ios/ExportOptions.plist -allowProvisioningUpdates -authenticationKeyIssuerID \$IOS_API_ISSUER_ID -authenticationKeyID \$IOS_API_KEY_ID -authenticationKeyPath `pwd`/private_keys/AuthKey_\$IOS_API_KEY_ID.p8

    # IPA file detection.
    # IPAファイルの検出。
    - name: Detect path for ipa file
      run: |
        echo "IPA_PATH=\$(find build/ios/ipa -type f -name '*.ipa')" >> \$GITHUB_ENV

    # Upload IPA files to AppStoreConnect.
    # IPAファイルのAppStoreConnectへのアップロード。
    - name: Upload to App Store Connect
      env:
        IOS_API_ISSUER_ID: \${{ secrets.IOS_API_ISSUER_ID_#### REPLACE_APP_NAME #### }}
        IOS_API_KEY_ID: \${{ secrets.IOS_API_KEY_ID_#### REPLACE_APP_NAME #### }}
      run: xcrun altool --upload-app --type ios -f \$IPA_PATH --apiKey \$IOS_API_KEY_ID --apiIssuer \$IOS_API_ISSUER_ID

    # Delete cache.
    # キャッシュの削除。
    - name: Clean up keychain and provisioning profile
      run: security delete-keychain \$RUNNER_TEMP/app-signing.keychain-db
""";
}