variables:
  FONT_AWESOME_TOKEN: monsupertoken

default:
  image: registry.gitlab.sl-projects.com/sofianelasri/rann-graphic-design-website:latest

stages:
  - test
  - deploy
  - sentry_release

unit_test:
  stage: test
  before_script:
    - npm config set @awesome.me:registry https://npm.fontawesome.com/
    - npm config set @fortawesome:registry https://npm.fontawesome.com/
    - npm config set //npm.fontawesome.com/:_authToken $FONT_AWESOME_TOKEN
  script:
    - cp .env.testing .env
    - composer install --prefer-dist --no-interaction
    - php artisan key:generate
    - php artisan migrate
    - npm install
    - npm run build
    - php artisan test

deploy_production:
  stage: deploy
  before_script:
    - apt-get update && apt-get install -y --no-install-recommends openssh-client
    - composer global require "laravel/envoy"
  script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - /config/composer/vendor/bin/envoy run deploy --commit="$CI_COMMIT_SHA"
  environment:
    name: production
    url: https://rann-graphic-design.fr/
  when: on_success
  rules:
    - if: $CI_COMMIT_BRANCH == "master"

sentry_release:
  stage: sentry_release
  image: getsentry/sentry-cli:latest
  script:
    - sentry-cli releases new -p $SENTRY_PROJECT v$CI_COMMIT_SHORT_SHA
    - sentry-cli releases set-commits --auto v$CI_COMMIT_SHORT_SHA
    - sentry-cli releases finalize v$CI_COMMIT_SHORT_SHA
  only:
    - master
  variables:
    SENTRY_AUTH_TOKEN: $SENTRY_AUTH_TOKEN
    SENTRY_ORG: $SENTRY_ORG
    SENTRY_PROJECT: $SENTRY_PROJECT