image: jakzal/phpqa

include:
  - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'

before_script:
    - composer install --no-scripts

cache:
    paths:
        - vendor/

stages:
    - SecurityChecker
    - CodingStandards
    - UnitTests
    - publish

security-checker:
    stage: SecurityChecker
    except:
        - main
        - dev
    script:
        - local-php-security-checker  --path=./composer.lock
    allow_failure: false

phpcs:
    stage: CodingStandards
    except:
        - main
        - dev
    script:
        - phpcs --version && phpcs --standard=PSR12 --ignore=./src/Kernel.php ./src
    allow_failure: false

phpstan:
    stage: CodingStandards
    except:
        - main
        - dev
    script:
        - phpstan --version && phpstan analyse ./src
    allow_failure: false

twig-lint:
    stage: CodingStandards
    except:
        - main
        - dev
    script:
        - twig-lint --version && twig-lint lint ./templates
    allow_failure: false
    
publish:
  stage: publish
  image: docker:dind
  services:
    - docker:dind
  only:
    - main
  variables:
    DOCKER_DRIVER: overlay2
    registry_host: ''
    registry_user: ''
    registry_pass: ''
    registry_img: ''
  before_script:
    - apk add jq
  script:
    - APP_VERSION=$(cat package.json | jq .version -r)
    - docker login $registry_host -u $registry_user -p $registry_pass
    - docker build -f ./Dockerfile -t $registry_host/$registry_img:$APP_VERSION .
    - docker push $registry_host/$registry_img:$APP_VERSION