# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
---
loader: taskgraph.loader.transform:loader

transforms:
    - fenix_taskgraph.transforms.build:transforms
    - taskgraph.transforms.job:transforms
    - taskgraph.transforms.task:transforms

kind-dependencies:
    - toolchain


job-defaults:
    # Builds generate multiple APKs with different ABIs. For each APK described
    # by `gradlew printVariant`, an artifact will be generated. `variant` and
    # the per-apk config from `printVariant` can be used as substitutions in
    # `name` and `path`.
    apk-artifact-template:
        type: file
        name: public/build/{abi}/target.apk
        github-name: 'fenix-{version}-{abi}.apk'
        path: '/builds/worker/checkouts/vcs/app/build/outputs/apk/{gradle_build_type}/{fileName}'
    description: Build Fenix from source code.
    fetches:
        toolchain:
            - android-sdk-linux
            - android-gradle-dependencies
    run:
        using: gradlew
        use-caches: false
    run-on-tasks-for: []
    treeherder:
        kind: build
        symbol: B
        platform: android-all/opt
        tier: 1
    worker-type: b-android
    worker:
        docker-image: {in-tree: base}
        max-run-time: 7200
        chain-of-trust: true


jobs:
    debug:
        attributes:
            code-review: true
        run-on-tasks-for: [github-pull-request, github-push]
        run:
            gradle-build-type: debug
            track-apk-size: true
        treeherder:
            symbol: debug(B)

    beta-firebase:
        disable-optimization: true
        run-on-tasks-for: [github-push] # We want this on push so that we detect problem before triggering a new beta
        run:
            gradle-build-type: beta
            test-build-type: beta
        treeherder:
            symbol: beta(Bf)

    nightly-firebase:
        disable-optimization: true
        run-on-tasks-for: [github-push] # We want this on push so that we detect problem before triggering a new nightly
        run:
            gradle-build-type: nightly
            test-build-type: nightly
        treeherder:
            symbol: nightly(Bf)

    android-test-debug:
        attributes:
            code-review: true
        run-on-tasks-for: [github-pull-request, github-push]
        run:
            gradle-build-type: androidTest
        apk-artifact-template:
            # 2 differences here: "androidTest/" is added and "{gradle_build_type}" is forced to "debug"
            path: '/builds/worker/checkouts/vcs/app/build/outputs/apk/androidTest/debug/{fileName}'
        treeherder:
            symbol: debug(Bat)

    # android-test-nightly and android-test-beta, while still being debug builds, are meant to be signed
    # with the nightly/beta key. The Firebase testing infrastructure requires both the androidTest APK
    # and the APK under test to be signed with the same key. Thus, the nightly APK being signed with
    # nightly means we need an androidTest APK with the same signature.
    #
    # TODO: See if we can tweak the signing kind to make 2 signing jobs out of a single `android-test`
    # job.
    android-test-nightly:
        attributes:
            nightly: true
        apk-artifact-template:
            # 2 differences here:
            #  * "androidTest/" is added
            #  * "{gradle_build_type}" is forced to "debug"
            path: '/builds/worker/checkouts/vcs/app/build/outputs/apk/androidTest/nightly/app-nightly-androidTest.apk'
        disable-optimization: true
        run:
            gradle-build-type: androidTest
            test-build-type: nightly
        run-on-tasks-for: [github-push]
        treeherder:
            symbol: nightly(Bat)

    android-test-beta:
        apk-artifact-template:
            # 3 differences here:
            #  * "androidTest/" is added
            #  * "{gradle_build_type}" is forced to "beta"
            #  * "{fileName}" is forced to "app-beta-androidTest.apk"
            path: '/builds/worker/checkouts/vcs/app/build/outputs/apk/androidTest/beta/app-beta-androidTest.apk'
        disable-optimization: true
        run:
            gradle-build-type: androidTest
            test-build-type: beta
        run-on-tasks-for: [github-push] # We want this on push so that we detect problem before triggering a new beta
        treeherder:
            symbol: beta(Bat)

    android-test-mozillaonline:
        apk-artifact-template:
            # 3 differences here:
            #  * "androidTest/" is added
            #  * "{gradle_build_type}" is forced to "beta"
            #  * "{fileName}" is forced to "app-beta-androidTest.apk"
            path: '/builds/worker/checkouts/vcs/app/build/outputs/apk/androidTest/beta/app-beta-androidTest.apk'
        disable-optimization: true
        run:
            gradle-build-type: androidTest
            gradle-extra-options:
                - -PmozillaOnline
            test-build-type: beta
        run-on-tasks-for: [github-push] # We want this on push so that we detect problem before triggering a new beta
        treeherder:
            symbol: beta(Bat-mo)

    nightly-simulation:
        attributes:
            nightly: false
        run-on-tasks-for: [github-push]
        include-nightly-version: true
        include-shippable-secrets: true
        run:
            gradle-build-type: nightly
        treeherder:
            symbol: nightlySim(B)

    nightly:
        attributes:
            nightly: true
        include-nightly-version: true
        include-shippable-secrets: true
        run:
            gradle-build-type: nightly
            track-apk-size: true
        run-on-tasks-for: []
        treeherder:
            symbol: nightly(B)

    beta:
        attributes:
            release-type: beta
        include-release-version: true
        include-shippable-secrets: true
        filter-incomplete-translations: true
        run:
            gradle-build-type: beta
            track-apk-size: true
        treeherder:
            symbol: beta(B)

    beta-mozillaonline:
        apk-artifact-template:
            github-name: 'fenix-mozillaonline-{version}-{abi}.apk'
        attributes:
            release-type: beta
        include-release-version: true
        include-shippable-secrets: true
        filter-incomplete-translations: true
        run:
            gradle-build-type: beta
            gradle-extra-options:
                - -PmozillaOnline
        treeherder:
            symbol: beta(Bmo)

    release:
        attributes:
            release-type: release
        include-release-version: true
        include-shippable-secrets: true
        filter-incomplete-translations: true
        run:
            gradle-build-type: release
            track-apk-size: true
        treeherder:
            symbol: release(B)

    release-mozillaonline:
        apk-artifact-template:
            github-name: 'fenix-mozillaonline-{version}-{abi}.apk'
        attributes:
            release-type: release
        include-release-version: true
        include-shippable-secrets: true
        filter-incomplete-translations: true
        run:
            gradle-build-type: release
            gradle-extra-options:
                - -PmozillaOnline
        treeherder:
            symbol: release(Bmo)
