---
kind: pipeline
type: docker
name: node16

steps:
- name: install-deps
  image: node:16
  commands:
  - npm install

- name: check-lockfile
  image: node:16
  depends_on:
  - install-deps
  commands:
  - npm run check-lockfile

- name: lint
  image: node:16
  depends_on:
  - install-deps
  commands:
  - npm run lint

- name: optimize-images
  image: node:16
  depends_on:
  - install-deps
  commands:
  - npm run build:images

- name: generate-calendar
  image: node:16
  depends_on:
  - install-deps
  commands:
  - npm run build:calendar

- name: build
  image: node:16
  depends_on:
  - optimize-images
  commands:
  - USE_LDAP=true npm run build:web

- name: export
  image: node:16
  depends_on:
  - generate-calendar
  - build
  commands:
  - npm run export

- name: deploy (staging)
  image: node:16
  depends_on:
  - export
  environment:
    TOKEN:
      from_secret: STAGING_TOKEN
  commands:
  - 'curl -XPOST -H "Authorization: $TOKEN" -H "X-Branch: $DRONE_BRANCH" "https://csclub.uwaterloo.ca/~a3thakra/update-csc/"'
  when:
    branch:
      exclude:
      - main

- name: deploy (production)
  image: node:16
  depends_on:
  - export
  environment:
    SSH_KEY:
      from_secret: DEPLOYMENT_SSH_KEY
  commands:
  - 'echo "$SSH_KEY" > /tmp/ssh_key'
  - chmod 600 /tmp/ssh_key
  - ssh -4 -i /tmp/ssh_key www@caffeine.csclub.uwaterloo.ca -o StrictHostKeyChecking=no '~/bin/deploy-website.sh'
  when:
    branch:
    - main

trigger:
  event:
    exclude:
    - pull_request #avoid double build on PRs
