---
version: '3'

vars:
  SHARED_COMMON_FOLDER: common
  VARIABLES_URL: https://gitlab.com/megabyte-labs/documentation/shared/-/raw/master/common.json

tasks:
  copy:
    log:
      error: Finished copying common files
      start: Copying common files
      success: Copied common files
    cmds:
      - mv .gitlab-ci.yml .gitlab-ci.yml.bak
      - cd ./{{.SHARED_COMMON_FOLDER}} && cp -rf . .. && cd ..
      - mv .gitlab-ci.yml.bak .gitlab-ci.yml
      - task: :common:husky:permissions

  template:
    cmds:
      - task: template:files

  template:files:
    deps:
      - template:files:liquidjs

  template:files:liquidjs:
    cmds:
      - task: :upstream:template:liquidjs
        vars:
          ADDITIONAL_IGNORE_FOLDERS: -path './{{.SHARED_COMMON_FOLDER}}*' -o -path './deprecated*' -o

  variables:
    log:
      error: Encountered error in `.variables.json` generation sequence
      start: Beginning `.variables.json` generation sequence
      success: Completed `.variables.json` generation sequence
    cmds:
      - curl -s {{.VARIABLES_URL}} > .variables.json
      - task: :upstream:variables
        vars:
          INPUT_FILE: .variables.json
          OUTPUT_FILE: .variables.json