kind: pipeline
type: docker
name: deploy

steps:
  # GO api
  - name: build_api
    image: golang
    environment:
        GIN_MODE: release
    commands:
      - cd Api
      - go build
  # Platformio esp firmware
  - name: build_esp
    image: python:slim
    commands:
      - pip install -U platformio
      - cd ESP-Temp-Humidity
      - pio run
  # C# frontend
  # upload docker
  - name: upload_frontend
    image: plugins/docker
    when:
      branch:
        - master
    settings:
      context: ManagementPage
      dockerfile: ManagementPage/ManagementPage/Dockerfile
      repo: registry.jacknet.io/51m0n/environment-api
      username: simon
      password:
        from_secret: docker_password
      registry: registry.jacknet.io
      auto_tag: true
  # upload docker
  - name: upload_api
    depends_on:
      - build_api
    image: plugins/docker
    when:
      branch:
        - master
    settings:
      context: Api
      dockerfile: Api/Dockerfile
      repo: registry.jacknet.io/51m0n/environment-api
      username: simon
      password:
        from_secret: docker_password
      registry: registry.jacknet.io
      auto_tag: true
# upload firmware blob
  - name: upload_esp
    image: plugins/gitea-release
    depends_on:
      - build_esp
    # This step is only run when a branch is tagged in Gitea.
    when:
      event: 
        - tag
      branch:
        - master
    settings:
      base_url: https://git.jacknet.io
      api_key:
        from_secret: gitea_token
      files:
        - ESP-Temp-Humidity\.pio\build\esp07\firmware.bin
      checksum:
        - sha1