kind: pipeline
name: clone-prepare-build-sign-release
# https://github.com/drone/drone

platform:
  os: linux
  arch: amd64

clone:
  disable: false
  depth: 50

steps:
- name: prepare
  image: plugins/docker
  # http://plugins.drone.io/drone-plugins/drone-docker/
  # https://github.com/drone-plugins/drone-docker
  when:
    event: [ tag ] # [ push, tag ]
  settings:
    dry_run: false
    registry: reg.unino.de
    insecure: false
    #auth: authtoken for registry
    username: { from_secret: reg-user }
    password: { from_secret: reg-pass }
    repo: reg.unino.de/develop/debian-${DRONE_REPO_NAMESPACE}-${DRONE_REPO_NAME}
    #mirror: registry-1.docker.io
    bip: 172.17.0.1/16 # set bridge if non-existent
    context: /drone/src # defaults to root of git repo
    #custom_dns: 127.0.0.11 # defaults to 8.8.8.8 and 8.8.4.4 
    storage_driver: overlay2 # aufs, overlay or vfs
    #debug: true
    #launch_debug: true
    target: builder # Dockerfile build target e.g. builder, debug, production
    dockerfile: Dockerfile
    auto_tag: false
    auto_tag_suffix: linux-amd64
    force_tag: true
    tags: [ latest, builder ]
    build_args: # custom args for docker build, e.g. additional BUILD_DEPS etc.
      - DEB_RELEASE=stretch
      - BUILD_DEPS=libhidapi-dev libssl-dev zip


- name: build
  image: reg.unino.de/develop/debian-${DRONE_REPO_NAMESPACE}-${DRONE_REPO_NAME}:latest
  # https://readme.drone.io/user-guide/pipeline/
  # https://docs.drone.io/reference/environ/
  when:
    event: [ push, tag ]
  depends_on: [ clone, prepare ]
  environment:
    MAKEFLAGS: -j 1
  commands:
    - 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 -rpq release/$RELEASE.zip    $CONTENT
    - tar -czf release/$RELEASE.tar.gz $CONTENT
    # - tar -cJf release/$RELEASE.tar.xz $CONTENT
    - rm -rf $CONTENT ;
      ls -la release
    - find release -type f -exec md5sum '{}' \;
    - exit 0 ; ░▒▓█ BUILD END █▓▒░


- name: sign
  image: plugins/gpgsign
  # http://plugins.drone.io/drone-plugins/drone-gpgsign/
  # https://github.com/drone-plugins/drone-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
  # http://plugins.drone.io/drone-plugins/drone-gitea-release/
  # https://github.com/drone-plugins/drone-gitea-release
  when:
    event: [ tag ]
  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/*
