---
kind: pipeline
type: docker
name: default


steps:

- name: build created
  image: alpine
  commands:
    - echo ${DRONE_BUILD_CREATED}

- name: restore cache
  image: drillster/drone-volume-cache
  settings:
    restore: true
    mount:
      - ./node_modules
  volumes:
  - name: cache
    path: /cache

- name: npm install
  image: node:12
  commands:
  - npm install

- name: npm run build
  image: node:12
  commands:
  - npm run build

- name: rebuild cache
  image: drillster/drone-volume-cache
  settings:
    rebuild: true
    mount:
      - ./node_modules
  volumes:
  - name: cache
    path: /cache

- name: deliver dist
  image: node:12
  commands:
  - echo ${DRONE_BUILD_CREATED}
  - git clone https://www.versioncontrol.me/frontwork-distribution/${DRONE_REPO_NAME}.git; cd ${DRONE_REPO_NAME} && rm -rf ./*; cp -r ../dist/* .; cp ../LICENSE.md .
  - git add --all; git -c user.email="${DRONE_COMMIT_AUTHOR_EMAIL}" -c user.name="${DRONE_COMMIT_AUTHOR}" commit --all --allow-empty --message "generated from tag ${DRONE_TAG}"
  - (git tag ${DRONE_TAG} && git push --force https://$GIT_USER:$GIT_PASSWORD@www.versioncontrol.me/frontwork-distribution/${DRONE_REPO_NAME}.git master ${DRONE_TAG}) || true
  environment:
    GIT_USER:
      from_secret: git_user
    GIT_PASSWORD:
      from_secret: git_password
  when:
    event:
    - tag

- name: deliver container
  image: plugins/docker
  settings:
    registry: registry.conatum.eu
    insecure: true
    repo: registry.conatum.eu/frontwork/admin
    tags: ${DRONE_BUILD_CREATED}

- name: release container
  image: plugins/docker
  settings:
    repo: frontwork/admin
    tags: ${DRONE_TAG}
    username: frontwork
    password:
      from_secret: docker_password
  when:
    event:
    - tag
    
volumes:
- name: cache 
  host:
    path: /tmp