version: v1.0
name: Pod2Daemon

execution_time_limit:
  hours: 4

agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu1804

global_job_config:
  secrets:
  - name: docker-hub
  prologue:
    commands:
      - echo $DOCKERHUB_PASSWORD | docker login --username "$DOCKERHUB_USERNAME" --password-stdin
      - checkout

blocks:
  - name: 'CI'
    dependencies: []
    task:
      jobs:
        - name: Run CI
          execution_time_limit:
            minutes: 120
          commands:
            - make ci

  - name: 'CD'
    dependencies: ["CI"]
    skip:
      # Only run on branches, not PRs.
      when: "branch !~ '.+'"
    task:
      secrets:
        - name: quay-robot-calico+semaphoreci
        - name: docker
      prologue:
        commands:
          - echo $DOCKER_TOKEN | docker login --username "$DOCKER_USER" --password-stdin
          - echo $QUAY_TOKEN | docker login --username "$QUAY_USER" --password-stdin quay.io
      jobs:
        - name: Run CD
          execution_time_limit:
            minutes: 15
          commands:
            - export BRANCH_NAME=$SEMAPHORE_GIT_BRANCH
            - if [ -z "${SEMAPHORE_GIT_PR_NUMBER}" ]; then make cd CONFIRM=true; fi

  - name: Trigger pin updates
    dependencies: []
    skip:
      when: "(branch != 'master')"
    task:
      secrets:
        - name: semaphore-api
      jobs:
        - name: Trigger pin updates
          execution_time_limit:
            minutes: 5
          commands:
            - checkout
            - make semaphore-run-auto-pin-update-workflows

