# Put it in the root folder.
    - store_test_results:
        path: test_results

steps-verify-ffmpeg: &steps-verify-ffmpeg
  steps:
    - attach_workspace:
        at:.
    - *step-depot-tools-add-to-path
    - *step-electron-dist-unzip
    - *step-setup-linux-for-headless-testing

    - *step-verify-ffmpeg
    - *step-maybe-notify-slack-failure

steps-verify-mksnapshot: &steps-verify-mksnapshot
  steps:
    - attach_workspace:
        at:.
    - *step-depot-tools-add-to-path
    - *step-electron-dist-unzip
    - *step-mksnapshot-unzip
    - *step-setup-linux-for-headless-testing

    - *step-verify-mksnapshot
    - *step-maybe-notify-slack-failure

steps-tests: &steps-tests
  steps:
    - attach_workspace:
        at:.
    - *step-depot-tools-add-to-path
    - *step-electron-dist-unzip
    - *step-mksnapshot-unzip
    - *step-setup-linux-for-headless-testing
    - *step-install-nodejs-on-mac

    - run:
        name: Run Electron tests
        environment:
          MOCHA_REPORTER: mocha-multi-reporters
          MOCHA_FILE: junit/test-results.xml
          MOCHA_MULTI_REPORTERS: mocha-junit-reporter, tap
          ELECTRON_DISABLE_SECURITY_WARNINGS: 1
        command: |
          cd src
          export ELECTRON_OUT_DIR=Default
          (cd electron && npm run test -- --ci)
    - run:
        name: Check test results existence
        command: |
          MOCHA_FILE='src/junit/test-results.xml'
          # Check if it exists and not empty.
          if [! -s "$MOCHA_FILE" ]; then
            exit 1
          fi
    - store_test_results:
        path: src/junit

    - *step-verify-mksnapshot

    - *step-maybe-notify-slack-failure

# Mac build are different in a few ways:
# 1. We can't use save_cache/restore_cache on Mac,
#   unpacking with `tar` fails with "Attempt to write to an empty file" error.
# 2. We don't use a shared checkout job because persist_to_workspace
#   and attach_workspace take too much time, more than the checkout itself.
steps-build-mac: &steps-build-mac
  steps:
    - *step-checkout-electron
    - *step-depot-tools-get
    - *step-depot-tools-add-to-path
    - *step-install-nodejs-on-mac
    - *step-gclient-sync
    - *step-setup-env-for-build
    - *step-gn-gen-default

    # Electron app
    - *step-electron-build
    - *step-electron-dist-build
    - *step-electron-dist-store

    # mksnapshot
    - *step-mksnapshot-build
    - *step-mksnapshot-store

    # chromedriver
    - *step-electron-chromedriver-build
    - *step-electron-chromedriver-store

    # ffmpeg
    - *step-ffmpeg-gn-gen
    - *step-ffmpeg-build
    - *step-ffmpeg-store

    # It would be better to verify ffmpeg as a part of a test job,
    # but it requires `gn` to run, and it's complicated
    # to store all gn's dependencies and configs.
    - *step-verify-ffmpeg

    - *step-verify-mksnapshot

    # Node.js headers for tests
    - *step-nodejs-headers-build

    - *step-show-sccache-stats

    - persist_to_workspace:
        root:.
        paths:
          - src/electron

    # Save all data needed for a further tests run.
    - *step-persist-data-for-tests

filter-only-prs-from-forks: &filter-only-prs-from-forks
  filters:
    branches:
      only: /^pull\/.*$/

chromium-upgrade-branches: &chromium-upgrade-branches
  /chromium\-upgrade\/[0-9]+/

# List of all jobs.
version: 2
jobs:
  # Layer 1: Checkout.
  linux-checkout:
    <<: *machine-linux-2xlarge
    environment:
      GCLIENT_EXTRA_ARGS: '--custom-var=checkout_arm=True --custom-var=checkout_arm64=True'
    <<: *steps-checkout

  linux-checkout-for-native-tests:
    <<: *machine-linux-2xlarge
    environment:
      GCLIENT_EXTRA_ARGS: '--custom-var=checkout_pyyaml=True'
    <<: *steps-checkout

  linux-checkout-for-native-tests-with-no-patches:
    <<: *machine-linux-2xlarge
    environment:
      GCLIENT_EXTRA_ARGS: '--custom-var=apply_patches=False --custom-var=checkout_pyyaml=True'
    <<: *steps-checkout

  # Layer 2: Builds.
  linux-x64-debug:
    <<: *machine-linux-2xlarge
    environment:
      <<: *env-debug-build
      <<: *env-enable-sccache
    <<: *steps-electron-build

  linux-x64-testing:
    <<: *machine-linux-2xlarge
    environment:
      <<: *env-testing-build
      <<: *env-enable-sccache
    <<: *steps-electron-build-for-tests

  linux-x64-ffmpeg:
    <<: *machine-linux-medium
    environment:
      <<: *env-enable-sccache
      <<: *env-send-slack-notifications
    <<: *steps-ffmpeg-build

  linux-x64-chromedriver:
    <<: *machine-linux-medium
    environment:
      <<: *env-release-build
      <<: *env-enable-sccache
      <<: *env-send-slack-notifications
    <<: *steps-chromedriver-build

  linux-x64-release:
    <<: *machine-linux-2xlarge
    environment:
      <<: *env-release-build
      <<: *env-enable-sccache
      <<: *env-send-slack-notifications
    <<: *steps-electron-build-for-tests

  linux-x64-publish:
    <<: *machine-linux-2xlarge
    environment:
      GCLIENT_EXTRA_ARGS: '--custom-var=checkout_boto=True --custom-var=checkout_requests=True'
      <<: *env-release-build
    <<: *steps-electron-build-for-publish

  linux-ia32-debug:
    <<: *machine-linux-2xlarge
    environment:
      <<: *env-ia32
      <<: *env-debug-build
      <<: *env-enable-sccache
    <<: *steps-electron-build

  linux-ia32-testing:
    <<: *machine-linux-2xlarge
    environment:
      <<: *env-ia32
      <<: *env-testing-build
      <<: *env-enable-sccache
    <<: *steps-electron-build-for-tests

  linux-ia32-ffmpeg:
    <<: *machine-linux-medium
    environment:
      <<: *env-ia32
      <<: *env-enable-sccache
      <<: *env-send-slack-notifications
    <<: *steps-ffmpeg-build

  linux-ia32-chromedriver:
    <<: *machine-linux-medium
    environment:
      <<: *env-ia32
      <<