---
kind: pipeline
name: "test python and publish to dockerhub"
type: docker

clone:
  disable: true

steps:
- name: skip_tls_clone
  image: plugins/git
  settings:
    depth: 10
    skip_verify: true

- name: semantic-release
  purge: true
  image: cphapt/cpha-semantic-release:latest
  environment:
    GITEA_TOKEN: 
      from_secret: gitea_token
  commands:
  - semantic-release

- name: gitea_release
  image: plugins/gitea-release
  settings:
    api_key:
      from_secret: gitea_token
    base_url: https://git.sthope.dev
    files: 
      - ./randomPwd/*
    checksum:
      - md5
      - sha1
      - sha256
      - sha512
      - adler32
      - crc32
  when:
    event: tag

- name: setup-virtualenv
  image: python:3.7-alpine
  commands:
  - pip install virtualenv
  - virtualenv /tmp/shared/.venv
  - source /tmp/shared/.venv/bin/activate
  volumes:
  - name: shared
    path: /tmp/shared
  when:
    event:
      include:
      - tag

- name: testing
  image: python:3.7-alpine
  commands:
  - source /tmp/shared/.venv/bin/activate
  - python randomPwd/randomPwd.py
  - echo $$DRONE_COMMIT_SHA > .tags
  volumes:
  - name: shared
    path: /tmp/shared
  when:
    event:
      include:
      - tag

- name: build-and-publish
  image: plugins/docker
  settings:
    purge: false
    debug: false
    auto_tag: true
    dockerfile: Dockerfile
    repo: sthopeless/randompwd
    username:
      from_secret: docker_username
    password:
      from_secret: docker_password
  when:
    event:
      include:
      - tag

- name: discord
  image: appleboy/drone-discord
  environment:
    DISCORD_WEBHOOK_ID:
      from_secret: discord_webhook_id
    DISCORD_WEBHOOK_TOKEN:
      from_secret: discord_webhook_token
  settings:
    message: >
      {{#success build.status}}
      ✅ Build #{{build.number}} of `{{repo.name}}` succeeded.
       
      📝 Commit by {{commit.author}} on `{{commit.branch}}`:
      ```
      {{commit.message}}
      ```
      🌐 <{{ build.link }}>
      {{else}}
      ❌ Build #{{build.number}} of `{{repo.name}}` failed.
      📝 Commit by {{commit.author}} on `{{commit.branch}}`:
      ```
      {{commit.message}}
      ```
      🌐 <{{ build.link }}>
      {{/success}}
  when:
    status:
    - failure

volumes:
- name: shared
  temp: {}