---
kind: pipeline
name: coopcloud.tech/abra
steps:
  - name: make check
    image: golang:1.22
    commands:
      - make check

  - name: make test
    image: golang:1.22
    environment:
      CATL_URL: https://git.coopcloud.tech/coop-cloud/recipes-catalogue-json.git
    commands:
      - mkdir -p $HOME/.abra
      - git clone $CATL_URL $HOME/.abra/catalogue
      - make test
    depends_on:
      - make check

  - name: fetch
    image: docker:git
    commands:
      - git fetch --tags
    depends_on:
      - make check
      - make test
    when:
      event: tag

  - name: release
    image: goreleaser/goreleaser:v1.24.0
    environment:
      GITEA_TOKEN:
        from_secret: goreleaser_gitea_token
    volumes:
      - name: deps
        path: /go
    commands:
      - goreleaser release
    depends_on:
      - fetch
    when:
      event: tag

  - name: publish image
    image: plugins/docker
    settings:
      auto_tag: true
      username: 3wordchant
      password:
        from_secret: git_coopcloud_tech_token_3wc
      repo: git.coopcloud.tech/coop-cloud/abra
      tags: dev
      registry: git.coopcloud.tech
    when:
      branch:
        - main
    depends_on:
      - make check
      - make test

  - name: integration test
    image: appleboy/drone-ssh
    settings:
      host:
        - int.coopcloud.tech
      username: abra
      key:
        from_secret: abra_int_private_key
      port: 22
      command_timeout: 60m
      script_stop: true
      request_pty: true
      script:
        - |
          wget https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/tests/run-ci-int -O run-ci-int
          chmod +x run-ci-int
          sh run-ci-int
    when:
      event:
        - cron:
      cron:
        # @daily https://docs.drone.io/cron/
        - integration 

volumes:
  - name: deps
    temp: {}
