when:
  event: tag
  ref: refs/tags/v*

steps:
  deploy:
    image: alpine/k8s:1.27.11
    secrets:
      - kubeconfig
    commands:
      - mkdir ~/.kube && echo "$KUBECONFIG" > ~/.kube/twhelp
      - cd ./k8s/overlays/prod
      # yamllint disable rule:quoted-strings
      - "kustomize edit set image twhelp=gitea.dwysokinski.me/twhelp/corev3:${CI_COMMIT_TAG##v}"
      - cd ../../..
      - kubectl --kubeconfig ~/.kube/twhelp -n twhelp delete jobs.batch twhelp-migrations-job || true
      - kustomize build ./k8s/overlays/prod | kubectl --kubeconfig ~/.kube/twhelp apply -n twhelp -f -

  email:
    image: deblan/woodpecker-email
    settings:
      dsn:
        from_secret: email_dsn
      from:
        address:
          from_secret: email_from_address
        name: Woodpecker
      recipients:
        - notifications@twhelp.app
      recipients_only: true
      content:
        subject:
          "[deployment - {{ pipeline.status }}] {{ repo.full_name }} ({{ commit.tag }})"
    when:
      status: [success, failure]

depends_on:
  - release
