kind: pipeline
type: exec
name: default

steps:
- name: test
  commands:
  - mkdir -p $HOMEPATH/.docker; echo $IMAGE_PULL_SECRETS > $HOMEPATH/.docker/config.json
  - VERSION=${DRONE_TAG:-latest} make test 
  environment:
    DEV_REGISTRY:
      from_secret: dev_registry
    DRYCC_REGISTRY:
      from_secret: drycc_registry
    IMAGE_PULL_SECRETS:
      from_secret: container_pull_secrets
  when:
    event:
    - push
    - tag
    - pull_request

- name: build
  commands:
  - mkdir -p $HOMEPATH/.docker; echo $IMAGE_PULL_SECRETS > $HOMEPATH/.docker/config.json
  - sed -i "s#canary#${DRONE_TAG}#g" version/version.go
  - VERSION=${DRONE_TAG} make build
  environment:
    DEV_REGISTRY:
      from_secret: dev_registry
    DRYCC_REGISTRY:
      from_secret: drycc_registry
    IMAGE_PULL_SECRETS:
      from_secret: container_pull_secrets
  when:
    event:
    - tag

- name: release
  commands:
  - docker run --rm
      -e DRONE_BUILD_EVENT=tag
      -e DRONE_REPO_OWNER="$DRONE_REPO_OWNER"
      -e DRONE_REPO_NAME="$DRONE_REPO_NAME"
      -e PLUGIN_API_KEY="$API_KEY"
      -e PLUGIN_BASE_URL="https://api.github.com/"
      -e PLUGIN_UPLOAD_URL="https://uploads.github.com/"
      -e DRONE_COMMIT_REF="refs/tags/$DRONE_TAG"
      -e PLUGIN_OVERWRITE="true"
      -e PLUGIN_FILES="_dist/*"
      -v $(pwd):$(pwd)
      -w $(pwd)
      docker.io/plugins/github-release
  environment:
    API_KEY:
      from_secret: github_token
  when:
    event: tag