definitions:
  caches:
    node-theme: htdocs/content/themes/theme-ev/node_modules
  steps:
    - step: &build-js
        name: Build Theme assets
        image: node:10
        caches:
          - node-theme
        script:
          - cd htdocs/content/themes/theme-ev
          - yarn install
          - yarn production
        artifacts:
          - htdocs/content/themes/theme-ev/dist/**
    - step: &build-php
        name: Build php
        image: composer
        caches:
          - composer
        script:
          - cp .env.sample .env
          - composer install --no-dev --no-interaction
        artifacts:
          - vendor/**
          - htdocs/content/plugins/**
          - htdocs/content/mu-plugins/**
          - htdocs/content/themes/**
          - htdocs/cms/**
    - step: &deploy-sync
        name: Test Deploy
        deployment: Test
        image: acm1/gettext
        script:
          - envsubst < $POST_DEPLOY_SCRIPT > post-deploy.sh
          - pipe: atlassian/rsync-deploy:0.4.3
            variables:
              USER: $SERVER_USER
              SERVER: $SERVER_IP
              REMOTE_PATH: $SERVER_PATH
              LOCAL_PATH: '.'
              DEBUG: 'true'
              EXTRA_ARGS: '-v --exclude-from=.deploy/excluded-files'
          - pipe: atlassian/ssh-run:0.2.6
            variables:
              SSH_USER: $SERVER_USER
              SERVER: $SERVER_IP
              MODE: 'script'
              COMMAND: 'post-deploy.sh'
          


pipelines:
  branches:
    test:
      - parallel:
        - step: *build-js
        - step: *build-php
      - step:
          <<: *deploy-sync
          deployment: Test
          name: TEST Deploy
    staging:
      - parallel:
        - step: *build-js
        - step: *build-php
      - step:
          <<: *deploy-sync
          deployment: Staging
          name: Staging Deploy