format_version: "6"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: android
trigger_map:
- push_branch: develop
  workflow: nightly
- pull_request_source_branch: '*'
  workflow: primary
- tag: '*'
  workflow: release
workflows:
  nightly:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@8.0: {}
    - cache-pull@2.7: {}
    - install-missing-android-tools:
        inputs:
        - gradlew_path: $PROJECT_LOCATION/gradlew
    - change-android-versioncode-and-versionname@1.3: {}
    - gradle-runner@2:
        inputs:
        - apk_file_include_filter: '*.aab'
        - gradlew_path: ./gradlew
        - gradle_options: ""
        - gradle_task: ktlintCheck lintGreenDebug testGreenReleaseUnitTest bundleGreenRelease
    - sign-apk@1:
        inputs:
        - apk_path: $BITRISE_AAB_PATH
    - script:
        inputs:
        - content: |
            #!/usr/bin/env bash

            # write the git log to a file for the deploy step to pick up
            git log -3 --pretty=%B | head -c 500 > whatsnew-en-US
    - google-play-deploy@3.7:
        inputs:
        - apk_path: $BITRISE_SIGNED_APK_PATH
        - package_name: com.keylesspalace.tusky.test
        - track: production
        - app_path: $BITRISE_SIGNED_AAB_PATH
        - whatsnews_dir: ./
        - service_account_json_key_path: $TUSKY_SERVICE_ACC_URL
    - deploy-to-bitrise-io@2.1: {}
    - cache-push@2.7: {}
  primary:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - cache-pull@2.7: {}
    - install-missing-android-tools:
        inputs:
        - gradlew_path: $PROJECT_LOCATION/gradlew
    - gradle-runner@2:
        inputs:
        - app_file_include_filter: |-
            *.apk
            *.aab
        - app_file_exclude_filter: |2+

        - test_apk_file_include_filter: ""
        - mapping_file_include_filter: ""
        - retry_on_failure: "no"
        - gradlew_path: ./gradlew
        - gradle_options: --no-daemon
        - gradle_task: ktlintCheck lintGreenDebug
    - android-unit-test@1.0:
        inputs:
        - project_location: $PROJECT_LOCATION
        - module: app
        - variant: greenDebug
    - android-build:
        inputs:
        - variant: greenDebug
        - module: app
    - deploy-to-bitrise-io@2.1:
        inputs:
        - debug_mode: "true"
        - notify_user_groups: none
    - cache-push@2.7: {}
  release:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - cache-pull@2.7: {}
    - install-missing-android-tools@3.1:
        inputs:
        - gradlew_path: $PROJECT_LOCATION/gradlew
    - gradle-runner@2.0:
        inputs:
        - apk_file_include_filter: ""
        - gradlew_path: ./gradlew
        - gradle_task: assembleBlueRelease bundleBlueRelease
    - sign-apk:
        inputs:
        - debuggable_permitted: "false"
        - keystore_alias: $TUSKY_RELEASE_KEY_NAME
        - private_key_password: $TUSKY_RELEASE_KEY_PASSWORD
        - verbose_log: "true"
        - android_app: $BITRISE_APK_PATH|$BITRISE_AAB_PATH
        - apk_path: ""
    - deploy-to-bitrise-io@2.1:
        inputs:
        - generate_universal_apk_if_none: "false"
    - script@1:
        inputs:
        - content: |
            #!/usr/bin/env bash
            # find the newest english changelog, write it to a file for the deploy step to pick up

            changelog_file=$(ls -1 fastlane/metadata/android/en-US/changelogs | sort -V -r | head -n 1)
            cat fastlane/metadata/android/en-US/changelogs/$changelog_file >> whatsnew-en-US
    - google-play-deploy@3:
        inputs:
        - app_path: $BITRISE_AAB_PATH
        - track: internal
        - service_account_json_key_path: $TUSKY_SERVICE_ACC_URL
        - package_name: com.keylesspalace.tusky
    - cache-push@2.7: {}
app:
  envs:
  - opts:
      is_expand: false
    PROJECT_LOCATION: .
  - opts:
      is_expand: false
    MODULE: app
  - opts:
      is_expand: false
    BUILD_VARIANT: GreenDebug
  - opts:
      is_expand: false
    TEST_VARIANT: GreenDebug
meta:
  bitrise.io:
    stack: linux-docker-android-20.04
