Added a check to ensure that the tag is created on the main branch before publishing the Composer package.
141 lines
4.5 KiB
YAML
141 lines
4.5 KiB
YAML
include:
|
|
- project: "ldc-web/shared-ci"
|
|
ref: "main"
|
|
file: "lint/phpcs.yml"
|
|
- project: "ldc-web/shared-ci"
|
|
ref: "main"
|
|
file: "lint/phpstan.yml"
|
|
- project: "ldc-web/shared-ci"
|
|
ref: "main"
|
|
file: "security/composer.yml"
|
|
- project: "ldc-web/shared-ci"
|
|
ref: "main"
|
|
file: "test/test.yml"
|
|
|
|
stages:
|
|
- lint
|
|
- security
|
|
- test
|
|
- publish
|
|
- release
|
|
|
|
phplint:
|
|
stage: lint
|
|
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
|
variables:
|
|
TEXT_REPORT: php-l-report.txt
|
|
before_script:
|
|
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
|
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
|
|
script:
|
|
- composer run-script lint:php > "$TEXT_REPORT" 2>&1; status=$?
|
|
- cat "$TEXT_REPORT"
|
|
- if [ $status -ne 0 ] || grep -qE "Parse error|Errors parsing" "$TEXT_REPORT"; then echo "PHP lint failed"; exit 1; fi
|
|
artifacts:
|
|
when: always
|
|
expose_as: "php-l report"
|
|
paths:
|
|
- php-l-report.txt
|
|
allow_failure: false
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
|
|
pint:
|
|
stage: lint
|
|
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
|
variables:
|
|
PINT_REPORT: pint-report.txt
|
|
before_script:
|
|
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
|
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
|
|
script:
|
|
- vendor/bin/pint --test > "$PINT_REPORT" 2>&1; status=$?
|
|
- cat "$PINT_REPORT"
|
|
- if [ $status -ne 0 ] || grep -qE "ERROR|ERRORS|ERROR:" "$PINT_REPORT"; then echo "Pint reported errors"; exit 1; fi
|
|
artifacts:
|
|
when: always
|
|
expose_as: "pint report"
|
|
paths:
|
|
- pint-report.txt
|
|
allow_failure: false
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
|
|
pest:
|
|
stage: test
|
|
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
|
variables:
|
|
JUNIT_REPORT: junit.xml
|
|
TEXT_REPORT: test-output.txt
|
|
COVERAGE_REPORT: coverage.xml
|
|
before_script:
|
|
- composer config gitlab-token.lab.s-web.fr $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
|
- composer install --no-scripts --no-interaction --no-ansi --no-progress --prefer-dist
|
|
script:
|
|
- rm -f "$JUNIT_REPORT" "$COVERAGE_REPORT"
|
|
- composer run-script test:coverage -- --min=85 > "$TEXT_REPORT" 2>&1; status=$?
|
|
- cat "$TEXT_REPORT"
|
|
- if [ -f "$COVERAGE_REPORT" ]; then echo "Coverage report generated $COVERAGE_REPORT"; else echo "No coverage report found"; fi
|
|
- exit $status
|
|
artifacts:
|
|
when: always
|
|
expose_as: "pest report"
|
|
paths:
|
|
- junit.xml
|
|
- test-output.txt
|
|
- coverage.xml
|
|
reports:
|
|
junit: junit.xml
|
|
allow_failure: false
|
|
rules:
|
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
|
|
package-publish:
|
|
image: $CI_REGISTRY/ldc-web/projets/ldc-web-images-docker/uwil-ci-8.5:latest
|
|
stage: publish
|
|
variables:
|
|
URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
|
|
script:
|
|
# Check that the tag is on the main branch
|
|
- git fetch origin main
|
|
- |
|
|
if ! git branch -r --contains "$CI_COMMIT_SHA" | grep -q "origin/main"; then
|
|
echo "Erreur : Le tag $CI_COMMIT_TAG n'a pas été créé sur la branche main !"
|
|
exit 1
|
|
fi
|
|
# Publish Composer package
|
|
- insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure" || echo "")
|
|
- |
|
|
response=$(curl -s -w "\n%{http_code}" $insecure --data tag=$CI_COMMIT_TAG $URL)
|
|
code=$(echo "$response" | tail -n 1)
|
|
body=$(echo "$response" | head -n 1)
|
|
if [ $code -eq 201 ]; then
|
|
echo "Package created - Code $code - $body"
|
|
else
|
|
echo "Could not create package - Code $code - $body"
|
|
exit 1
|
|
fi
|
|
rules:
|
|
- if: '$CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+/'
|
|
|
|
release:
|
|
stage: release
|
|
image: registry.gitlab.com/gitlab-org/cli:latest
|
|
needs:
|
|
- job: package-publish
|
|
rules:
|
|
- if: '$CI_COMMIT_TAG =~ /^v?\d+\.\d+\.\d+/'
|
|
before_script:
|
|
- |
|
|
tag_clean=$(echo "$CI_COMMIT_TAG" | sed 's/^v//')
|
|
sed -n "/## .*\[v\?${tag_clean}\]/,/## .*\[/p" CHANGELOG.md | sed '$d' > release_notes.md || true
|
|
if [ ! -s release_notes.md ]; then
|
|
echo "Release $CI_COMMIT_TAG du package uwil/sitemap-generator." > release_notes.md
|
|
fi
|
|
script:
|
|
- echo "Création de la release $CI_COMMIT_TAG via glab CLI..."
|
|
release:
|
|
name: "Release $CI_COMMIT_TAG"
|
|
tag_name: "$CI_COMMIT_TAG"
|
|
ref: "$CI_COMMIT_TAG"
|
|
description: "./release_notes.md"
|