kind: pipeline
name: clone-prepare-build-sign-release

platform:
  os: linux
  arch: amd64

clone:
  disable: false
  depth: 50

# https://readme.drone.io/user-guide/pipeline/
# https://docs.drone.io/reference/environ/
# https://github.com/drone/drone
steps:




#http://plugins.drone.io/drone-plugins/drone-docker/
#https://github.com/drone-plugins/drone-docker
- name: prepare
  image: plugins/docker
  settings:
    registry: reg.unino.de
    insecure: false
    #auth: authtoken
    username:
      from_secret: reg-user
    password:
      from_secret: reg-pass
    repo: reg.unino.de/library/debian-devel
    #mirror: registry.hub.docker.com/library/busybox

    dry_run: true


    #bip: false
    #context: /drone
    #custom_dns:
    #storage_driver: aufs # aufs, overlay or vfs

    #debug: true
    #launch_debug: true
    #target: production # build target from dockerfile, e.g. production, debug
    dockerfile: Dockerfile

    auto_tag: false
    auto_tag_suffix: linux-amd64
    force_tag: true
    tags:
      - latest
    build_args:
      - HTTP_PROXY: http://172.17.0.1:3142
      - BUILDDEPS: build-essential libc6-dev libhidapi-dev libssl-dev zip





- name: build
  image: debian:stable-slim
  when:
    event: [ push, tag ]
  depends_on: [ prepare ]
  environment:
    MAKEFLAGS: -j 4
    BUILDDEPS: build-essential libc6-dev libhidapi-dev libssl-dev zip
  commands:
    - | # Use HTTP caching proxy for APT, avoid HTTPS pulls
      cat >> /etc/apt/apt.conf.d/01-proxy <<-EOF
        Acquire::http  { Proxy "http://172.17.0.1:3142"; }
        Acquire::https { Proxy "https://"; };
      EOF
    - apt-get update && 
      apt-get -y upgrade && 
      apt-get -y install $BUILDDEPS
    - export MAKEFLAGS && make
    - CONTENT=${DRONE_REPO_NAME}
    - test -n "${DRONE_TAG}" && 
      RELEASE=${DRONE_REPO_NAME}-${DRONE_TAG}-bin || 
      RELEASE=${DRONE_REPO_NAME}-bin
    - mv dist $CONTENT
    - ls -la $CONTENT ; 
      find $CONTENT -type f -exec md5sum '{}' \;
    - rm -rf release ; 
      mkdir release
    - zip -rp   release/$RELEASE.zip    $CONTENT
    - tar -czvf release/$RELEASE.tar.gz $CONTENT
    - tar -cJvf release/$RELEASE.tar.xz $CONTENT
    - rm -rf $CONTENT
    - ls -la release ; 
      find release -type f -exec md5sum '{}' \;
    - printf '\n\n\n======= BUILD FINISHED. =======\n\n\n'

# http://plugins.drone.io/drone-plugins/drone-gpgsign/
# https://github.com/drone-plugins/drone-gpgsign
- name: sign
  image: plugins/gpgsign
  when:
    event: [ push, tag ]
  depends_on: [ build ]
  settings:
    key: 
      from_secret: gpg-key
    passphrase: 
      from_secret: gpg-pass
    detach_sign: true
    clear_sign: false
    files:
      - release/*
    excludes:
      - release/*.asc

# http://plugins.drone.io/drone-plugins/drone-gitea-release/
# https://github.com/drone-plugins/drone-gitea-release
- name: release
  image: plugins/gitea-release
  when:
    event: [ tag ]
#  depends_on: [ sign ]
  depends_on: [ sign ]
  settings:
    title: Release ${DRONE_REPO_NAME}-${DRONE_TAG} # file or string
    note: RELEASE.md # file or string
    draft: false
    prerelease: false
    base_url: https://git.unino.de
    insecure: false
    api_key:
      from_secret: gitea-release
    checksum: [ md5 ] # [ md5, sha1, sha256, sha512, adler32, crc32 ]
    file_exists: overwrite # overwrite, skip, fail
    files: # wildcard * matching files with prefix supported
      - release/*
