- name: "Felix: Build"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - Prerequisites
  task:
    env_vars:
      - name: BUILD_CACHE_GROUP
        value: "felix"
    prologue:
      commands:
        - cd felix
        - gcloud config set project unique-caldron-775
        - gcloud auth activate-service-account --key-file=$HOME/secrets/secret.google-service-account-key.json
    secrets:
      - name: google-service-account-for-gce
    jobs:
      - name: "Felix: Build and cache FV prerequisites"
        priority:
        # This job is on the critical path so we increase its priority.
          - value: 51
            when: "pull_request =~ '.+'"
        env_vars:
          - name: STORE_BUILD_CACHE
            value: "true"
        execution_time_limit:
          minutes: 20
        commands:
          - make build image ut-bpf-prereqs fv-prereqs
          - ./.semaphore/cache-test-artifacts
      - name: "Felix: UT"
        priority:
          # This job is on the critical path so we increase its priority.
          - value: 51
            when: "pull_request =~ '.+'"
        execution_time_limit:
          minutes: 30
        commands:
          - ../.semaphore/run-and-monitor ut.log make ut
      - name: "Felix: k8sfv"
        priority:
          # This job is on the critical path so we increase its priority.
          - value: 51
            when: "pull_request =~ '.+'"
        execution_time_limit:
          minutes: 15
        commands:
          - ../.semaphore/run-and-monitor k8sfv-typha.log make k8sfv-test JUST_A_MINUTE=true USE_TYPHA=true
          - ../.semaphore/run-and-monitor k8sfv-no-typha.log make k8sfv-test JUST_A_MINUTE=true USE_TYPHA=false
      - name: "Felix: Static checks"
        priority:
          # This job is on the critical path so we increase its priority.
          - value: 51
            when: "pull_request =~ '.+'"
        execution_time_limit:
          minutes: 15
        commands:
          - ../.semaphore/run-and-monitor static-checks.log make static-checks
    epilogue:
      always:
        commands:
          - 'test-results publish --name "${SEMAPHORE_JOB_NAME}" ./report/*.xml || true'
- name: "Felix: multi-arch build"
  run:
    when: "${CHANGE_IN(felix)}"
  dependencies:
    - "Felix: Build"
  task:
    prologue:
      commands:
        - cd felix
    jobs:
      - name: "Felix: build multi-arch binaries"
        matrix:
          - env_var: ARCH
            values:
              - ppc64le
              - s390x
        commands:
          # Only building the code, not the image here because the felix image is now only used for FV tests, which
          # only run on AMD64 at the moment.
          - ../.semaphore/run-and-monitor build-$ARCH.log make build ARCH=$ARCH
- name: "Felix: Build - native arm64 runner"
  run:
    when: "${CHANGE_IN(felix)}"
  dependencies:
    - "Felix: Build"
  task:
    agent:
      machine:
        type: s1-aws-arm64-2
    prologue:
      commands:
        - cd felix
    jobs:
      - name: "Felix: build arm64 binaries"
        commands:
          - ../.semaphore/run-and-monitor build-arm64.log make build ARCH=arm64
- name: "Felix: Build Windows binaries"
  run:
    when: "${CHANGE_IN(felix)}"
  dependencies:
    - Prerequisites
  task:
    env_vars:
      - name: BUILD_CACHE_GROUP
        value: "felix"
    jobs:
      - name: "Felix: Build Windows binaries"
        commands:
          - cd felix
          - make bin/calico-felix.exe fv/win-fv.exe
- name: "Felix: Windows FV"
  run:
    when: "false or ${CHANGE_IN(felix,non-go:/process/testing/aso,non-go:/process/testing/utils,non-go:/process/testing/winfv-felix)}"
  dependencies: ["Felix: Build Windows binaries"]
  task:
    secrets:
      - name: banzai-secrets
      - name: private-repo
    prologue:
      commands:
        - az login --service-principal -u "${AZ_SP_ID}" -p "${AZ_SP_PASSWORD}" --tenant "${AZ_TENANT_ID}" --output none
        - export REPORT_DIR=/home/semaphore/report
        - export AZURE_SUBSCRIPTION_ID=$AZ_SUBSCRIPTION_ID
        - export AZURE_TENANT_ID=$AZ_TENANT_ID
        - export AZURE_CLIENT_ID=$AZ_SP_ID
        - export AZURE_CLIENT_SECRET=$AZ_SP_PASSWORD
        - export REPORT_DIR=/home/semaphore/calico/process/testing/winfv-felix/report
        - export LOGS_DIR=~/fv.log
        - export RG_PREFIX=${USER}-win-felix-${SEMAPHORE_GIT_SHA:0:4}-pr${SEMAPHORE_GIT_PR_NUMBER}
        - cd felix
    epilogue:
      always:
        commands:
          - artifact push job ${REPORT_DIR} --destination semaphore/test-results || true
          - artifact push job ${LOGS_DIR} --destination semaphore/logs || true
          - cd ~/calico/process/testing/aso && make dist-clean
    env_vars:
      - name: BUILD_CACHE_GROUP
        value: "felix"
      - name: FV_TYPE
        value: "calico-felix"
      - name: SEMAPHORE_ARTIFACT_EXPIRY
        value: 2w
      - name: CONTAINERD_VERSION
        value: 1.7.28
    jobs:
      - name: "Felix: Windows FV"
        commands:
          - export AZURE_RESOURCE_GROUP=${RG_PREFIX}-rg
          - echo AZURE_RESOURCE_GROUP=${AZURE_RESOURCE_GROUP}
          - ../.semaphore/run-and-monitor win-fv-felix.log ~/calico/process/testing/winfv-felix/run-win-fv.sh
- name: "Felix: iptables tests on Ubuntu 22.04"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: iptables tests on Ubuntu 22.04"
        execution_time_limit:
          minutes: 60
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "22.04-ipt"
        commands:
          - source felix/.semaphore/fv-prologue
          - export NUM_FV_BATCHES=16
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
- name: "Felix: nftables tests on Ubuntu 22.04"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: nftables tests on Ubuntu 22.04"
        execution_time_limit:
          minutes: 60
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "22.04-nft"
        commands:
          - source felix/.semaphore/fv-prologue
          - export NUM_FV_BATCHES=16
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
- name: "Felix: BPF tests on Ubuntu 24.04 (iptables)"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: BPF tests on Ubuntu 24.04"
        execution_time_limit:
          minutes: 60
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "bpf-24.04-ipt-with-ut"
        commands:
          - source felix/.semaphore/fv-prologue
          - export NUM_FV_BATCHES=60
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
- name: "Felix: BPF tests on Ubuntu 22.04 (nftables)"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: BPF tests on Ubuntu 22.04 (nftables)"
        execution_time_limit:
          minutes: 60
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "bpf-22.04-nft-with-ut"
          - name: FELIX_FV_BPFATTACHTYPE
            value: "tc"
        commands:
          - source felix/.semaphore/fv-prologue
          # Limit to BPF conntrack tests to reduce overall runtime.
          - export FV_FOCUS='_BPF_.*ct=true'
          - export NUM_FV_BATCHES=10
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
- name: "Felix: BPF program-loading check on 25.04 (nftables)"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: BPF program-loading check on 25.04"
        execution_time_limit:
          minutes: 30
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "bpf-25.04-nft-no-fv-with-ut"
          - name: FELIX_FV_BPFATTACHTYPE
            value: "tc"
        commands:
          - source felix/.semaphore/fv-prologue
          # Only run the UT that checks that the precompiled BPF binaries are loadable.
          - export UT_FOCUS="TestPrecompiledBinariesAreLoadable"
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
- name: "Felix: BPF tests on Ubuntu 25.04 with jitharden=2 (nftables)"
  run:
    when: "${CHANGE_IN(felix,typha,non-go:/.semaphore/vms/)}"
  dependencies:
    - "Felix: Build"
  task:
    jobs:
      - name: "Felix: BPF tests on Ubuntu 25.04 with jitharden=2"
        execution_time_limit:
          minutes: 60
        env_vars:
          - name: FELIX_TEST_GROUP
            value: "bpf-25.04-nft-with-ut-jitharden"
          - name: FELIX_FV_BPFATTACHTYPE
            value: "tc"
        commands:
          - source felix/.semaphore/fv-prologue
          # Limit to BPF TCP+conntrack tests to reduce overall runtime.
          - export FV_FOCUS='_BPF_.*tcp.*ct=true'
          - export NUM_FV_BATCHES=16
          - .semaphore/vms/run-tests-on-vms ${VM_PREFIX}
    epilogue:
      always:
        commands:
          - source felix/.semaphore/fv-epilogue
    secrets:
      - name: google-service-account-for-gce
