Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.38 KiB
Newer Older
Reiter, Christoph's avatar
Reiter, Christoph committed
image: registry.gitlab.tugraz.at/dbp/relay/dbp-relay-server-template/main:v2
Reiter, Christoph's avatar
Reiter, Christoph committed

before_script:
  - 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "git@gitlab.tugraz.at:"'
  - 'git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.tugraz.at/".insteadOf "https://gitlab.tugraz.at/"'
Reiter, Christoph's avatar
Reiter, Christoph committed

variables:
  COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/_composer_cache"

cache:
  key: ${CI_PROJECT_PATH}
  paths:
    - _composer_cache

stages:
  - test
  - deploy
Bekerle, Patrizio's avatar
Bekerle, Patrizio committed
  - e2e
Reiter, Christoph's avatar
Reiter, Christoph committed

.test_defaults: &test_defaults
  script:
    - sudo update-alternatives --set php "/usr/bin/${PHP}"
    - composer install
    - composer test

test-php7.3:
  stage: test
  variables:
    PHP: "php7.3"
  <<: *test_defaults

test-php7.4:
  stage: test
  variables:
    PHP: "php7.4"
  <<: *test_defaults

test-php8.0:
  stage: test
  variables:
    PHP: "php8.0"
  <<: *test_defaults

psalm:
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
    - composer install
    - composer run psalm

phpstan:
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
    - composer install
    - composer run phpstan

cs-fixer:
Reiter, Christoph's avatar
Reiter, Christoph committed
  stage: test
  allow_failure: true
  script:
    - sudo update-alternatives --set php /usr/bin/php7.4
Reiter, Christoph's avatar
Reiter, Christoph committed
    - composer install

.deploy_defaults: &deploy_defaults
  needs: ["test-php7.3", "test-php7.4"]
  except:
    - schedules
  stage: deploy
  script:
    - sudo update-alternatives --set php /usr/bin/php7.3
    # Add ssh key
    - mkdir -p ~/.ssh
    - echo "${DEPLOY_KEY}" | tr -d '\r' > ~/.ssh/id_rsa
    - chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_rsa
    - ssh-keyscan -t rsa "${DEPLOY_HOST}" >> ~/.ssh/known_hosts
    # Deploy
    - dep deploy --file ./.gitlab-ci/deploy.php "${CI_ENVIRONMENT_NAME}"
    - echo "Deployed to ${CI_ENVIRONMENT_URL}"
    # Simple health check
    - curl --max-time 10 --retry 3 --output /dev/null --silent --show-error --fail --location "${CI_ENVIRONMENT_URL}"

deploy_development:
  only:
    refs:
      - main
  environment:
    name: development
    url: https://api-template-dev.tugraz.at/
  variables:
    DEPLOY_HOST: mw01-dev.tugraz.at
    DEPLOY_KEY: "$DEPLOY_SSH_KEY"
  <<: *deploy_defaults
Bekerle, Patrizio's avatar
Bekerle, Patrizio committed

e2e_tests:
  only:
    refs:
      - main
  variables:
    E2E_PROJECT: rest
Bekerle, Patrizio's avatar
Bekerle, Patrizio committed
  stage: e2e
  trigger:
    project: dbp/e2e-tests
    strategy: depend