kind: pipeline
type: docker
name: build-release-images
trigger:
  event:
    exclude:
    - pull_request
  ref:
    - refs/tags/**

platform:
  os: linux
  arch: amd64

steps:

- name: get-tags
  image: docker:git
  commands:
    - git fetch --tags
  depends_on:
    - clone

- name: make-tags
  image: node
  commands:
    - echo -n "${DRONE_TAG}, latest" > .tags
  depends_on:
    - get-tags

- name: build-gitea
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: git.mrmeeb.stream
    username: 
      from_secret: docker_username
    password: 
      from_secret: docker_password
    repo: git.mrmeeb.stream/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: build-github
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: ghcr.io
    username: 
      from_secret: docker_username
    password: 
      from_secret: github_token
    repo: ghcr.io/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: release-gitea
  image: goreleaser/goreleaser
  environment:
    GITEA_TOKEN:
      from_secret: gitea_token
  commands:
    - goreleaser release -f .goreleaser-gitea.yaml
  depends_on:
    - build-gitea

- name: release-github
  image: goreleaser/goreleaser
  environment:
    GITHUB_TOKEN:
      from_secret: github_token
  commands:
    - goreleaser release -f .goreleaser-github.yaml
  depends_on:
    - build-github

- name: notify
  image: plugins/slack
  when:
    status:
    - success
    - failure
  settings:
    webhook: 
      from_secret: slack_webhook
  depends_on:
    - release-gitea
    - release-github

---
kind: pipeline
type: docker
name: build-main-images
trigger:
  event:
    exclude:
    - pull_request
  ref:
    - refs/heads/main

platform:
  os: linux
  arch: amd64

steps:

- name: make-tags
  image: node
  commands:
    - echo -n "${DRONE_COMMIT_SHA:0:8}, latest" > .tags
  when:
    ref:
      - refs/heads/main
  depends_on:
    - clone

- name: build-gitea
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: git.mrmeeb.stream
    username: 
      from_secret: docker_username
    password: 
      from_secret: docker_password
    repo: git.mrmeeb.stream/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: build-github
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: ghcr.io
    username: 
      from_secret: docker_username
    password: 
      from_secret: github_token
    repo: ghcr.io/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: notify
  image: plugins/slack
  when:
    status:
    - success
    - failure
  settings:
    webhook: 
      from_secret: slack_webhook
  depends_on:
    - build-github
    - build-gitea

---
kind: pipeline
type: docker
name: build-develop-images
trigger:
  event:
    exclude:
    - pull_request
  branch:
    - develop

platform:
  os: linux
  arch: amd64

steps:
  # Set tags for develop branch - git commit SHA and 'develop'
- name: make-tags
  image: node
  commands:
    - echo -n "develop-${DRONE_COMMIT_SHA:0:8}, develop" > .tags
   
  # Build containers from develop branch
- name: build-gitea
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: git.mrmeeb.stream
    username: 
      from_secret: docker_username
    password: 
      from_secret: docker_password
    repo: git.mrmeeb.stream/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: build-github
  image: thegeeklab/drone-docker-buildx
  privileged: true
  settings:
    provenance: false
    registry: ghcr.io
    username: 
      from_secret: docker_username
    password: 
      from_secret: github_token
    repo: ghcr.io/mrmeeb/cronicle
    platforms:
      - linux/arm64
      - linux/amd64
  depends_on:
    - make-tags

- name: notify
  image: plugins/slack
  when:
    status:
    - success
    - failure
  settings:
    webhook: 
      from_secret: slack_webhook
  depends_on:
    - build-gitea
    - build-github