ldc-mesbr-app/.gitlab-ci.yml

153 lines
4 KiB
YAML

include:
- project: "ldc-web/shared-ci"
ref: "main"
file: "security/security.yml"
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
stages:
- deps
- lint
- test
- security
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS"
when: never
- if: "$CI_COMMIT_BRANCH"
variables:
PHP_CI_IMAGE: "$CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest"
# ---------------------------------------------------------
# DEPENDENCIES
# ---------------------------------------------------------
composer_vendor_dev:
stage: deps
image: $PHP_CI_IMAGE
cache:
key:
files:
- composer.lock
paths:
- vendor/
before_script:
- composer config gitlab-token.lab.s-web.fr "${CI_DEPLOY_USER}" "${CI_DEPLOY_PASSWORD}"
script:
- composer install --no-interaction --no-scripts --no-progress --prefer-dist
artifacts:
paths:
- vendor/
expire_in: 2h
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH"
# ---------------------------------------------------------
# BASE TEMPLATE
# ---------------------------------------------------------
.php-base: &php-base
image: $PHP_CI_IMAGE
needs:
- job: composer_vendor_dev
artifacts: true
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
# ---------------------------------------------------------
# LINT & STATIC ANALYSIS
# ---------------------------------------------------------
phplint:
<<: *php-base
stage: lint
variables:
TEXT_REPORT: php-l-report.txt
script:
- vendor/bin/parallel-lint --exclude vendor --exclude storage --exclude bootstrap --exclude node_modules --exclude .intellipest . > "$TEXT_REPORT" 2>&1; status=$?
- cat "$TEXT_REPORT"
- exit $status
artifacts:
when: always
expose_as: "php-l report"
paths:
- php-l-report.txt
pint:
<<: *php-base
stage: lint
variables:
PINT_REPORT: pint-report.txt
script:
- vendor/bin/pint --test > "$PINT_REPORT" 2>&1; status=$?
- cat "$PINT_REPORT"
- exit $status
artifacts:
when: always
expose_as: "pint report"
paths:
- pint-report.txt
phpcs:
<<: *php-base
stage: lint
variables:
PHPCS_REPORT: phpcs-report.txt
PHPCS_JUNIT: phpcs-junit.xml
script:
- vendor/bin/phpcs -q --report=full --report-junit="$PHPCS_JUNIT" --standard=phpcs.xml --extensions=php --ignore=vendor/*,storage/*,bootstrap/*,node_modules/*,.intellipest/* . > "$PHPCS_REPORT" 2>&1; status=$?
- cat "$PHPCS_REPORT"
- exit $status
artifacts:
when: always
expose_as: "phpcs report"
paths:
- "$PHPCS_REPORT"
- "$PHPCS_JUNIT"
reports:
junit: "$PHPCS_JUNIT"
phpstan:
<<: *php-base
stage: lint
variables:
PHPSTAN_REPORT: phpstan-report.txt
PHPSTAN_JUNIT: phpstan-junit.xml
script:
- vendor/bin/phpstan analyse --error-format=junit --no-progress > "$PHPSTAN_JUNIT" 2> "$PHPSTAN_REPORT"; status=$?
- if [ ! -s "$PHPSTAN_JUNIT" ] || ! head -n 1 "$PHPSTAN_JUNIT" | grep -q '^<'; then rm -f "$PHPSTAN_JUNIT"; fi
- exit $status
artifacts:
when: always
expose_as: "phpstan report"
paths:
- "$PHPSTAN_JUNIT"
reports:
junit: "$PHPSTAN_JUNIT"
# ---------------------------------------------------------
# TESTS
# ---------------------------------------------------------
pest:
<<: *php-base
stage: test
variables:
JUNIT_REPORT: junit.xml
TEXT_REPORT: test-output.txt
COVERAGE_REPORT: coverage.xml
script:
- rm -f "$JUNIT_REPORT" "$COVERAGE_REPORT"
- composer run-script tests:coverage -- --min=85 --log-junit="$JUNIT_REPORT" --coverage-clover="$COVERAGE_REPORT" > "$TEXT_REPORT" 2>&1; status=$?
- cat "$TEXT_REPORT"
- exit $status
artifacts:
when: always
expose_as: "pest report"
paths:
- junit.xml
- test-output.txt
- coverage.xml
reports:
junit: junit.xml