default:
  before_script:
    - cp sample.database.yml database.yml
    - cp sample_dot_env .env
    - yarn install

  tags:
    - golang
    - postgres

stages:
  - test
  - preprod
  - production

test:

  stage: test

  variables:
    GO_ENV: "test"

  only:
    - branches

  artifacts:
    paths:
      - tmp
    expire_in: 1 week

  cache:
    paths:
      - node_modules

  script:
    - make test

staging:
  stage: preprod

  variables:
    GO_ENV: "preprod"

  dependencies:
    - test

  only:
    - develop
    - master

  artifacts:
    paths:
      - public
      - bin
    expire_in: 1 week

  script:
    - make build
    - cp sample_dot_env ./bin/.env
    - rsync -v -r -e ssh ./bin/ shipyard.nekutima.eu:/usr/local/www/cgi-bin/app.shipyard.nekutima.eu

deploy:
  stage: production

  variables:
    GO_ENV: "production"

  when: manual

  dependencies:
    - staging

  only:
    - master

  artifacts:
    paths:
      - public
      - bin
    expire_in: 1 week

  script:
    - make build
    - cp sample_dot_env ./bin/.env
    - rsync -v -r -e ssh ./bin/ appcluster.nekutima.eu:/usr/local/www/cgi-bin/app.nekutima.eu/
