- name: "Node: Build"
  run:
    when: "${CHANGE_IN(node)}"
  dependencies:
    - Prerequisites
  task:
    env_vars:
      - name: BUILD_CACHE_GROUP
        value: "node"
    agent:
      machine:
        type: f1-standard-4
        os_image: ubuntu2204
    prologue:
      commands:
        - cd node
    jobs:
      - name: "Node: CI"
        priority:
          # This job is on the critical path so we increase its priority.
          - value: 51
            when: "pull_request =~ '.+'"
        commands:
          - ../.semaphore/run-and-monitor ci.log make ci
        env_vars:
          - name: STORE_BUILD_CACHE
            value: "true"
- name: "Node: multi-arch build"
  run:
    when: "${CHANGE_IN(node)}"
  dependencies:
    - "Node: Build"
  task:
    prologue:
      commands:
        - cd node
    jobs:
      - name: "Node: build multi-arch images"
        matrix:
          - env_var: ARCH
            values:
              - ppc64le
              - s390x
        commands:
          - ../.semaphore/run-and-monitor image-$ARCH.log make image ARCH=$ARCH
      - name: "Node: build Windows archive"
        commands:
          - ../.semaphore/run-and-monitor build-windows-archive.log make build-windows-archive
      - name: "Node: build Windows image"
        commands:
          - ../.semaphore/run-and-monitor build-windows-image.log make image-windows
- name: "Node: Build - native arm64 runner"
  run:
    when: "${CHANGE_IN(node)}"
  dependencies:
    - "Node: Build"
  task:
    agent:
      machine:
        type: s1-aws-arm64-2
    prologue:
      commands:
        - cd node
    jobs:
      - name: "Node: build arm64 image"
        commands:
          - ../.semaphore/run-and-monitor build-arm64.log make image ARCH=arm64
- name: "Node: kind-cluster tests"
  run:
    # KinD tests also build and run all the other images.
    when: "${CHANGE_IN(node,typha,apiserver,cni-plugin,pod2daemon,calicoctl,kube-controllers,goldmane,whisker,whisker-backend,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Prerequisites"
  task:
    env_vars:
      - name: BUILD_CACHE_GROUP
        value: "node"
      - name: CI_GROUP_LABEL
        value: "node"
      - name: CI_JOB_LABEL
        value: "kind-cluster-tests"
    prologue:
      commands:
        # Set up access to GCP buckets.
        - export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/secret.google-service-account-key.json
        - gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
        - gcloud config set project unique-caldron-775
        - cd node
        - export SHORT_WORKFLOW_ID=$(echo ${SEMAPHORE_WORKFLOW_ID} | sha256sum | cut -c -8)
        - export ZONE=europe-west3-c
        - export VM_PREFIX=sem-${SEMAPHORE_PROJECT_NAME}-${SHORT_WORKFLOW_ID}-kind-
        - echo VM_PREFIX=${VM_PREFIX}
        - export COMPONENT=node
        - export VM_DISK_SIZE=80GB
        - mkdir artifacts
        - ./.semaphore/cache-test-artifacts
    jobs:
      - name: "Node: kind-cluster tests"
        execution_time_limit:
          minutes: 120
        commands:
          - ../.semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - '../.semaphore/vms/publish-reports "Node: KinD STs"'
          - ../.semaphore/vms/clean-up-vms ${VM_PREFIX}
    secrets:
      - name: google-service-account-for-gce
