kind: pipeline
type: docker
name: default

trigger:
  branch: [ main ]
  event:  [ push ]

# Kill the default clone entirely
clone:
  disable: true

steps:
  - name: manual clone
    image: alpine/git
    environment:
      GIT_ASKPASS: 'echo'   # prevent interactive prompts
    commands:
      - git clone --depth=50 "https://fencl:5ece5d37cd3a9988a78983b10cede284e25717f8@git.internet-master.cz/fencl/davisfe.cz.git" .
      # - git fetch origin +refs/heads/deployment:refs/remotes/origin/deployment
      # - git checkout -qf origin/deployment
      - git log -1 --oneline
      - ls -la

  - name: build and push to gitea registry
    image: plugins/docker:20.16
    settings:
      registry: git.internet-master.cz
      repo: git.internet-master.cz/fencl/davisfe.cz
      context: .
      dockerfile: Dockerfile
      tags:
        - latest
      username: fencl
      password: 5ece5d37cd3a9988a78983b10cede284e25717f8

  - name: call-portainer-webhook
    image: curlimages/curl
    commands:
      - curl -u 'howard:Papadopolus0' -X POST 'https://portainer.martinfencl.eu/api/stacks/webhooks/72df3f63-b271-4aef-9325-772a2ccbaeca'

---
kind: pipeline
type: docker
name: scrape-cron

trigger:
  event:
    - cron
  cron:
    - lipno-scraper

steps:
  - name: scrape-and-commit
    image: node:18-alpine
    environment:
      GIT_AUTHOR_NAME: drone
      GIT_AUTHOR_EMAIL: drone@internet-master.cz
      GIT_COMMITTER_NAME: drone
      GIT_COMMITTER_EMAIL: drone@internet-master.cz
    commands:
      - apk add --no-cache git
      - npm ci
      - node scripts/scrapeLipno.js
      - git add public/data/lipno.json
      - git commit -m "chore: update lipno reservoir data [CI SKIP]" || true
      - git push origin main || true