# 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/.
---
task-defaults:
    platform: linux2404-64/opt
    worker-type: t-linux-docker-amd
    worker:
        docker-image: {in-tree: "ubuntu2404-test"}
        max-run-time: 1800
    treeherder:
        kind: test
        tier: 1
    run-on-repo-type: [hg]
    run:
        using: run-task
        cwd: '{checkout}'
        use-caches: [checkout, npm]

newtab-unit-tests:
    description: newtab unit tests
    treeherder:
        symbol: node(newtab)
    require-build:
        by-project:
            autoland:
                linux2404-64/opt: build-linux64/opt
            try:
                linux2404-64/opt: build-linux64/opt
            default:
                linux2404-64/opt: build-linux64-shippable/opt
    fetches:
        build:
            - target.tar.xz
        toolchain:
            - linux64-node
            - node-modules
            - newtab-node-modules
    run:
        command: >
            cd /builds/worker/checkouts/gecko &&
            cp -r $MOZ_FETCHES_DIR/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/extensions/newtab &&
            cp -r $MOZ_FETCHES_DIR/newtab/node_modules node_modules &&
            FIREFOX_BIN=$MOZ_FETCHES_DIR/firefox/firefox PATH=$PATH:$MOZ_FETCHES_DIR/node/bin node bin/try-runner.js
    when:
        files-changed:
            - "browser/extensions/newtab/**"

newtab-unit-tests-ccov:
    description: newtab unit tests code coverage
    treeherder:
        symbol: node(newtab-ccov)
    worker:
        artifacts:
            - name: public/code-coverage-grcov.zip
              path: /builds/worker/checkouts/gecko/browser/extensions/newtab/logs/coverage/code-coverage-grcov.zip
              type: file
    require-build:
        by-project:
            try:
                linux2404-64/opt: build-linux64/opt
            default:
                linux2404-64/opt: build-linux64-shippable/opt
    fetches:
        build:
            - target.tar.xz
        toolchain:
            - linux64-node
            - node-modules
            - newtab-node-modules
    run:
        command: >
            cd /builds/worker/checkouts/gecko &&
            cp -r $MOZ_FETCHES_DIR/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/extensions/newtab &&
            cp -r $MOZ_FETCHES_DIR/newtab/node_modules node_modules &&
            FIREFOX_BIN=$MOZ_FETCHES_DIR/firefox/firefox PATH=$PATH:$MOZ_FETCHES_DIR/node/bin node bin/try-runner.js
    # This should only run on mozilla-central, as the bot will only parse mozilla-central
    # coverage anyways.
    run-on-projects: ["mozilla-central"]
    # Note the lack of a "when" rule here. This is to avoid seeing fluctuating
    # coverage on coverage.moz.tools / searchfox depending on whether the latest
    # push contained patches touching these files or not.

messagingsystem-unit-tests:
    description: messagingsystem unit tests
    treeherder:
        symbol: node(messagingsystem)
    require-build:
        by-project:
            autoland:
                linux2404-64/opt: build-linux64/opt
            try:
                linux2404-64/opt: build-linux64/opt
            default:
                linux2404-64/opt: build-linux64-shippable/opt
    fetches:
        build:
            - target.tar.xz
        toolchain:
            - linux64-node
            - node-modules
            - aboutwelcome-node-modules
            - asrouter-node-modules
    run:
        command: >
            cd /builds/worker/checkouts/gecko &&
            cp -r $MOZ_FETCHES_DIR/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/components/aboutwelcome &&
            cp -r $MOZ_FETCHES_DIR/aboutwelcome/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/components/asrouter &&
            cp -r $MOZ_FETCHES_DIR/asrouter/node_modules node_modules &&
            FIREFOX_BIN=$MOZ_FETCHES_DIR/firefox/firefox PATH=$PATH:$MOZ_FETCHES_DIR/node/bin node bin/try-runner.js
    when:
        files-changed:
            - "browser/components/aboutwelcome/**"
            - "browser/components/asrouter/**"

messagingsystem-unit-tests-ccov:
    description: messaging system unit tests code coverage
    treeherder:
        symbol: node(messagingsystem-ccov)
    worker:
        artifacts:
            - name: public/code-coverage-grcov.zip
              path: /builds/worker/checkouts/gecko/browser/components/asrouter/logs/coverage/code-coverage-grcov.zip
              type: file
    require-build:
        by-project:
            try:
                linux2404-64/opt: build-linux64/opt
            default:
                linux2404-64/opt: build-linux64-shippable/opt
    fetches:
        build:
            - target.tar.xz
        toolchain:
            - linux64-node
            - node-modules
            - aboutwelcome-node-modules
            - asrouter-node-modules
    run:
        command: >
            cd /builds/worker/checkouts/gecko &&
            cp -r $MOZ_FETCHES_DIR/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/components/aboutwelcome &&
            cp -r $MOZ_FETCHES_DIR/aboutwelcome/node_modules node_modules &&
            cd /builds/worker/checkouts/gecko/browser/components/asrouter &&
            cp -r $MOZ_FETCHES_DIR/asrouter/node_modules node_modules &&
            FIREFOX_BIN=$MOZ_FETCHES_DIR/firefox/firefox PATH=$PATH:$MOZ_FETCHES_DIR/node/bin node bin/try-runner.js
    # This should only run on mozilla-central, as the bot will only parse mozilla-central
    # coverage anyways.
    run-on-projects: ["mozilla-central"]
    # Note the lack of a "when" rule here. This is to avoid seeing fluctuating
    # coverage on coverage.moz.tools / searchfox depending on whether the latest
    # push contained patches touching these files or not.

devtools-tests:
    description: devtools node-based tests (for instance jest)
    attributes:
        code-review: true
    treeherder:
        symbol: node(devtools)
    worker:
        docker-image: {in-tree: "lint"}
        artifacts:
            - type: file
              name: public/code-review/issues.json
              path: /builds/worker/issues.json
    run:
        command: >
            ./mach devtools-node-test --artifact=/builds/worker/issues.json
    fetches:
        toolchain:
            - linux64-node
    when:
        files-changed:
            - 'devtools/client/**'
            - 'devtools/shared/**'

devtools-verify-bundle:
    description: devtools bundle checker
    attributes:
        code-review: true
    treeherder:
        symbol: node(devtools-bundle)
        tier: 2
    worker:
        docker-image: {in-tree: "lint"}
        max-run-time: 1200
        artifacts:
            - type: file
              name: public/code-review/issues.json
              path: /builds/worker/issues.json
    run:
        command: >
            cd devtools/client/debugger &&
            yarn &&
            $MOZ_FETCHES_DIR/node/bin/node bin/bundle.js &&
            cd ../../.. &&
            ./mach python taskcluster/scripts/misc/verify-devtools-bundle.py --output /builds/worker/issues.json
    fetches:
        toolchain:
            - linux64-node
    when:
        files-changed:
            - 'devtools/**'

eslint-plugin-mozilla:
    description: eslint-plugin-mozilla integration tests
    treeherder:
        symbol: node(epm)
    worker:
        docker-image: {in-tree: "lint"}
    run:
        command: >
            cp -r $MOZ_FETCHES_DIR/eslint-plugin-mozilla/node_modules tools/lint/eslint/eslint-plugin-mozilla/node_modules &&
            ./mach configure --disable-compile-environment &&
            PATH=$PATH:$MOZ_FETCHES_DIR/node/bin ./mach npm test --prefix tools/lint/eslint/eslint-plugin-mozilla
    when:
        files-changed:
            - 'tools/lint/eslint/eslint-plugin-mozilla/**'
    fetches:
        toolchain:
            - linux64-node
            - eslint-plugin-mozilla

stylelint-plugin-mozilla:
    description: stylelint-plugin-mozilla integration tests
    treeherder:
        symbol: node(spm)
    worker:
        docker-image: {in-tree: "lint"}
    run:
        command: >
            cp -r $MOZ_FETCHES_DIR/stylelint-plugin-mozilla/node_modules tools/lint/stylelint/stylelint-plugin-mozilla/node_modules &&
            ./mach configure --disable-compile-environment &&
            PATH=$PATH:$MOZ_FETCHES_DIR/node/bin ./mach npm test --prefix tools/lint/stylelint/stylelint-plugin-mozilla
    when:
        files-changed:
            - 'tools/lint/stylelint/stylelint-plugin-mozilla/**'
            - toolkit/themes/shared/design-system/dist/tokens-table.mjs
    fetches:
        toolchain:
            - linux64-node
            - stylelint-plugin-mozilla

design-tokens-tests:
    description: design tokens unit tests
    treeherder:
        symbol: node(design-tokens)
    require-build:
        by-project:
            autoland:
                linux2404-64/opt: build-linux64/opt
            try:
                linux2404-64/opt: build-linux64/opt
            default:
                linux2404-64/opt: build-linux64-shippable/opt
    run:
        command: >
            cd /builds/worker/checkouts/gecko &&
            rm -rf node_modules &&
            PATH=$PATH:$MOZ_FETCHES_DIR/node/bin $MOZ_FETCHES_DIR/node/bin/npm ci &&
            cd /builds/worker/checkouts/gecko/toolkit/themes/shared/design-system &&
            rm -rf node_modules &&
            PATH=$PATH:$MOZ_FETCHES_DIR/node/bin $MOZ_FETCHES_DIR/node/bin/npm ci &&
            $MOZ_FETCHES_DIR/node/bin/node tests/try-runner.js
    fetches:
        toolchain:
            - linux64-node
    when:
        files-changed:
            - "toolkit/themes/shared/design-system/**"
