when:
  - branch: main
    event: push
    path:
      include: ['sb/**']
      on_empty: false

steps:
  - name: build_by_hugo
    image: hugomods/hugo
    commands:
      - hugo version
      - hugo -s sb --logLevel info

  - name: copy_to_server
    image: alpine
    environment:
      SSH_HOST:
        from_secret: ssh_host
      SSH_USER:
        from_secret: ssh_user
      SSH_KEY:
        from_secret: ssh_key
      SSH_PORT:
        from_secret: ssh_port
      TARGET_PATH:
        from_secret: target_path

    commands:
      - apk add --no-cache openssh
      - mkdir -p ~/.ssh
      - echo "$SSH_KEY" | tr -d '\r' > ~/.ssh/deployKey
      - chmod 600 ~/.ssh/deployKey
      - ssh-keyscan -H -p $SSH_PORT $SSH_HOST 2>/dev/null >> ~/.ssh/known_hosts
      - chmod 600 ~/.ssh/known_hosts
      - scp -r -i ~/.ssh/deployKey -P $SSH_PORT sb/public/* $SSH_USER@$SSH_HOST:$TARGET_PATH/
      - ssh -i ~/.ssh/deployKey -p $SSH_PORT $SSH_USER@$SSH_HOST 'touch $HOME/time_$(date +"%Y-%m-%d_%T_%N")'