functions:
  abi-compliance-check:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        args:
          - -c
          - |
            if [[ -n "$XDG_CACHE_DIR" ]]; then
                cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
            elif [[ -n "$LOCALAPPDATA" ]]; then
                cache_dir="$LOCALAPPDATA" # Windows.
            elif [[ -n "$USERPROFILE" ]]; then
                cache_dir="$USERPROFILE/.cache" # Windows (fallback).
            elif [[ -d "$HOME/Library/Caches" ]]; then
                cache_dir="$HOME/Library/Caches" # MacOS.
            elif [[ -n "$HOME" ]]; then
                cache_dir="$HOME/.cache" # Linux-like.
            elif [[ -d ~/.cache ]]; then
                cache_dir="~/.cache" # Linux-like (fallback).
            else
                cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
            fi

            mkdir -p "$cache_dir/mongo-c-driver" || exit
            cache_dir="$(cd "$cache_dir/mongo-c-driver" && pwd)" || exit

            printf "MONGO_C_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
    - command: expansions.update
      type: setup
      params:
        file: expansions.set-cache-dir.yml
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        include_expansions_in_env:
          - MONGO_C_DRIVER_CACHE_DIR
        args:
          - -c
          - .evergreen/scripts/abi-compliance-check-setup.sh
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        include_expansions_in_env:
          - MONGO_C_DRIVER_CACHE_DIR
        args:
          - -c
          - .evergreen/scripts/abi-compliance-check.sh
    - command: s3.put
      type: system
      params:
        display_name: "ABI Compliance Check: "
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/html
        local_files_include_filter: abi-compliance/compat_reports/**/compat_report.html
        permissions: public-read
        remote_file: ${project}/${branch_name}/${revision}/${version_id}/${build_id}/${task_id}/${execution}/abi-compliance-check/
    - command: s3.put
      type: system
      params:
        display_name: "ABI Compliance Check: "
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/plain
        local_files_include_filter: abi-compliance/logs/**/log.txt
        permissions: public-read
        remote_file: ${project}/${branch_name}/${revision}/${version_id}/${build_id}/${task_id}/${execution}/abi-compliance-check/
  backtrace:
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - .evergreen/scripts/debug-core-evergreen.sh
  bootstrap-mongo-orchestration:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        args:
          - -c
          - .evergreen/scripts/integration-tests.sh
    - command: expansions.update
      type: setup
      params:
        file: mongoc/mo-expansion.yml
  check-headers:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - .evergreen/scripts/check-public-decls.sh
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - .evergreen/scripts/check-preludes.py .
  clang-format:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        env:
          DRYRUN: "1"
        args:
          - -c
          - uv run --frozen --only-group=format tools/format.py --mode=check
  cse-sasl-cyrus-darwinssl-compile:
    - command: expansions.update
      params:
        updates:
          - { key: SSL, value: DARWIN }
          - { key: SASL, value: CYRUS }
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          COMPILE_LIBMONGOCRYPT: "ON"
        args:
          - -c
          - EXTRA_CONFIGURE_FLAGS="-DENABLE_PIC=ON ${EXTRA_CONFIGURE_FLAGS}" .evergreen/scripts/compile.sh
  cse-sasl-cyrus-openssl-compile:
    - command: expansions.update
      params:
        updates:
          - { key: SSL, value: OPENSSL }
          - { key: SASL, value: CYRUS }
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          COMPILE_LIBMONGOCRYPT: "ON"
        args:
          - -c
          - EXTRA_CONFIGURE_FLAGS="-DENABLE_PIC=ON ${EXTRA_CONFIGURE_FLAGS}" .evergreen/scripts/compile.sh
  cse-sasl-sspi-openssl-compile:
    - command: expansions.update
      params:
        updates:
          - { key: SSL, value: OPENSSL }
          - { key: SASL, value: SSPI }
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          COMPILE_LIBMONGOCRYPT: "ON"
        args:
          - -c
          - EXTRA_CONFIGURE_FLAGS="-DENABLE_PIC=ON ${EXTRA_CONFIGURE_FLAGS}" .evergreen/scripts/compile.sh
  cse-sasl-sspi-winssl-compile:
    - command: expansions.update
      params:
        updates:
          - { key: SSL, value: WINDOWS }
          - { key: SASL, value: SSPI }
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          COMPILE_LIBMONGOCRYPT: "ON"
        args:
          - -c
          - EXTRA_CONFIGURE_FLAGS="-DENABLE_PIC=ON ${EXTRA_CONFIGURE_FLAGS}" .evergreen/scripts/compile.sh
  csfle-setup:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: drivers-evergreen-tools/.evergreen/csfle
        args:
          - -c
          - |
            set -o errexit
            echo "Preparing KMS TLS venv environment..."
            if [[ "$OSTYPE" =~ cygwin && ! -d kmstlsvenv ]]; then
                # Avoid using Python 3.10 on Windows due to incompatible cipher suites.
                # See CDRIVER-4530.
                . ../venv-utils.sh
                venvcreate "C:/python/Python39/python.exe" kmstlsvenv || # windows-2017
                venvcreate "C:/python/Python38/python.exe" kmstlsvenv    # windows-2015
                python -m pip install --upgrade boto3~=1.19 pykmip~=0.10.0 "sqlalchemy<2.0.0"
                deactivate
            else
                . ./activate-kmstlsvenv.sh
                deactivate
            fi
            echo "Preparing KMS TLS venv environment... done."
    - command: ec2.assume_role
      params:
        role_arn: ${aws_test_secrets_role}
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: drivers-evergreen-tools/.evergreen/csfle
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - ./setup.sh
  csfle-teardown:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: drivers-evergreen-tools/.evergreen/csfle
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - ./teardown.sh
  docker-login-amazon-ecr:
    - command: expansions.update
      params:
        updates:
          - { key: DOCKER_CONFIG, value: "${workdir}/.docker" }
    - command: ec2.assume_role
      params:
        role_arn: arn:aws:iam::901841024863:role/ecr-role-evergreen-ro
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
          - DOCKER_CONFIG
        args:
          - -c
          - aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 901841024863.dkr.ecr.us-east-1.amazonaws.com
  fetch-build:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        args:
          - -c
          - rm -rf mongoc
    - command: s3.get
      type: setup
      params:
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        local_file: build.tar.gz
        remote_file: ${project}/${build_variant}/${revision}/${BUILD_NAME}/${build_id}.tar.gz
    - command: archive.targz_extract
      params:
        destination: mongoc
        path: build.tar.gz
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            for file in $(find .evergreen/scripts -type f); do
                chmod +rx "$file" || exit
            done
  fetch-det:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        args:
          - -c
          - |
            if [[ ! -d drivers-evergreen-tools ]]; then
                git clone --depth=1 https://github.com/mongodb-labs/drivers-evergreen-tools.git
            fi
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: drivers-evergreen-tools
        args:
          - -c
          - find .evergreen -type f -name "*.sh" -exec chmod +rx "{}" \;
  fetch-source:
    - command: git.get_project
      type: setup
      params:
        directory: mongoc
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            set -o errexit
            set -o pipefail
            if [ -n "${github_pr_number}" -o "${is_patch}" = "true" ]; then
                VERSION=patch-${version_id}
            else
                VERSION=latest
            fi
            echo "CURRENT_VERSION: $VERSION" > expansion.yml
    - command: expansions.update
      type: setup
      params:
        file: mongoc/expansion.yml
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            for file in $(find .evergreen/scripts -type f); do
                chmod +rx "$file" || exit
            done
  kms-divergence-check:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - .evergreen/scripts/kms-divergence-check.sh
  make-docs:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        include_expansions_in_env:
          - distro_id
        args:
          - -c
          - |
            # See SphinxBuild.cmake for EVG_DOCS_BUILD reasoning
            uv run --frozen --only-group docs env EVG_DOCS_BUILD=1 .evergreen/scripts/build-docs.sh
  openssl-compat:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        include_expansions_in_env:
          - OPENSSL_ENABLE_FIPS
          - OPENSSL_USE_STATIC_LIBS
          - OPENSSL_VERSION
        args:
          - -c
          - .evergreen/scripts/openssl-compat-setup.sh
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        include_expansions_in_env:
          - OPENSSL_USE_STATIC_LIBS
          - OPENSSL_VERSION
        args:
          - -c
          - .evergreen/scripts/openssl-compat-check.sh
  restore-instance-profile:
    - command: subprocess.exec
      params:
        binary: bash
        args:
          - -c
          - |
            # Restore the AWS Instance Profile that may have been removed in AWS tasks.

            if [[ ! -d drivers-evergreen-tools ]]; then
                echo "drivers-evergreen-tools not present ... skipping"
                exit 0
            fi

            cd drivers-evergreen-tools/.evergreen/auth_aws
            if [[ ! -f aws_e2e_setup.json ]]; then
                echo "aws_e2e_setup.json not present ... skipping"
                exit 0
            fi

            . ./activate-authawsvenv.sh

            echo "restoring instance profile ... "
            # Capture and hide logs on success. Logs may included expected `HTTP Error 404: Not Found` messages when checking for instance profile.
            if ! { python ./lib/aws_assign_instance_profile.py 2>&1 >|output.txt; }; then
                echo "restoring instance profile ... failed"
                cat output.txt 1>&2
                exit 1
            fi
            echo "restoring instance profile ... succeeded"
  run oidc k8s test:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        env:
          K8S_VARIANT: ${VARIANT}
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - ./drivers-evergreen-tools/.evergreen/auth_oidc/k8s/setup-pod.sh
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        env:
          K8S_DRIVERS_TAR_FILE: ${OIDC_TEST_TARBALL}
          K8S_TEST_CMD: ./.evergreen/scripts/oidc-k8s-test.sh
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - ./drivers-evergreen-tools/.evergreen/auth_oidc/k8s/run-driver-test.sh
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - ./drivers-evergreen-tools/.evergreen/auth_oidc/k8s/teardown-pod.sh
  run-simple-http-server:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        working_dir: mongoc
        background: true
        args:
          - -c
          - |
            set -o errexit
            echo "Starting simple HTTP server..."
            uvx python .evergreen/scripts/simple_http_server.py
            echo "Starting simple HTTP server... done."
  run-tests:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        args:
          - -c
          - .evergreen/scripts/run-tests.sh
  sasl-cyrus-darwinssl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: CYRUS
          SSL: DARWIN
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sasl-cyrus-openssl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: CYRUS
          SSL: OPENSSL
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sasl-off-nossl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: "OFF"
          SSL: "OFF"
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sasl-off-winssl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: "OFF"
          SSL: WINDOWS
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sasl-sspi-openssl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: SSPI
          SSL: OPENSSL
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sasl-sspi-winssl-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        env:
          SASL: SSPI
          SSL: WINDOWS
        args:
          - -c
          - .evergreen/scripts/compile.sh
  sbom:
    - command: ec2.assume_role
      type: setup
      params:
        role_arn: ${kondukto_role_arn}
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
        args:
          - -c
          - |
            set -o errexit
            set -o pipefail
            kondukto_token="$(aws secretsmanager get-secret-value --secret-id "kondukto-token" --region "us-east-1" --query 'SecretString' --output text)"
            printf "KONDUKTO_TOKEN: %s\n" "$kondukto_token" >|expansions.kondukto.yml
    - command: expansions.update
      type: setup
      params:
        file: expansions.kondukto.yml
    - command: expansions.update
      params:
        updates:
          - { key: DOCKER_CONFIG, value: "${workdir}/.docker" }
    - command: ec2.assume_role
      params:
        role_arn: arn:aws:iam::901841024863:role/ecr-role-evergreen-ro
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        include_expansions_in_env:
          - AWS_ACCESS_KEY_ID
          - AWS_SECRET_ACCESS_KEY
          - AWS_SESSION_TOKEN
          - DOCKER_CONFIG
        args:
          - -c
          - aws ecr get-login-password --region us-east-1 | podman login --username AWS --password-stdin 901841024863.dkr.ecr.us-east-1.amazonaws.com
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        include_expansions_in_env:
          - branch_name
          - DOCKER_CONFIG
          - KONDUKTO_TOKEN
        args:
          - -c
          - .evergreen/scripts/sbom.sh
    - command: s3.put
      type: test
      params:
        display_name: Augmented SBOM
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: application/json
        local_file: mongoc/augmented-sbom.json
        permissions: public-read
        remote_file: ${project}/${build_variant}/${revision}/${version_id}/${build_id}/sbom/augmented-sbom.json
  scan-build:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        redirect_standard_error_to_output: true
        args:
          - -c
          - .evergreen/scripts/compile-scan-build.sh
  set-cache-dir:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        args:
          - -c
          - |
            if [[ -n "$XDG_CACHE_DIR" ]]; then
                cache_dir="$XDG_CACHE_DIR" # XDG Base Directory specification.
            elif [[ -n "$LOCALAPPDATA" ]]; then
                cache_dir="$LOCALAPPDATA" # Windows.
            elif [[ -n "$USERPROFILE" ]]; then
                cache_dir="$USERPROFILE/.cache" # Windows (fallback).
            elif [[ -d "$HOME/Library/Caches" ]]; then
                cache_dir="$HOME/Library/Caches" # MacOS.
            elif [[ -n "$HOME" ]]; then
                cache_dir="$HOME/.cache" # Linux-like.
            elif [[ -d ~/.cache ]]; then
                cache_dir="~/.cache" # Linux-like (fallback).
            else
                cache_dir="$(pwd)/.cache" # EVG task directory (fallback).
            fi

            mkdir -p "$cache_dir/mongo-c-driver" || exit
            cache_dir="$(cd "$cache_dir/mongo-c-driver" && pwd)" || exit

            printf "MONGO_C_DRIVER_CACHE_DIR: %s\n" "$cache_dir" >|expansions.set-cache-dir.yml
    - command: expansions.update
      type: setup
      params:
        file: expansions.set-cache-dir.yml
  start-load-balancer:
    - command: subprocess.exec
      type: setup
      params:
        binary: bash
        args:
          - -c
          - |
            export DRIVERS_TOOLS=./drivers-evergreen-tools
            export MONGODB_URI="${MONGODB_URI}"
            export PATH="$(uv tool dir --bin):$PATH" # DEVPROD-19733
            $DRIVERS_TOOLS/.evergreen/run-load-balancer.sh start
    - command: expansions.update
      type: setup
      params:
        file: lb-expansion.yml
  std-compile:
    - command: subprocess.exec
      type: test
      params:
        binary: bash
        working_dir: mongoc
        add_expansions_to_env: true
        args:
          - -c
          - .evergreen/scripts/compile-std.sh
  stop-load-balancer:
    - command: subprocess.exec
      params:
        binary: bash
        args:
          - -c
          - |
            # Only run if a load balancer was started.
            if [[ -z "${SINGLE_MONGOS_LB_URI}" ]]; then
                echo "OK - no load balancer running"
                exit
            fi
            if [[ -d drivers-evergreen-tools ]]; then
                cd drivers-evergreen-tools && .evergreen/run-load-balancer.sh stop
            fi
  stop-mongo-orchestration:
    - command: subprocess.exec
      params:
        binary: bash
        args:
          - -c
          - |
            if [[ -d drivers-evergreen-tools ]]; then
                cd drivers-evergreen-tools && .evergreen/run-mongodb.sh stop
            fi
  upload-build:
    - command: archive.targz_pack
      params:
        include:
          - ./**
        source_dir: mongoc
        target: ${build_id}.tar.gz
    - command: s3.put
      params:
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: ${content_type|application/x-gzip}
        local_file: ${build_id}.tar.gz
        permissions: public-read
        remote_file: ${project}/${build_variant}/${revision}/${task_name}/${build_id}.tar.gz
  upload-docs:
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc/_build/for-docs/src/libbson
        env:
          AWS_ACCESS_KEY_ID: ${aws_key}
          AWS_SECRET_ACCESS_KEY: ${aws_secret}
        args:
          - -c
          - aws s3 cp doc/html s3://mciuploads/${project}/docs/libbson/${CURRENT_VERSION} --quiet --recursive --acl public-read --region us-east-1
    - command: s3.put
      params:
        display_name: libbson docs
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/html
        local_file: mongoc/_build/for-docs/src/libbson/doc/html/index.html
        permissions: public-read
        remote_file: ${project}/docs/libbson/${CURRENT_VERSION}/index.html
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc/_build/for-docs/src/libmongoc
        env:
          AWS_ACCESS_KEY_ID: ${aws_key}
          AWS_SECRET_ACCESS_KEY: ${aws_secret}
        args:
          - -c
          - aws s3 cp doc/html s3://mciuploads/${project}/docs/libmongoc/${CURRENT_VERSION} --quiet --recursive --acl public-read --region us-east-1
    - command: s3.put
      params:
        display_name: libmongoc docs
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/html
        local_file: mongoc/_build/for-docs/src/libmongoc/doc/html/index.html
        permissions: public-read
        remote_file: ${project}/docs/libmongoc/${CURRENT_VERSION}/index.html
  upload-man-pages:
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            set -o errexit
            # Get "aha", the ANSI HTML Adapter.
            git clone --depth 1 https://github.com/theZiz/aha.git aha-repo
            pushd aha-repo
            make
            popd # aha-repo
            mv aha-repo/aha .
            .evergreen/scripts/man-pages-to-html.sh libbson _build/for-docs/src/libbson/doc/man > bson-man-pages.html
            .evergreen/scripts/man-pages-to-html.sh libmongoc _build/for-docs/src/libmongoc/doc/man > mongoc-man-pages.html
    - command: s3.put
      params:
        display_name: libbson man pages
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/html
        local_file: mongoc/bson-man-pages.html
        permissions: public-read
        remote_file: ${project}/man-pages/libbson/${CURRENT_VERSION}/index.html
    - command: s3.put
      params:
        display_name: libmongoc man pages
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: text/html
        local_file: mongoc/mongoc-man-pages.html
        permissions: public-read
        remote_file: ${project}/man-pages/libmongoc/${CURRENT_VERSION}/index.html
  upload-mo-artifacts:
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            set -o errexit
            declare dir="MO"
            if [[ -d "/cygdrive/c/data/mo" ]]; then
                dir="/cygdrive/c/data/mo"
            fi
            if [[ -d "$dir" ]]; then
                find "$dir" -name \*.log | xargs tar czf mongodb-logs.tar.gz
            fi
    - command: s3.put
      params:
        display_name: mongodb-logs.tar.gz
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: ${content_type|application/x-gzip}
        local_file: mongoc/mongodb-logs.tar.gz
        optional: true
        permissions: public-read
        remote_file: ${project}/${build_variant}/${revision}/${version_id}/${build_id}/logs/${task_id}-${execution}-mongodb-logs.tar.gz
    - command: s3.put
      params:
        display_name: orchestration.log
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: ${content_type|text/plain}
        local_file: mongoc/MO/server.log
        optional: true
        permissions: public-read
        remote_file: ${project}/${build_variant}/${revision}/${version_id}/${build_id}/logs/${task_id}-${execution}-orchestration.log
    - command: subprocess.exec
      params:
        binary: bash
        working_dir: mongoc
        args:
          - -c
          - |
            set -o errexit
            # Find all core files from mongodb in orchestration and move to mongoc
            declare dir="MO"
            if [[ -d "/cygdrive/c/data/mo" ]]; then
                dir="/cygdrive/c/data/mo"
            fi
            declare mdmp_dir="$dir"
            if [[ -d "/cygdrive/c/mongodb" ]]; then
                mdmp_dir="/cygdrive/c/mongodb"
            fi
            for core_file in $(find -H "$dir" "$mdmp_dir" \( -name "*.core" -o -name "*.mdmp" \) 2> /dev/null); do
                declare base_name
                base_name="$(echo "$core_file" | sed "s/.*\///")"
                # Move file if it does not already exist
                if [[ ! -f "$base_name" ]]; then
                    mv "$core_file" .
                fi
            done
    - command: archive.targz_pack
      params:
        include:
          - ./**.core
          - ./**.mdmp
        source_dir: mongoc
        target: mongo-coredumps.tgz
    - command: s3.put
      params:
        display_name: Core Dumps - Execution ${execution}
        aws_key: ${aws_key}
        aws_secret: ${aws_secret}
        bucket: mciuploads
        content_type: ${content_type|application/x-gzip}
        local_file: mongo-coredumps.tgz
        optional: true
        permissions: public-read
        remote_file: ${project}/${build_variant}/${revision}/${version_id}/${build_id}/coredumps/${task_id}-${execution}-coredumps.log
  upload-test-results:
    - command: subprocess.exec
      params:
        binary: bash
        args:
          - -c
          - |
            mkdir -p mongoc
            touch mongoc/test-results.json
    - command: attach.results
      params:
        file_location: mongoc/test-results.json
