variables:
  - &node_image 'node:22-alpine'
  - &branch 'master'

when:
  - event: push
    branch: *branch

steps:
  - name: Install server dependencies
    image: *node_image
    commands:
      - cd server
      - yarn install --frozen-lockfile
  - name: Install client dependencies
    image: *node_image
    commands:
      - cd client
      - yarn install --frozen-lockfile
  - name: Build server
    depends_on: [Install server dependencies]
    image: *node_image
    commands:
      - cd server
      - yarn build
  - name: Build client
    depends_on: [Install client dependencies]
    image: *node_image
    commands:
      - cd client
      - yarn build
  - name: Build Docker image
    depends_on: [Build server, Build client]
    image: woodpeckerci/plugin-docker-buildx
    settings:
      dockerfile: Dockerfile-Woodpecker
      platforms: linux/amd64
      registry:
        from_secret: REPO_URL
      username:
        from_secret: REPO_USERNAME
      password:
        from_secret: REPO_PASSWORD
      repo:
        from_secret: REPO_NAME
  - name: Discord notification - build
    image: appleboy/drone-discord
    depends_on: [Build Docker image]
    when:
      - status: [success, failure]
    settings:
      webhook_id:
        from_secret: DISCORD_WEBHOOK_ID
      webhook_token:
        from_secret: DISCORD_WEBHOOK_TOKEN
      message: "{{#success build.status}}✅ Sestavení {{build.number}} proběhlo úspěšně.{{else}}❌ Sestavení {{build.number}} selhalo.{{/success}}\n\nPipeline: {{build.link}}\nPoslední commit: {{commit.message}}Autor: {{commit.author}}"