Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.14 KiB
stages:
  - install_dependencies
  - test
  - sonar
  - dockerize
  - deploy

variables:
    VERSION: "3.6"
    SONARQUBE_URL: https://sonarqube.lam.fr

install_dependencies:
    image: jakzal/phpqa:php8.0
    stage: install_dependencies
    script:
        - composer install --ignore-platform-reqs
    cache:
        key: ${CI_COMMIT_REF_SLUG}
        paths:
            - vendor
        policy: pull-push
    only:
        refs:
            - develop

test:
    image: jakzal/phpqa:php8.0
    stage: test
    cache: 
        key: ${CI_COMMIT_REF_SLUG}
        paths:
            - vendor
        policy: pull
    script:
        - phpdbg -qrr ./vendor/bin/phpunit --bootstrap ./tests/bootstrap.php --whitelist src --coverage-clover ./coverage/clover.xml --log-junit ./coverage/junit-logfile.xml --coverage-text --colors=never ./tests
    artifacts:
        paths:
            - coverage
    only:
        refs:
            - develop

sonar_scanner:
    image: sonarsource/sonar-scanner-cli:latest
    stage: sonar
    script:
        - sonar-scanner -Dsonar.projectKey=anis-server -Dsonar.sources=src -Dsonar.projectVersion=$VERSION -Dsonar.host.url=$SONARQUBE_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.php.tests.reportPath=./coverage/junit-logfile.xml -Dsonar.php.coverage.reportPaths=./coverage/clover.xml
    only:
        refs:
            - develop

dockerize:
    image: docker:stable
    stage: dockerize
    cache: 
        key: ${CI_COMMIT_REF_SLUG}
        paths:
            - vendor
        policy: pull
    dependencies: []
    script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker pull $CI_REGISTRY/anis/anis-server/server:latest || true
        - docker build --cache-from $CI_REGISTRY/anis/anis-server/server:latest -t $CI_REGISTRY/anis/anis-server/server:latest .
        - docker push $CI_REGISTRY/anis/anis-server/server:latest
    only:
        refs:
            - develop

deploy:
    image: alpine
    stage: deploy
    variables:
        GIT_STRATEGY: none
    cache: {}
    dependencies: []
    script:
        - apk add --update curl
        - curl -XPOST $DEV_WEBHOOK
    only:
        refs:
            - develop