# More examples of Codefresh YAML can be found at
# https://codefresh.io/docs/docs/yaml-examples/examples/

version: "1.0"
# Stages can help you organize your steps in stages
stages:
  - "clone"
  - "build"
  - "integration"
  - "push"
  - "notification"

steps:
  clone:
    title: "Cloning repository"
    type: "git-clone"
    repo: "https://github.com/codefresh-io/cli/"
    # Clone the master branch. Or, use ${{CF_BRANCH}} to get branch name from trigger
    # Learn more at https://codefresh.io/docs/docs/codefresh-yaml/variables/
    revision: "master"
    stage: "clone"

  build:
    title: "Building Docker image"
    type: "build"
    image_name: "codefresh-io/cli"
    working_directory: "${{clone}}"
    # Set 'latest' tag on the image. Or, use built-in variables
    # like ${{CF_BRANCH_TAG_NORMALIZED}} to use the current branch name/tag.
    tag: "latest"
    dockerfile: "Dockerfile"
    stage: "build"

  approval_for_push:
    type: "pending-approval"
    title: "Should we run push"
    when:
      branch:
        only:
          - "master"
    stage: "push"

  parallel_push:
    type: "parallel"
    steps:
      annotate_build:
        title: "Annotating Build"
        image: "${{build}}"
        working_directory: "IMAGE_WORK_DIR"
        commands:
          - "echo Annotating Build..."
        on_success:
          metadata:
            set:
              - ${{build.imageId}}:
                  - CF_QUALITY: true
        on_error:
          metadata:
            set:
              - ${{build.imageId}}:
                  - CF_QUALITY: false
      push:
        title: "Pushing image to cfcr"
        type: "push"
        image_name: "codefresh-io/cli"
        registry: "cfcr"
        candidate: "${{build}}"
        tags:
          # Set 'latest' tag on the image. Or, use built-in variables
          # like ${{CF_BRANCH_TAG_NORMALIZED}} to use the current branch name/tag.
          - "latest"
    stage: "push"

  SendToSlack:
    title: "Sending message to slack"
    image: "codefreshplugins/slacknotifier"
    environment:
      - "SLACK_HOOK_URL=${{SLACK_WEBHOOK_URL}}"
      - "SLACK_TEXT=${{SLACK_TEXT}}"
      - "SLACK_ATTACHMENTS=${{SLACK_ATTACHMENTS}}"
    stage: "notification"

