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

  - name: xgettext-go
    image: golang:1.26
    environment:
      GOPRIVATE: coopcloud.tech
    commands:
      - go run git.coopcloud.tech/toolshed/xgettext-go@latest
        -o pkg/i18n/locales/abra.pot
        --keyword=i18n.G
        --keyword-ctx=i18n.GC
        --sort-output
        --add-comments-tag="translators"
        $(find . -name "*.go" -not -path "*vendor*" | sort)
    depends_on:
      - make check
    when:
      event:
        exclude:
          - tag

  - name: xgettext-go status
    image: golang:1.26-alpine3.22
    commands:
      - apk add patchutils git make
      - cd /drone/src
      - sed -i "s/charset=CHARSET/charset=UTF-8/g" pkg/i18n/locales/*.pot
      - git diff pkg/i18n/locales/abra.pot | grepdiff --output-matching=hunk POT-Creation-Date | git apply --reverse --allow-empty
      - git diff
      - git diff-files --exit-code
    depends_on:
      - xgettext-go
    when:
      event:
        exclude:
          - tag

  - name: make test
    image: golang:1.26
    environment:
      ABRA_DIR: /root/.abra_test
    commands:
      - make test
    depends_on:
      - make check

  - name: publish image
    image: plugins/docker
    settings:
      auto_tag: true
      username: abra-bot
      password:
        from_secret: git_coopcloud_tech_token_abra_bot
      repo: git.coopcloud.tech/toolshed/abra
      tags: dev
      registry: git.coopcloud.tech
    when:
      branch:
        - main
    depends_on:
      - make check
      - make test

  - name: on-demand 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/toolshed/abra/raw/branch/main/scripts/tests/run-ci-int -O run-ci-int
          chmod +x run-ci-int
          sh run-ci-int
    when:
      ref:
        - refs/heads/int-*
    depends_on:
      - make check
      - make test

  - name: nightly 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/toolshed/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: {}

trigger:
  action:
    exclude:
      - synchronized
